离子:$cordovaSocialSharing 无法读取未定义的 属性

Ionic: $cordovaSocialSharing cannot read property of undefined

我想使用这个插件:$cordovaSocialSharing 因为它是我为 Ionic 上的原生社交按钮找到的唯一插件...

当我在 Chrome 控制台中 运行 我的代码时出现此错误: "Cannot read property 'socialsharing' of undefined"@(ng-cordova.js:6715)

我按照 ngcordova.com 中的说明重新安装了 ng-Cordova 并多次安装了该插件,但它似乎不起作用...我在 Android 模拟器中尝试过,但都没有。

这是我的代码: 在我的 controllers.js:

angular.module('starter.controllers', ['ionic', 'ionic-ratings', 'onezone-datepicker', 'ngCordova'])

然后,

.controller('CaravanDetailCtrl', function($rootScope, $scope, $cordovaSocialSharing, sweetAlert) {
   $scope.socialsharingFacebook = function() {

            $cordovaSocialSharing
                .shareViaFacebook("msg", "img", "url")
                .then(function(result) {
                    SweetAlert.swal({   
                        title: "",   
                        text: "success",   
                        type: "success",   
                        showCancelButton: false,   
                        confirmButtonColor: "rgba(5, 60, 84, 0.8)",   
                        confirmButtonText: "OK",   
                        closeOnConfirm: true 
                    });
                }, function(err) {
                    SweetAlert.swal({   
                        title: "",   
                        text: "sorry",   
                        type: "error",   
                        showCancelButton: false,   
                        confirmButtonColor: "rgba(5, 60, 84, 0.8)",   
                        confirmButtonText: "OK",   
                        closeOnConfirm: true 
                    });
                });
    }

}

我也尝试过这个(在 controllers.js 中):

$ionicPlatform.ready(function() {
   $cordovaSocialSharing
            .shareViaFacebook("msg", "img", "url")
            .then(function(result) {
                SweetAlert.swal({   
                    title: "",   
                    text: "success",   
                    type: "success",   
                    showCancelButton: false,   
                    confirmButtonColor: "rgba(5, 60, 84, 0.8)",   
                    confirmButtonText: "OK",   
                    closeOnConfirm: true 
                });
            }, function(err) {
                SweetAlert.swal({   
                    title: "",   
                    text: "sorry",   
                    type: "error",   
                    showCancelButton: false,   
                    confirmButtonColor: "rgba(5, 60, 84, 0.8)",   
                    confirmButtonText: "OK",   
                    closeOnConfirm: true 
                });
            });
}

知道如何解决这个问题,或者知道另一个真正适用于 Ionic 的插件吗?

您需要使用真实设备,大多数 Cordova 插件在浏览器中不可用。

检测到您的应用程序 运行 在 Cordova/Phonegap

  if (window.cordova) {
     $cordovaSocialSharing
          .shareViaFacebook(message, image, link)
          .then(function(result) {
      // Success!
     }, function(err) {
         // An error occurred. Show a message to the user
     });
  } else {
    console.log('Not a device');
  }