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?
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):
Also, I added this new method to my AppDelegate.m which gets the payload from the push message:
(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:
If you want to do an additional JavaScript call with this info, I recommend using:
Of course you can also pass arguments as strings into that JS function if you want.