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

时间:2016-09-02 15:47:56

标签: android angularjs cordova ionic-framework socialshare

我想使用这个插件:$cordovaSocialSharing,因为它是Ionic在Ionic上发现的唯一插件...

我在Chrome控制台中运行代码时遇到此错误: “无法读取未定义的属性'socialsharing'”@(ng-cordova.js:6715)

我重新安装了ng-Cordova,就像它在ngcordova.com和插件中多次说的那样,但似乎它不起作用......我试过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的想法?

1 个答案:

答案 0 :(得分:0)

您需要使用真实设备,大多数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');
  }