【问题标题】:Links in iOS Ionic app not opening immediatelyiOS Ionic 应用程序中的链接未立即打开
【发布时间】:2017-09-05 17:14:19
【问题描述】:

我的应用程序的一个视图中有几个链接:

  1. 分享
  2. 添加到日历
  3. 打开外部链接

在我用来测试应用程序的 iPhone 上,第 1 和第 2 种工作,但只有当我按下主页按钮然后返回应用程序时,才会出现共享/日历对话框。谁能建议可能导致这种情况的原因?我什至不知道在哪里看。

外部链接使用 window.open(url, "_system") 因为我无法让常规类型的链接在模拟器中工作。我可能会切换回常规的 HTML 链接,因为另一个链接能够在测试 iPhone 上运行。使用 iOS 在手机浏览器中打开链接的建议方法是什么?

代码大致如下。

.controller('WCtrl', function ($scope, $stateParams, $sce) {
  // ...
  $scope.doShare = function () {
    var options = {
      message: 'Message here',
      subject: 'Event shared'
    };
    var onSuccess = function (result) {
      console.log('Share successful.');
    };
    var onError = function (msg) {
      console.log('Sharing failed with message: ' + msg);
    }
    window.plugins.socialsharing.shareWithOptions(options, onSuccess, onError);
  };
  $scope.doCalAdd = function () {
    var onSuccess = function (result) {
      console.log('Add to calendar successful.');
    };
    var onError = function (msg) {
      console.log('Add to calendar failed with message: ' + msg);
    }
    // ...
    window.plugins.calendar.createEventInteractively(
      title,
      location,
      notes,
      starttime,
      endtime,
      onSuccess,
      onError);
  };
  $scope.doTicketsOpen = function () {
    var url = w.ticketing;
    window.open(url, '_system');
  };
})
<ion-view class="item-text-wrap" view-title="Event Details">
  <ion-content class="has-footer">
    <!-- ... -->
  </ion-content>
  <ion-footer-bar>
    <div class="button-bar">
      <div class="button icon ion-share" ng-click="doShare();">Share</div>
      <div class="button icon ion-calendar" ng-click="doCalAdd();">Calendar</div>
      <div class="button icon ion-link" ng-click="doTicketsOpen();">Ticketing</div>
    </div>
  </ion-footer-bar>
</ion-view>

我在 index.html 中有一个 Content-Security-Policy 元标记,如下所示。

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" />

【问题讨论】:

标签: ios cordova ionic-framework


【解决方案1】:

您必须在index.htmlContent-Security-Policy 元标记的default-src 中添加gap:

这是因为在 iOS 10 上,Apple 对 CSP 的要求更加严格,而 * 并未涵盖某些内容

【讨论】:

  • 在哪里可以了解更多信息?如果我没有在这里发布这个问题,我就不会考虑查看 Content-Security-Policy 元标记。
  • 关于苹果更严格,没有任何相关信息,甚至可能是一个bug,实际上在第一个iOS 10 beta 上更糟糕,但苹果没有提供任何相关信息,人们通过测试发现了。关于一般的 CSP,白名单插件文档cordova.apache.org/docs/en/latest/reference/… 中有一些信息,其中提到 gap: 是使用 UIWebView 时插件工作所必需的(默认)。这对于正确配置 CSP 也很有用content-security-policy.com
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-16
  • 1970-01-01
  • 2013-06-09
  • 1970-01-01
  • 2016-04-08
  • 2021-08-07
  • 2014-07-18
相关资源
最近更新 更多