xcode ios phonegap 子浏览器插件设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16303782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:18:31  来源:igfitidea点击:

ios phonegap Child Browser plugin setup

htmliosxcodecordova

提问by mhartington

So I'm setting up the Child Browser plugin in Xcode for my phonegap app and was having some issues with it. First off, just to make sure its structured correctly in Xcode, I have all the native files in my plugins folder along with ChildBrowser.bundlefor the icons.
Now for the html side, I have a my cordova.jsand childbrowser.jsfiles in my head followed by this

所以我在 Xcode 中为我的 phonegap 应用程序设置了 Child Browser 插件,但遇到了一些问题。首先,为了确保它在 Xcode 中的结构正确,我的插件文件夹中包含所有本机文件以及ChildBrowser.bundle图标。
现在对于 html 方面,我脑子里有一个我的cordova.jschildbrowser.js文件,然后是这个

 <script type="text/javascript">
    function onDeviceReady() {

        var root = this;
        cb = window.plugins.childBrowser;

        if(cb != null) {
        cb.onLocationChange = function(loc){ root.locChanged(loc); };
        cb.onClose = function(){root.onCloseBrowser(); };
        cb.onOpenExternal = function(){root.onOpenExternal(); }
        }
    }

    function onCloseBrowser() {
        console.log("onCloseBrowser!");
    }

    function locChanged(loc) {
        console.log("locChanged!");
    }

    function onOpenExternal() {
        alert("onOpenExternal!");
    }

</script>

Then for my <a>tag I used the onClick event that is used in the github example Here

然后对于我的<a>标签,我使用了 github 示例中使用的 onClick 事件这里

<a onclick="childBrowser.showWebPage('http://google.com');" href="#">Test</a>

But when I try it in the simulator, nothing really happens and the consol log doesn't even show any activity. I'm I doing this right or what? Any help is appreciated. Im using phonegap 2.6.0

但是当我在模拟器中尝试它时,实际上什么也没发生,并且控制台日志甚至没有显示任何活动。我这样做是对的还是什么?任何帮助表示赞赏。我正在使用 phonegap 2.6.0

回答by AvtarSingh Suchariya

This will help you to add the child browser.

这将帮助您添加子浏览器。

https://github.com/phonegap/phonegap-plugins/tree/master/iOS/ChildBrowser

https://github.com/phonegap/phonegap-plugins/tree/master/iOS/ChildBrowser

and Also Installing Cordova Plugins with Phonegap - no Cordova.plist

以及使用 Phonegap 安装 Cordova 插件 - 没有 Cordova.plist

I integrated it successfully by above the link and below are the steps.

我通过上面的链接成功地集成了它,下面是步骤。

1) Copy all the files in "ChildBrowser" and paste it in "Plugin" folder of PhoneGap 2.6.0 Project.

1) 将“ChildBrowser”中的所有文件复制并粘贴到PhoneGap 2.6.0 Project的“Plugin”文件夹中。

2) Add Framework from "Plugin" as shown below screenshot.

2) 从“插件”添加框架,如下图所示。

enter image description here

在此处输入图片说明

3) Include the "ClildBrowser.js" into "www/index.html"

3) 将“ClildBrowser.js”包含到“www/index.html”中

4) From Xcode, add the files into "Plugin" Folder.

4) 在 Xcode 中,将文件添加到“插件”文件夹中。

5) Follow the code mentioned at https://github.com/phonegap/phonegap-plugins/tree/master/iOS/ChildBrowser

5) 按照https://github.com/phonegap/phonegap-plugins/tree/master/iOS/ChildBrowser 中提到的代码

6) Enjoy.

6)享受。

回答by user2216399

Update: If your using Phongap 2.0 or above, you don't need an external plugin . Phonegape 2.0 , and above come with InAppBrowser which is ChildBrowser but very effective and time saving you dont need to go through all this painful process. to setup InAppBrowser

更新:如果您使用 Phongap 2.0 或更高版本,则不需要外部插件。Phonegape 2.0 及更高版本带有 InAppBrowser,它是 ChildBrowser,但非常有效且节省时间,您无需经历所有这些痛苦的过程。设置 InAppBrowser

steps:

脚步:

1- in config.xmladd :

1-config.xml添加:

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

2- Create Function and call that function once phonegap is loaded "inside OnDeviceReady()or after"

2- 创建函数并OnDeviceReady()在“内部或之后”加载 phonegap后调用该函数

function externalWeb(url) {
    console.log("Initializing InAppBrowswer");

    var ref = window.open(url, '_blank', 'location=yes', 'EnableViewPortScale=yes');

    ref.addEventListener('loadstart', function(event) {
        console.log("start loading external link  :" + event.url);
    });

    ref.addEventListener('loadstop', function(event) {
        console.log("External link lodaded without any problem  : " + event.url);
    });

    ref.addEventListener('loaderror', function(event) {
        console.log("There is error in loading External link :" + event.url);
        alert('error: ' + event.message);
    });

    ref.addEventListener('exit', function(event) {
        console.log("External link is closed now :" + event.type + "link :" + event.url);
    });
}

3- now to open a link call the function above with the URL as string

3- 现在打开一个链接,使用 URL 作为字符串调用上面的函数

var targetURL="http://www.google.co.uk";
externalWeb(targetURL);

For more information follow the link InAppBrowser

有关更多信息,请访问 InAppBrowser链接

回答by Ecko123

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

Do remember to get the latest plugin code , since phonegap has changed the way parameters are passed to native .m file For ex :

请记住获取最新的插件代码,因为 phonegap 改变了参数传递给原生 .m 文件的方式例如:

- (void)showWebPage:(CDVInvokedUrlCommand*)command 

and in .h file

并在 .h 文件中

@property (nonatomic, strong) ChildBrowserViewController* childBrowser;

-(void)showWebPage:(CDVInvokedUrlCommand*)command;