【发布时间】:2018-12-06 04:58:36
【问题描述】:
我已尝试使用以下链接中提供的插件
https://github.com/floatinghotpot/cordova-plugin-sms?files=1
我收到一个错误短信未定义
下面是我的控制器代码
angular.module('starter.controllers', [])
.controller('SMSCtrl', function($scope ,$ionicPopup ) {
$scope.data = {};
$scope.SMSlist = function() {
console.log("Button click");
var filter = {
box : 'inbox', //inbox, sent, draft
//following 4 filters should not be applied together, they are OR relationship
read :1, //0 for unread and 1 for already
// _id: 1234, //specify the msg id
// body : 'This is a test SMS' , //content to match
// address: '+9731151243';
indexFrom : 0,
maxCount : 10,
};
if(SMS) SMS.listSMS(filter,function(data){
if(Array.isArray(data)){
var sms = data[i];
console.log(sms);
$scope.article = sms;
}
}, function(err) {
var alertPopup = $ionicPopup.alert({
title: 'Reading Failed!',
template: 'Read Failed'
});
})
}
})
任何帮助将不胜感激
【问题讨论】:
-
您确定 deviceReady 在您尝试执行该代码之前已触发吗?您可以通过在两个地方使用 alert(); 最轻松地检查这一点:在 deviceReady 处理程序上和在
if (SMS)之前。这样你就可以看到哪个先完成。 -
似乎是我没有初始化第三方插件,但不知道如何初始化。我在 app.js 中的 run function .run(function($ionicPlatform) { $ionicPlatform.ready(function() { var phoneNumber = window.plugins.sms; sms.get(function(result) { //结果 }, function() { //error }); }); });
-
所以 deviceReady 在
if (SMS)之前触发?在这种情况下,您是使用Cordova CLI 还是PhoneGap Build 来构建您的应用程序? -
我正在使用 Cordova CLI
-
我假设你已经完成了
cordova plugin add com.rjfun.cordova.sms,对吧?其他插件是否正常工作?另外,你是用模拟器还是真机来测试呢?以及哪个平台(iOS、Android、WP 等)?
标签: angularjs cordova ionic-framework cordova-plugins