Reputation: 2370
I'm trying to add the SMS cordova plugin to my ionic application but I'm failing miserably.
I've no idea how to inject the plugin or use it the documentation seems to be more phonegapp orientated.
I've got the following:
Installed
cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git
My view
<button ng-click="send()">Test</button>
My Controller
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope, $http, $state, $cordovaSms) {
$scope.send = function(){
$cordovaSms
.send('phonenumber', 'SMS content')
.then(function() {
// Success! SMS was sent
}, function(error) {
// An error occurred
});
};
})
I get the following error:
ionic.bundle.js:26794 Error: [$injector:unpr] Unknown provider:
$cordovaSmsProvider <- $cordovaSms <- DashCtrl
Upvotes: 0
Views: 3204
Reputation: 51
Google changed the policy regarding to SMS access, so the direct reading of incoming SMS is no longer allowed and the associated permissions will be removed (SMS_READ).
Now, it is necessary to use the Android SMS Retriever API (Android SMS Retriever API) and your SMS message needs to comply a specific format in order to be intercepted by your app.
In Cordova use this plugin to easily read incoming SMS:
cordova plugin add cordova-plugin-android-sms-retriever
Github: https://github.com/diegosiao/cordova-plugin-android-sms-retriever
Upvotes: 1
Reputation: 1347
On IONIC 2 , the cordova-sms-plugin its the solution choose for the native SMS plugin. So far so good, except the case you want to send messages to multiple recipients.
At this moment, cordova-sms-plugin does not send to multiple recipients, even if we use string array. It will successfully send to first recipient, but not to the rest of array.
So after I searched a while I got another cordova plugin, which sends messages to all numbers in array. The only problem is, if among those numbers are invalid or incomplete phone numbers, it simply ignores them and pass to the next number to send.
Would be nice to have a callback or at least a trace, when certain numbers are invalid or incomplete, but at least it sends to multimple numbers.
Cheers
Upvotes: 0
Reputation: 461
I think it's a casing issue. Are you using ionic-native yet? If not, start there.
bower install ionic-native --save
bower uninstall ngCordova --save
Then replace ngCordova
with ionic.native
in your module dependencies.
Here is working code from one of my projects...
.controller('RosterCtrl', function ($cordovaSMS, ...
// snip ....
$cordovaSMS.send(phone, message)
.then(function () {
$log.log('Message sent.');
});
Upvotes: 1