【问题标题】:Launching Custom URL in PhoneGap + iPhone在 PhoneGap + iPhone 中启动自定义 URL
【发布时间】:2012-12-06 18:18:09
【问题描述】:

我正在开发适用于 iPhone 的 Sencha 触控应用程序。现在应用程序已准备就绪,可以在手机浏览器中正常运行。但是,现在我想分发我的应用程序,所以我使用的是 PhoneGap。

我所有的 HTML 和 JavaScript 页面都部署在 http://170.60.26.20:8099/Sencha/Html/index.html。现在我想使用 phonegap 加载该 URL。建议我如何执行此操作的步骤。

我已经安装了phonegap-1.2.0-0 版本。

【问题讨论】:

  • @iMayur .. 我已经尝试过你解释的方式,只是通过更改 window.location="170.60.26.20:8099/Sencha/Html/index.html";但它仍然无法正常工作..
  • 您的网址170.60.26.20:8099/Sencha/Html/index.html 在普通浏览器中无法正常工作,因为该页面所在的服务器没有响应。
  • @iMayur.. 在我的测试环境中。我在移动浏览器中点击 url。它工作正常,这意味着 URL 绝对没问题。只是它在电话间隙上不起作用。
  • 我已经在移动浏览器(模拟器和设备)中尝试过,仍然170.60.26.20:8099/Sencha/Html/index.html url 没有响应。请您提供工作网址,就像我在回答中使用了演示链接一样。

标签: iphone ipad cordova sencha-touch


【解决方案1】:

在xcode中创建新的Phonegap App,你只需要修改www文件夹中已经存在的index.html文件。 您可以使用window.location javascript 方法在手机应用程序中加载您的网络应用程序。

在PhoneGap(Cordova).plist 中,将您的服务器添加到ExternalHosts 列表并将OpenAllWhitelistURLsInWebView 设置为YES

请尝试以下代码在 phonegap 应用中运行您的 html 页面。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <!-- Change this if you want to allow scaling -->
    <meta name="viewport" content="width=default-width; user-scalable=no" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>LoadUrl
    <!-- If you application is targeting iOS BEFORE 4.0 you MUST put json2.js from http://www.JSON.org/json2.js into your www directory and include it here -->
    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8">

    function onBodyLoad()
    {
        document.addEventListener("deviceready",onDeviceReady,false);
    }
    /* When this function is called, PhoneGap has been initialized and is ready to roll */
    function onDeviceReady()
    {
    // do your thing!
       window.location="http://web.me.com/djpinter1/iPhone/jqtouch/demos/main_tabbar/#ui";
      //window.location="http://170.60.26.20:8099/Sencha/Html/index.html";
    }
    </script>
  </head>
  <body onload="onBodyLoad()">   
  </body>
</html>

【讨论】:

  • 别忘了在PhoneGap.plist中将你的服务器添加到ExternalHosts列表和OpenAllWhitelistURLsInWebView为YES,否则新页面会在Safari中打开。
  • 非常感谢您的回答。这帮助我找出了我遇到的问题。
【解决方案2】:

在您的 xcode 中,启动一个新项目作为 phonegap 项目。然后将项目文件夹中的文件复制到 phonegap 项目中的 www 文件夹中。记住 index.html 文件应该在父文件夹中,否则您必须在相应的类中相应地更改 url调用 webview。

您可以点击此链接

http://wiki.phonegap.com/w/page/39991939/Getting%20Started%20with%20PhoneGap%20iOS%20using%20Xcode%204

希望对你有帮助

【讨论】:

  • 感谢您的快速回复。但我所有的 html 和 js 资源都存在于远程服务器中。我怎么能加载那个。在android中,我们使用phonegap sdk给出的loadUrl()。我怎么能在这里做同样的事情。
  • 检查此 URL 也 stackoverflow.com/questions/8063802/… 很好的解决方案只是在 AppDelegate.m 中重载 + (NSString*) startPage;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-25
  • 2012-01-02
  • 2013-12-02
相关资源
最近更新 更多