我想使用这个插件:$cordovaSocialSharing因为它是我在 Ionic 找到的本机社交按钮的唯一插件...
当我在 Chrome 控制台中运行代码时出现此错误:“无法读取未定义的属性'socialsharing'”@(ng-cordova.js:6715)
我重新安装了 ng-Cordova,因为它在 ngcordova.com 和插件中多次说,但它似乎并没有'work...I 尝试在 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 回答
您需要使用真实设备,大多数 Cordova 插件在浏览器中不可用。
检测到您的应用程序在 Cordova/Phonegap 中运行