InAppBrowser not being called in Phonegap 3.1.0

血红的双手。 提交于 2019-12-04 19:04:50
RickCase

Please check the followings:

STEP 1

In your "platforms/ios/www/plugins/", is there a "org.apache.cordova.inappbrowser" dir? If the answer is no, it's not successfully added.

Solution: Create dir "org.apache.cordova.inappbrowser/www/", and put "InAppBrowser.js" in it. You can find it in your PhoneGap project root "yourproject/plugins/org.apache.cordova.inappbrowser/www/". Then go to step 2.

STEP 2

Open "platforms/ios/www/cordova_plugins.js". In "module.exports", add:

    {
        "file": "plugins/org.apache.cordova.inappbrowser/www/InAppBrowser.js",
        "id": "org.apache.cordova.inappbrowser.InAppBrowser",
        "clobbers": [
            "window.open"
        ]
    }

In "module.exports.metadata", add:

    "org.apache.cordova.inappbrowser": "0.2.5"

and Save. "0.2.5" is the version of plugin, can be found in plugin.xml. (Looks like this number does not matter.)

Then run it, open your inspector and check if "InAppBrowser.js" is successfully added into the head tag.

Note: manually adding "InAppBrowser.js" into head tag without modifying "cordova_plugins.js" will not work. If answer to 1 is yes, go to step 2 directly.

Hopefully this solves your problem.

Check that your config.xml has these things:

  <?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.helloworld" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>HelloWorld</name>
    <description>
        Hello World sample application that responds to the deviceready event.
    </description>
    <author email="support@phonegap.com" href="http://phonegap.com">
        PhoneGap Team
    </author>
    <feature name="http://api.phonegap.com/1.0/device" />
    <preference name="phonegap-version" value="3.1.0" />
    <preference name="permissions" value="none" />
    <preference name="orientation" value="default" />
    <preference name="target-device" value="universal" />
    <preference name="fullscreen" value="true" />
    <preference name="webviewbounce" value="true" />
    <preference name="prerendered-icon" value="true" />
    <preference name="stay-in-webview" value="false" />
    <preference name="ios-statusbarstyle" value="black-opaque" />
    <preference name="detect-data-types" value="true" />
    <preference name="exit-on-suspend" value="false" />
    <preference name="show-splash-screen-spinner" value="true" />
    <preference name="auto-hide-splash-screen" value="true" />
    <preference name="disable-cursor" value="false" />
    <preference name="android-minSdkVersion" value="7" />
    <preference name="android-installLocation" value="auto" />
    <icon src="icon.png" />
    <icon gap:density="ldpi" gap:platform="android" src="res/icon/android/icon-36-ldpi.png" />
    <icon gap:density="mdpi" gap:platform="android" src="res/icon/android/icon-48-mdpi.png" />
    <icon gap:density="hdpi" gap:platform="android" src="res/icon/android/icon-72-hdpi.png" />
    <icon gap:density="xhdpi" gap:platform="android" src="res/icon/android/icon-96-xhdpi.png" />
    <icon gap:platform="blackberry" src="res/icon/blackberry/icon-80.png" />
    <icon gap:platform="blackberry" gap:state="hover" src="res/icon/blackberry/icon-80.png" />
    <icon gap:platform="ios" height="57" src="res/icon/ios/icon-57.png" width="57" />
    <icon gap:platform="ios" height="72" src="res/icon/ios/icon-72.png" width="72" />
    <icon gap:platform="ios" height="114" src="res/icon/ios/icon-57-2x.png" width="114" />
    <icon gap:platform="ios" height="144" src="res/icon/ios/icon-72-2x.png" width="144" />
    <icon gap:platform="webos" src="res/icon/webos/icon-64.png" />
    <icon gap:platform="winphone" src="res/icon/windows-phone/icon-48.png" />
    <icon gap:platform="winphone" gap:role="background" src="res/icon/windows-phone/icon-173.png" />
    <gap:splash gap:density="ldpi" gap:platform="android" src="res/screen/android/screen-ldpi-portrait.png" />
    <gap:splash gap:density="mdpi" gap:platform="android" src="res/screen/android/screen-mdpi-portrait.png" />
    <gap:splash gap:density="hdpi" gap:platform="android" src="res/screen/android/screen-hdpi-portrait.png" />
    <gap:splash gap:density="xhdpi" gap:platform="android" src="res/screen/android/screen-xhdpi-portrait.png" />
    <gap:splash gap:platform="blackberry" src="res/screen/blackberry/screen-225.png" />
    <gap:splash gap:platform="ios" height="480" src="res/screen/ios/screen-iphone-portrait.png" width="320" />
    <gap:splash gap:platform="ios" height="960" src="res/screen/ios/screen-iphone-portrait-2x.png" width="640" />
    <gap:splash gap:platform="ios" height="1024" src="res/screen/ios/screen-ipad-portrait.png" width="768" />
    <gap:splash gap:platform="ios" height="768" src="res/screen/ios/screen-ipad-landscape.png" width="1024" />
    <gap:splash gap:platform="winphone" src="res/screen/windows-phone/screen-portrait.jpg" />
    <gap:plugin name="org.apache.cordova.geolocation" />
    <gap:plugin name="org.apache.cordova.network-information" version="0.2.3" />
    <gap:plugin name="org.apache.cordova.inappbrowser" version="0.1.0" />
    <access origin="http://127.0.0.1*" />
    <access origin="*" />
    <content src="index.html" />
</widget>

I've resolved this issue by using the Cordova CLI commands exclusively to create the project and then to add the plugins. It seems you have to use their build commands to get everything moved into the right directories. Now I just issue a cordova build and that will build for iOS and Android with the appropriate plugin files in the correct spot.

I've also modified the generated js/index.js to call my Sencha Touch app as follows:

var device = false;
var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicity call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        try {
            device = true;
            People.app.mainLaunch();
        }
        catch(e) {
            alert("Error: " + e);
        }

        console.log('Received Event: ' + id);
    }
};

And then in my Sencha Touch app, I create I modified my launch method to prevent a race condition between my ST app being initialized before PhoneGap starting up as follows:

launch: function() {
    this.launched = true;
    this.mainLaunch();
},
mainLaunch: function() {
    try {
        if (this.launched && device) {
            Ext.Viewport.add({xtype:'myApp');
        }
    }
    catch(e) {
        alert(e);
    }
},
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!