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
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.');
});
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
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
Related
I'm having a lot of trouble to get Google Cloud Messaging to work in my Phonegap-based app.
I'm following the instructions that are here.
It uses the PushPlugin, which I installed in my app according to the instructions.
Somehow I get no response after registering, nothing happens (no console.log appears) when I do :
window.plugins.pushNotification.register(
pushSuccessHandler,
pushErrorHandler, {
"senderID":"12345678",
"ecb":"onNotificationGCM"
}
);
var pushSuccessHandler = function(result) {
console.log(result);
};
var pushErrorHandler = function(error) {
console.log(error);
};
var onNotificationGCM = function(e) {
console.log(e);
switch(e.event) {
case 'registered' : {
console.log('android reg id: ' + e.regid);
break;
}
}
};
I setup an API project in Google Developer Console, got a project number that I used as the SenderID, and did all modifications to the Phonegap manifest and config xml files.
My app is not published yet in the Play store.
Is this necessary to get Cloud Messaging working?
And is the code above enough to get a 'reg id', or do I first need to push something from the server, but with what 'reg id' then??
Somewhere I read that the push notifications only work in a Phonegap-app when it is running, or when the notification is clicked, so not when the app is started from the normal icon. I don't understand this however, because aren't the notifications supposed to work when the app is not running?
Push notification will work without publishing, publishing is not required.
Only you have to get Sender ID from developer console.
Sender Id - its project number in developer console
for more detail you can check here
https://github.com/phonegap-build/PushPlugin
I am using it its woreking fine for both android and iOS
Update:
I'm using Intellij IDEA to build the app. When I compiled with phonegap build android the push notifications were working ok.
I had to add the 'android-support-v13.jar' and 'gcm.jar' files as a library in the Project Settings of the IDEA project, to get it working. These libraries need to be added to the Dependencies of the main module with scope 'Compile'.
Before I only added them directly in Dependencies of the module, with Scope 'Provided' but apparently that doesn't work (although it compiled).
We've got a Cordova based iOS app that does not use push notifications. As of Cordova 3.5.0, each submission we have made to the app store results in an email informing us that our app includes API used to register with Apple's Push Notification Service, but doesn't have push notification entitlement.
The app has been accepted each time, as we don't actually use push notifications for anything. However, I would like to avoid triggering this warning in case Apple decides to change their policy as to whether these API references are acceptable.
We did not experience the issue with prior versions of Cordova, and have done no work in Objective-C ourselves. Is this a known issue with Cordova 3.5? Searching has yielded some folks with similar problems but I've only found solutions for people wanting to add push entitlements, (rather than figure out where the Push API is being referenced and remove it). I took a look at the Cordova issues ML, but didn't find anything there. Any other leads that folks are aware of would be appreciated!
Plugins used:
org.apache.cordova.console
org.apache.cordova.device
org.apache.cordova.file
org.apache.cordova.inappbrowser
org.apache.cordova.media
org.apache.cordova.network-information
org.apache.cordova.splashscreen
Relevant email snippet, specific info replaced with [ ]:
From: iTunes Store
Date: Wed, Sep 17, 2014 at 3:49 PM
Subject: iTunes Connect: Your app "[appName]" (Apple ID: [id]) has one or more issues
To: [developer]
Dear developer,
We have discovered one or more issues with your recent delivery for "[app]". Your delivery was successful, but you may wish to correct the following issues in your next delivery:
Missing Push Notification Entitlement - Your app appears to include API used to register with the Apple Push Notification service, but the app signature's entitlements do not include the "aps-environment" entitlement. If your app uses the Apple Push Notification service, make sure your App ID is enabled for Push Notification in the Provisioning Portal, and resubmit after signing your app with a Distribution provisioning profile that includes the "aps-environment" entitlement. See "Provisioning and Development" in the Local and Push Notification Programming Guide for more information. If your app does not use the Apple Push Notification service, no action is required. You may remove the API from future submissions to stop this warning. If you use a third-party framework, you may need to contact the developer for information on removing the API.
After you’ve corrected the issues, you can use Xcode or Application Loader to upload a new binary to iTunes Connect.
Regards,
The App Store team
HOW TO DO THIS VIA THE XCODE UI (6.1):
While commenting out the offending code in Classes\AppDelegate.m will get your app approved, you want to continue benefitting from future Cordova upgrades so the best way to do this is to turn on the DISABLE_PUSH_NOTIFICATIONS symbol during compilation so this bit of code gets left out.
I come from a C# background so I understand conditional compilation but I am new to XCode so I had to do a bit of research finding out how to define compilation symbols via the UI.
Turns out the magic words are 'Preprocessor Macro'. This is how the you can accomplish this graphically (note that this the way its done in XCode 6.1):
Hope this helps other people out there in same situation.
Krik is right ! I've found this API calls in /Classes/AppDelegate.m certainly generated by Cordova 3.5.
I din't tried it for the moment, but these lines can certainly be commented in xCode to avoid Apple's warnings.
- (void) application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// re-post ( broadcast )
NSString* token = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: #"<" withString: #""]
stringByReplacingOccurrencesOfString: #">" withString: #""]
stringByReplacingOccurrencesOfString: #" " withString: #""];
[[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotification object:token];
}
- (void) application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
// re-post ( broadcast )
[[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];
}
Have you had the Push Plugin installed at some point? Sounds like you have the respective Code somewhere in your application package. I'd do a project-wide search for the specific API calls e.g:
didRegisterForRemoteNotificationsWithDeviceToken
didFailToRegisterForRemoteNotificationsWithError
The dead code, files need to be removed.
Heres' the full documentation: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW2
As Charles Merriam points out, newer versions of cordova-ios make it easy to disable touching push notifications by setting the preprocesor flag DISABLE_PUSH_NOTIFICATIONS. (See bug history.)
You will need to cordova platform update ios, platform uninstall ios and platform install ios to get the new in AppDelegate.m. (Maybe there's a better way than blowing away the folder?)
I found a Cordova on_platform_add hook script that will edit project.pbxproj with that flag for you when you install the iOS platform. I needed to npm install xcode to get the hook script to work.
Both kirk and r121 are correct.
In more recent versions of Cordova, this offending code is now helpfully generated inside a wrapper of #ifndef DISABLE_PUSH_NOTIFICATIONS. All you need do is add-DISABLE_PUSH_NOTIFICATIONS to your compiler flags. That's set in target/Build Settings/Custom Compiler Flags/(both C and C++ release) for those building inside XCode.
In our build process, we have been blowing away and rebuilding the AppDelegate.m file a lot. The hack I use is:
sed -i "" -e "s/ifndef DISABLE_PUSH_NOTIFICATIONS/if 0/" build/cordova/platforms/ios/gThrive/Classes/AppDelegate.m
# That uses the os/x sed to not have push notifications in the app
which just makes the problem go away.
I want to create an phonegap app using this plugin. I have done this steps to create and add plugin :
1:I am creatin this app using phonegap cli :-
phonegap create GetPhone --id "com.phone" --name "GetPhoneApp"
2: Going into the project and buid
cd GetPhone
phonegap local build android
3:Installing plugin
phonegap local plugin add https://github.com/macdonst/TelephoneNumberPlugin
4:moving telephonenumber.js to www folder
5: adding
<script type="text/javascript" charset="utf-8" src="telephonenumber.js"></script>
into index.html then added below ondeviceready :-
var telephoneNumber = cordova.require("cordova/plugin/telephonenumber");
telephoneNumber.get(function(result) {
alert("result = " + result);
}, function(error) {
alert("error = " + error.code);
});
6: Added
<plugin name="TelephoneNumber" value="com.simonmacdonald.cordova.plugins.TelephoneNumber"/>
into config.xml in www directory.
7: Build
phonegap local build android
8: Uploaded into build.phonegap.com and created .apk file.
Then when i am running this app on android device it does not alert anything. Is there any wrong step i have taken. I dont know much more about phone gap. After googling i have created this. I have seen this tutorial also to add this plugin. When i am build it locally it does not show any error. But it is also not running.
Please help me find the error.
First of all I would suggest you get acquainted with standard tools, especially adb. These will allow you to provide more information, find out what really is going on.
Skimming through the guide is also helpful, so you can be sure you know what you're doing and why you're doing it. Look at step-by-step debugging of Android code as well.
I would also encourage you to build a Cordova application from sources without using the fancy tools to get the hang of what goes where and how all the components come together. Your source tree is confusing and you seem to have used a mixture of Cordova 3.1 and Cordova 2.9, and even Phonegap? You only need to include cordova.js and your script (js/script.js in this case), nothing else at the moment.
Having said that, on to the major issue.
Your call to get returns an error. Why? Take a quick look at the source code of the plugin:
https://github.com/macdonst/TelephoneNumberPlugin/blob/master/src/com/simonmacdonald/cordova/plugins/TelephoneNumber.java
The plugin retrieves the TelephonyManager and tries to call the getLine1Number. And as you can see result != null is false which drops through to returning a PluginResult.Status.ERROR, which is why you get your error alert box.
This is the core issue at hand. TelephonyManager returning a null for your request. Why? After searching around you might stumble on:
Retrieve phone Number in android
TelephonyManager.getLine1Number() failing?
Reading device phone number throws NULLPointerException
So, navigate over to Settings > About Phone > Status on your device and look at the "My phone number" field. Is it "Unknown"? Tough luck then. My SIM doesn't store the number, so I got the same results as you did.
Another thing to note, is that at least on Android 4.4, the method returns an empty string "" instead of a null, so when testing on my Android 2.3.7 device I got a null and thus got the error branch. But on my Android 4.4.2 device I got a "" and got the success branch, but the number was empty, obviously.
You can set the number on the emulator by using this pretty advanced guide if you'd like to try. So what can you do? Probably nothing by using the API, not even the Android system itself can get your number if it's not stored on the SIM card. Asking the user or sending an SMS to discover the number via a web service may be an option as well.
Step number 5 above will not work unless the code is called after the 'deviceready' event is triggered.
you will need some sort of call to know when the document is loaded, you can do either:
<body onload="onLoad()">
<script>
function onLoad() {
document.addEventListener('deviceready', deviceReady, false);
}
</script>
OR (w/ jquery):
<script>
$(document).ready(function () {
document.addEventListener('deviceready', deviceReady, false);
}
</script>
and then create this function:
function deviceReady() {
var telephoneNumber = cordova.require("cordova/plugin/telephonenumber");
telephoneNumber.get(function(result) {
alert("result = " + result);
}, function(error) {
alert("error = " + error.code);
});
}
This will ensure that your document has loaded and that cordova is ready to call to.
I use the following plugin: marknutter/GCM-Cordova from git hub.
I installed this plugin on eclipse and ran it on an android device.
I manage to register the device for GCM messages + receive messages.
When The device receives a message from Google Cloud, it calls the onMessage event handler, line 55, in this file:
https://github.com/marknutter/GCM-Cordova/blob/master/src/com/cordova2/gcm/GCMIntentService.java
The event handler reaches line 77 to run this command: GCMPlugin.sendJavascript( json );
this commands supposed to send the data received to the webView of the app.
However the static class' GCMPlugin members, are not initialized at all so, when the call to GCMPlugin.sendJavascript( json ) all the members of GCMPlugin members are null. As a result an exception occurs and the message can't be delivered to the webView.
Anyone has an idea how to fix this ?
I would not waste any time trying to run some obscure plug-ins, when there is officially supported PhoneGap plugin for push notifications: https://github.com/phonegap-build/PushPlugin. I'm using it in a couple of my apps already and it works wonders. Updates to it are pushed every couple of months.
If anyone is interested, I'm working on this plugin to support the latest Cordova and using the latest GCM from Google which will allow you to send push notifications to Android and iOS devices: https://github.com/gonzaloaune/GCMPushPlugin
I created an app for iPhone and Android using Phonegap.
Now I wanted to add push functionality which already works pretty good.
When a push message arrives on my iPhone I get a message on the homescreen. If I swipe it, iOS will open my application. - So far so good.
Now, within my PhoneGap app I need to check what that message actually says in order to open the correct view within my app via JavaScript.
I know there are quite some posts about this but I couldn't find some clear answers to these questions:
Does PhoneGap support push messages?
If yes, where is the documentation for that?
If not, which plugins/frameworks can be recommended? So far I found pushwoosh and Urbanair. Are they any good?
Regarding Pushwoosh, I noticed that I need some kind of pushwoosh ID - Why that?
By Pushwoosh ID you most probably mean Pushwoosh App Id or Application Code. It's an ID of your application in Pushwoosh Control Panel (current format is XXXXX-XXXXX). You will see it as soon as you add a new app in Pushwoosh.
There was quite an extensive blog post made by Holly Schinsky on easy PhoneGap integration with Pushwoosh
http://devgirl.org/2012/12/04/easy-phonegap-push-notifications-with-pushwoosh/
It should be very helpful for all PhoneGap developers aiming to integrate push notifications into their apps.
I found a really easy solution without using a framework.
I simply added the following code to the very end of the method didFinishLaunchingWithOptions (Right before the return statement):
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(#"Launched from push notification: %#", dictionary);
[self addMessageFromRemoteNotification:dictionary updateUI:NO];
}
}
Also, I added this new method to my AppDelegate.m which gets the payload from the push message:
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(#"Received notification: %#", userInfo);
[self addMessageFromRemoteNotification:userInfo updateUI:YES];
}
(The NSLog calls above will show you what's inside the push message)
As a last step, I added this listener to do what ever I want with the payload:
- (void)addMessageFromRemoteNotification:(NSDictionary*)userInfo updateUI:(BOOL)updateUI
{
// do what ever you want with userInfo
}
If you want to do an additional JavaScript call with this info, I recommend using:
[self.viewController.webView stringByEvaluatingJavaScriptFromString:#"callSomeJSFunction()"];
Of course you can also pass arguments as strings into that JS function if you want.