iOS 分享 sheet 触发两次 [Cordova/Ionic/Angular]

iOS share sheet fires twice [Cordova/Ionic/Angular]

出于某种原因,当我在我的应用程序菜单中按下 n-click 共享按钮时,iOS 中的共享 sheet 会触发两次(即第一个 sheet 进入视图,然后是另一个在它上面)。

menu.html...

<ion-nav-buttons side="right">
  <button ng-cloak ng-if="sharable" ng-click="systemShare()" class="button button-icon button-clear ion-share"></button>
</ion-nav-buttons>

controller.js...

.controller('dataCtrl', function($scope, $rootScope, $stateParams, dataService, $cordovaSocialSharing) {

dataService.getData($stateParams.itemId).then(function(data){
   $scope.data = data;

    // set sharable
    $rootScope.sharable=true;
    document.addEventListener("deviceready", function () {
      $rootScope.systemShare = function(){
      $cordovaSocialSharing
        .share($scope.data.title, $scope.data.title, null, $scope.data.url)
        .then(function(result) {
          // Success!
        }, function(err) {
          // An error occured. Show a message to the user
        },false);
      }
    });
  });
})

我有几个控制器遵循相同的模式(并且每个控制器的代码在上面显示的内容方面基本相同)。他们获取数据,填充视图,然后使用 $rootScope.

定义共享按钮功能和参数

第一次按下按钮时会触发两次。有时它会发生第二次,但并非总是如此。无论首先使用哪个版本的 view/controller 都会发生双发(也就是说,我有一个用于游览的控制器和一个用于停止的控制器:两者几乎相同,无论我先去哪个都会表现出这种行为)。

我想我需要更改定义 systemShare() 函数的方式,但我不确定除了通过 $rootScope 之外该怎么做,因为它需要通过以下方式访问全局菜单。

看起来这是一个 Ionic 错误。看: https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/issues/465

建议的解决方法(对我有用)是在超时时结束调用。

    setTimeout(function() {
        $cordovaSocialSharing
          .share('Subject', 'Message', null, 'http://www.google.com') // Share via native share sheet
          .then(function(result) {
              console.log(result);
              }, function(err) {
              alert('Sharing failed. Please try again.');
              });
    }, 500);