Cordova 3.4.0 InAppBrowser Not Working

六眼飞鱼酱① 提交于 2019-12-08 07:11:09

问题


I'm new to Cordova and JS and have been struggling with the InAppBrowser plug-in for Cordova 3.4.0 to work in iOS (Xcode v5.0.2).

The cordova project was built successfully using these command line commands:

cordova create InAppBrowserTest3-4 local.test InAppBrowser_Test3-4
cordova plugin add org.apache.cordova.inappbrowser
cordova platform add ios
cordova plugins
[ 'org.apache.cordova.inappbrowser' ]

www config file contains:

<feature name="InAppBrowser">
    <param name="ios-package" value="CDVInAppBrowser" />
</feature>

Only these additional commands were added to the generated onDeviceReady method to exercise the InAppBrowser:

onDeviceReady: function() { app.receivedEvent('deviceready');

//added these lines below
    alert('deviceReady');
    var ref = window.open('http://apache.org', '_blank', 'location=yes');
    ref.addEventListener('loadstart', function(event) { alert('start: ' + event.url); });
    ref.addEventListener('loadstop', function(event) { alert('stop: ' + event.url); });
    ref.addEventListener('loaderror', function(event) { alert('error: ' + event.message); });
    ref.addEventListener('exit', function(event) { alert(event.type); });
    alert('end deviceReady');
}

When executed, the last alert isn't called and no browser is open. Similar code is running successfully using Cordova 2.9.0.

Does anyone have any suggestions? I've read through several similar posts but haven't found a solution yet.


回答1:


To solve this, try the following:

cordova create hello com.example.hello HelloWorld

cd hello

cordova platform add android

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git

cordova build

Note the "cordova build" step, which creates the platform/ios/www directory where you can find the file cordova_plugins.js with the folder plugins correctly installed.




回答2:


I tried manually adding in the data to platforms/ios/www/plugins/cordova_plugins but whenever I performed run ios it would be overwritten by the build process. What worked for me was doing cordova platform remove ios then cordova platform add ios.

This showed up in my cordova_plugins.js file:

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

And it stayed there. It works fine now.




回答3:


I use the PhoneGap compile on the cloud. What I do is include the

<gap:plugin name="org.apache.cordova.inappbrowser" version="0.2.4" />

into the xml config file. Make sure your cordova.js at the top of other javascript includes in the index.html. That should work.



来源:https://stackoverflow.com/questions/22075580/cordova-3-4-0-inappbrowser-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!