[英]Ionic 2 Build TypeError: Cannot read property 'AssetUrl' of undefined
[英]Ionic Cordova Social Share plugin - cannot read property 'socialsharing' of undefined
所以,我一直在此為現在是3天... ...試了教程像這一個,和原來的頁面后試圖在這里,並宣讀了GitHub的描述一千倍。
我正在使用的版本:
$ npm -v
3.7.3
$ cordova -v
6.1.0 (cordova-lib@undefined)
$ ionic -v
1.7.14
我在 Chrome 瀏覽器中遇到的錯誤:無法讀取 undefined 的屬性“socialsharing” 。 如果按下按鈕,在 android 或 ios 手機上沒有任何反應。 甚至沒有錯誤函數調用。
app.js + 控制器:(注意我正在嘗試使用 window.plugins 而沒有 .plugins !)
angular.module('starter', ['ionic', 'ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
.controller('shareCtrl',['$scope',function($scope) {
$scope.facebookShare=function(){
window.socialsharing.shareViaFacebook('Digital Signature Maker', null /* img */, "https://play.google.com/store/apps/details?id=com.prantikv.digitalsignaturemaker" /* url */, null,
function(errormsg){alert("Error: Cannot Share")});
}
$scope.whatsappShare=function(){
window.plugins.socialsharing.shareViaWhatsApp('Digital Signature Maker', null /* img */, "https://play.google.com/store/apps/details?id=com.prantikv.digitalsignaturemaker" /* url */, null,
function(errormsg){alert("Error: Cannot Share")});
}
我什至嘗試過手動安裝,這里有一個不同的錯誤。 當我將 SocialSharing.js 插入 index.html(cordova.js 之前)時,Chrome 控制台說: Uncaught ReferenceError: require is not defined ,這是 SocialSharing.js 的第 1 行:
var cordova = require('cordova');
所以我已經成功安裝了 require.sj (npm install -g requirejs),然后手動嘗試但出現了完全不同類型的錯誤。
嘗試重新安裝插件或刪除並重新添加平台,但沒有變化。
不確定它是否相關,但曾嘗試使用 ngCordova 的 $cordovaFileOpener2 並且總是為cordova給出未定義的錯誤。 (也不適用於實際手機)
感謝任何幫助! 謝謝
更新:我已經粘貼了上面所有的 .js 文件內容。
請注意,我已經成功安裝了共享插件:
cordova plugin add cordova-plugin-x-socialsharing
Fetching plugin "cordova-plugin-x-socialsharing" via npm
Installing "cordova-plugin-x-socialsharing" for android
這是我的 index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-view view-title="Share">
<ion-content ng-controller="shareCtrl">
<div class="card">
<div class="item item-divider">
<b> Share this app</b>
</div>
<ul class="list">
<li class="item" id="displayLabel">
<button class="button button-block button-royal item-icon-left" ng-click="whatsappShare()">
<i class="icon ion-social-whatsapp"></i>
WhatsApp
</button>
</li>
<li class="item" id="displayLabel">
<button class="button button-block button-royal item-icon-left" ng-click="facebookShare()">
<i class="icon ion-social-twitter"></i>
facebook
</button>
</li>
<li class="item" id="displayLabel">
<button class="button button-block button-royal item-icon-left" ng-click="OtherShare()">
<i class="icon ion-android-share-alt"></i>
Other
</button>
</li>
</ul>
</div>
</ion-content>
</ion-view>
</body>
</html>
實際上,插件提供了對基於 Web 的應用程序通常不可用的設備和平台功能的訪問。 所以你可能無法在瀏覽器上實現插件功能。
您可以使用插件或 ngCordova.js 文件在設備(android/ios/emulator)上實現
使用插件
安裝: cordova插件添加cordova-plugin-x-socialsharing
用法:
.controller('ShareCtrl', function ($scope) {
$scope.whatsappShare = function(){
if(window.plugins.socialsharing) {
window.plugins.socialsharing.canShareVia('whatsapp',
'msg', null, null, null,
function (e) {
//do something
},
function (e) {
//error occured
});
}
}
})
使用 ng-Cordova
安裝:在你的項目中添加 ng-cordova 文件並將其包含在 index.html 文件中
<script src="lib/ng-cordova.min.js"></script>
用法:
.controller('ShareCtrl', function ($scope,$cordovaSocialSharing) {
$scope.shareByWhatsApp = function() {
$cordovaSocialSharing
.shareViaWhatsApp('sharedMsg', "", shareAppLink)
.then(function(result) {
}, function(err) {
// An error occurred. Show a message to the user
alert("error : "+err);
});
};
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.