【问题标题】:InAppBrowser not being called in Phonegap 3.1.0InAppBrowser 未在 Phonegap 3.1.0 中调用
【发布时间】:2013-10-23 00:17:04
【问题描述】:

我从 NPM 获取了最新版本的 phonegap 并安装了它。我创建了一个新项目,并根据 PhoneGap 上的文档添加了 InAppBrowser 插件。然后我从我的 webapp 进行 JavaScript 调用,但我从来没有看到我在下面编码的警报,也没有看到我在 Xcode 中为插件设置的任何断点。

这是 JS 的代码:

var pdfViewer = {
    loadPdf: function(record, successCallback, errorCallback) {
        var filename = record.get('building') + "-" + record.get('floor') + ".pdf";
        var url = People.app.srvcUrl + Global.floorPlanUri + filename + "?access_token=" + People.app.bearerToken.access_token;
        if (Ext.os.is.iOS) {
        //    cordova.exec(successCallback, errorCallback, "PDFViewer", "loadRemotePdf", [url, filename]);


            var ref = window.open(url, '_blank', 'location=yes');
            ref.addEventListener('loadstart', function() { alert("You made it!"); });
        } else {
            window.open(url, '_system', 'location=yes');
        }
    }
};

会发生什么情况是,该 url 被启动以在我现有的应用程序顶部显示一个 PDF,没有警报,也没有位置/关闭按钮。为什么不使用 InAppBrowser 的任何想法?我需要让它显示在一个带有关闭按钮的窗口中。

这是我在运行应用程序时在 Xcode 中看到的输出:

2013-10-23 09:39:02.380 mobile-xxx-ios[3302:60b] Multi-tasking -> Device: YES, App: YES
2013-10-23 09:39:02.426 mobile-xxx-ios[3302:60b] Unlimited access to network resources
2013-10-23 09:39:02.564 mobile-xxx-ios[3302:60b] [CDVTimer][phonedialer] 0.477016ms
2013-10-23 09:39:02.567 mobile-xxx-ios[3302:60b] [CDVTimer][sms] 0.230014ms
2013-10-23 09:39:02.569 mobile-xxx-ios[3302:60b] [CDVTimer][emailcomposer] 0.252008ms
2013-10-23 09:39:02.571 mobile-xxx-ios[3302:60b] [CDVTimer][TotalPluginStartup] 7.416010ms
2013-10-23 09:39:02.957 mobile-xxx-ios[3302:60b] Resetting plugins due to page load.
2013-10-23 09:39:05.789 mobile-xxx-ios[3302:60b] Finished load of: file:///var/mobile/Applications/5916FB20-FDEC-40A7-AE77-9EF14AF30585/mobile-xxx-ios.app/www/index.html
2013-10-23 09:39:18.168 mobile-xxx-ios[3302:60b] Resetting plugins due to page load.
2013-10-23 09:39:18.680 mobile-xxx-ios[3302:60b] Finished load of: https://pdfs.xxx.com/noauth/plans/x-1.pdf
FAILED to create agar for HelveticaLTMM.
FAILED to create agar for TimesLTMM.

这是我的 config.xml:

<widget xmlns     = "http://www.w3.org/ns/widgets"
        id        = "io.cordova.helloCordova"
        version   = "2.0.0">
    <name>Mobile App</name>

    <description>
        Mobile Phonegap Application
    </description>

    <access origin="*" subdomains="true"/>

    <content src="index.html" />

    <!-- Preferences for iOS -->
    <preference name="KeyboardDisplayRequiresUserAction" value="true" />
    <preference name="SuppressesIncrementalRendering" value="false" />
    <preference name="UIWebViewBounce" value="true" />
    <preference name="TopActivityIndicator" value="gray" />
    <preference name="EnableLocation" value="false" />
    <preference name="EnableViewportScale" value="false" />
    <preference name="AutoHideSplashScreen" value="true" />
    <preference name="ShowSplashScreenSpinner" value="true" />
    <preference name="MediaPlaybackRequiresUserAction" value="false" />
    <preference name="AllowInlineMediaPlayback" value="false" />
    <preference name="OpenAllWhitelistURLsInWebView" value="false" />
    <preference name="BackupWebStorage" value="cloud" />
    <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" />

    <feature name="SSLSelfCertOverride">
        <param name="ios-package" value="SSLSelfCertOverride" />
    </feature>
    <feature name="LocalStorage">
        <param name="ios-package" value="CDVLocalStorage"/>
    </feature>
    <feature name="PhoneDialer">
        <param name="ios-package" value="PhoneDialer"/>
        <param name="onload" value="true" />
    </feature>
    <feature name="Sms">
        <param name="ios-package" value="Sms"/>
        <param name="onload" value="true" />
    </feature>
    <feature name="EmailComposer">
        <param name="ios-package" value="EmailComposer"/>
        <param name="onload" value="true" />
    </feature>
    <feature name="InAppBrowser">
        <param name="ios-package" value="CDVInAppBrowser" />
    </feature>
    <feature name="Geolocation">
        <param name="ios-package" value="CDVLocation" />
    </feature>
    <feature name="PackageInfo">
        <param name="ios-package" value="PackageInfo" />
    </feature>
    <feature name="PDFViewer">
        <param name="ios-package" value="PDFViewer" />
    </feature>
</widget>

【问题讨论】:

  • 您是否已将服务器添加到whitelist? xcode 根本没有日志信息?
  • 是的,它已列入白名单并允许 *. Xcode 没有提供太多我已经知道的信息。它似乎确实证实了 CDVTimer 没有初始化 InAppBrowser。

标签: ios cordova inappbrowser


【解决方案1】:

请检查以下内容:

第 1 步

在您的“platforms/ios/www/plugins/”中,是否有“org.apache.cordova.inappbrowser”目录? 如果答案是否定的,则没有添加成功。

解决方案:创建目录“org.apache.cordova.inappbrowser/www/”,并将“InAppBrowser.js”放入其中。您可以在 PhoneGap 项目根目录“yourproject/plugins/org.apache.cordova.inappbrowser/www/”中找到它。然后转到第 2 步。

第 2 步

打开“platforms/ios/www/cordova_plugins.js”。在“module.exports”中,添加:

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

在“module.exports.metadata”中,添加:

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

并保存。 “0.2.5”是插件的版本,可以在plugin.xml中找到。 (看起来这个数字无关紧要。)

然后运行它,打开检查器并检查“InAppBrowser.js”是否已成功添加到 head 标签中。

注意:在不修改“cordova_plugins.js”的情况下手动将“InAppBrowser.js”添加到head标签中将不起作用。如果1的回答是肯定的,直接进入步骤2。

希望这能解决您的问题。

【讨论】:

  • 你是个魔术师。我已经查看了 1000 个具有相同问题的线程,但没有人知道该怎么做。从现在开始,我将在每个关于该主题的帖子中链接到您。
  • 对我不起作用 :( 在 Xcode 5 中一切正常,但在 Xcode 6 (beta 7) 中却不行如果我调用“window.open”,InAppBrowser 会添加日志,但屏幕上什么也没有发生!
【解决方案2】:

检查您的 config.xml 是否包含以下内容:

  <?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>

【讨论】:

  • PG 在这里做什么有点令人困惑。如果您从 PG CLI 创建一个应用程序并添加插件,您最终会得到 2 个 config.xml(一个在根目录中,一个在 www 目录中)。您在上面显示的那个最接近 www 目录中的那个,但它没有添加您拥有的插件行。查看他们的文档,它显示将其添加到根 config.xml:docs.phonegap.com/en/3.1.0/…。无论如何,任何一种方法都行不通。适合你吗?
  • 不,抱歉,我还没有在 iOS 上进行测试。但澄清一下,我的 config.xml 来自非平台特定的 www 并且 代码用于告诉 Phonegap Build服务要添加的插件。
  • 请使用最新的3.4版本,可以正常使用。
【解决方案3】:

我已通过专门使用 Cordova CLI 命令创建项目然后添加插件解决了这个问题。看来您必须使用他们的构建命令才能将所有内容移动到正确的目录中。现在我只需发出cordova build,它将为 iOS 和 Android 构建,并在正确的位置使用适当的插件文件。

我还修改了生成的 js/index.js 来调用我的 Sencha Touch 应用,如下所示:

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);
    }
};

然后在我的 Sencha Touch 应用程序中,我创建了我修改了我的启动方法,以防止我的 ST 应用程序在 PhoneGap 启动之前被初始化,如下所示:

launch: function() {
    this.launched = true;
    this.mainLaunch();
},
mainLaunch: function() {
    try {
        if (this.launched && device) {
            Ext.Viewport.add({xtype:'myApp');
        }
    }
    catch(e) {
        alert(e);
    }
},

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 2014-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多