I am new to this topic and require some guidance in implementing Apple Push Notification in my application. I have created my appID and also configured Apple Push Notification for the same. I have downloaded the provisioning profile and installed the app on the iphone. I have also written the following code provided by Apple documentation
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
{
const void *devTokenBytes = [devToken bytes];
NSLog(#"devToken=%#",devTokenBytes);
//self.registered = YES;
//[self sendProviderDeviceToken:devTokenBytes]; // custom method
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
NSLog(#"Error in registration. Error: %#", err);
}
I want to know what I have to write on the server side. When I run the code it says that the device is not registered. How can I register my application for the push notification.
Can anyone help me with this...
Any code will be very helpful...
Thanx in advance...
You need to tell your server about the device token returned by Apple when you register for notifications from the device, so that the server can present the same token and app id when it tells the apple server that there's a new notification. Have you done that? I believe the device token could change each time you register, so you'll need to keep track of that on your server (and tell the server each time).
You've shown the callbacks involved in device registration, but have you actually called the registration method itself?
You also got to listen to didReceiveRemoteNotification in case you want to know when notifications arrive also when the app is in foreground. You might also want to clear the badge number set on the app icon when the user has read the notification it was sent.
Related
I have a iPhone app that uses Push Notifications. My understanding of how this works is I need the "Device Token" of each iPhone before I can send a notification.
Using the test iPhones I have, I can obtain the Device Token from the xcode interface and store them in a data table which the Push Notification PHP script uses to send the notifications.
How do I send the Push Notifications to iPhones that install the app of which I do not know the Device Token ID.
I think my question is; do I need the Device Tokens before I can sent a notification to a iPhone.
If I do require the Device Token, how do I obtain it from iPhones using my app.
You can't receive any Push Notification with the Simulator.
You don't directly send a notification. You said to Apple's servers that there is a notification for this Device Token. Then iPhones themselves will ask automatically to receive push notifications is some are available.
To answer to your question : Yes you do. Without the Device Token you can't register your notification to Apple's server. Then you have to implement this register the device to get the DeviceToken:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
Here is you should look up == Push Notification Programming Guide
- (void)applicationDidFinishLaunching:(UIApplication *)app {
// other setup tasks here....
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}
// Delegation methods
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
const void *devTokenBytes = [devToken bytes];
self.registered = YES;
[self sendProviderDeviceToken:devTokenBytes]; // custom method
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(#"Error in registration. Error: %#", err);
}
See the code from apple Local and Push Notification Programming Guide, first you have to call registerForRemoteNotificationTypes in your app, and then in two delegates, you can get dev token or not, this token is from APNS, so when you get it, you will send it to your service to store it. And you can't get a device token from simulator.
Your push notification service will have to use the device token to send notification to your app, so you will definitely need it. In additional, you will have to get SSL certificates from apple dev center, that requires an valid paid developer ID of iOS.
For more information, please check Push Notification Programming Guide, and it's a great help.
Furthermore, I tried this PHP library to test push notification service, and it's good, you can just find its unit test, and paste the device token there, and run it, you will get message from it.
sly/notification-pusher
I need to check apple push notifications to multiple devices. I am using JavaPNS and the push is working fine. But I have only one device token with me. How can I be sure that in real time (when there will be millions of device tokens - devices) , the push will work fine.
I already saw this:
load testing apple push notification server application
but am not sure that I understand it completely or for that matter is it the correct approach.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
self.mDeviceToken = deviceToken;
//Removing the brackets from the device token
NSString *tokenString = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
NSLog(#"Push Notification tokenstring is %#",tokenString);
}
when you get the token you should send this token to your database using webservice. in that way you will get all the tokens who installed your app.
I have several doubts about APNS. Am trying myself to make clear on the APNS but still need some clarifications. I have to know how we are posting push notification in APN Server and how we push the notification to Apple APN Server? And also how am i receive the notification from Apple and show the notification to user? I know we are receive the Notifications from below delegate,
-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
How we should show the notifications to the user, please suggest any sample codes? Please clarify my silly doubts. Thanks in advance. Please help me.
this tutorial is useful please see
http://mobiforge.com/developing/story/programming-apple-push-notification-services
when you receive push notificaion ,please NSLog userInfo
-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NsLog("%#",userInfo);
}
push notificaion is come only one time , pop is open for about 10 second(Depend on notifcation type)... if you click then didReceiveRemoteNotification delegte is call , if you can't click any reason you see notificaion by go to setting->notification click...and check
if you want store total push notifaction use the database and store in your database
I want to ask about what I need to make a Push Notification, I reed a lot of things and Succeeded send a push from my mac to my devices that exists in the organizer (using PushMeBaby source code). but also I'm confused about make it for other devices (all who has my app) and How I get their Token Device number ?
Just in Big title tell me what I need.
Thanks
Use UIApplication's
- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types
The device token will be returned via callback:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
Then you have to send deviceToken to your server. Note: deviceToken can change from time to time. So you have to check it every time and resubmit to your server if it changes.
Make sure that port 2195 is opened on your router. You should also register your application for remote notifications on Provisioning portal.
Not to promote other peoples stuff but there is an easy way to send notifications with premade code by xtify and Parse google them they are both free.
uninstall the app first, then reinstall, I can receive the push notification normally.
here is my analysis:
client uninstalls app, but my provider server has the devicetoken. then reinstall,APNS delivers the same devicetoken to iphone,so when a new push item comes to APNS,it successly delivers the item to the client.
my app has synchronized devicetoken records with the provider itself,but this problem comes when no launching after reinstall(if the user launch after reinstall,I can remove the register accounts under the devicetoken).how can i solve this problem?
It can not ever be delivered until you save the new device token from
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken