Is possible to send an iOS push notification to a specific device? I've built a forum type app which the user can create a question and other people can answer it. I need to send an iOS Push Notification to the specific user which asked the question informing them that the question was answered. Is this possible to be done through PHP or another method?
4 Answers
Yes, you can absolutely send a push notification to a specific device.
First you need to ask the device for permission to receive push notifications:
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
Then if the user accepts you will receive the delegate message didRegisterForRemoteNotificationsWithDeviceToken. You then pass that deviceToken to your server with the user Id from your app that identifies the user in your forum. Something like this:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {
NSString* deviceToken = [[[[_deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
//send deviceToken and your userId to your server to associate the two together
}
Then you need to build your push server which sends the notifications, which I won't get into here as there is a ton of documentation online for that and it is quite involved. You can also use third party services for this such as Urban Airship and StackMob.

- 15,654
- 5
- 37
- 60
-
1+1. Wait, you're relying on the format of `- [NSData description]`? Revoked upvote. – Oct 03 '12 at 20:30
When you send push notification, the device gets an unique ID which you use to send to Apple to tell them whom to deliver the message to.
When you get this unique ID you send it off to your server, when you do that you can include any other data such as username, refs ect.
Its more of a server-side issue than an iOS issue.

- 10,073
- 15
- 85
- 168
Mateus,
tl;dr: Yes, you can.
Since your forum app is written in php, here are some frameworks that may be useful to you:
If you end up using Easy APNS: You can send messages to a single user (like in your example), or to a group of users (maybe everyone who is "watching" that thread) using an array of user identifiers. Quite a few examples are available here: https://github.com/manifestinteractive/easyapns/blob/master/src/php/samples.php

- 4,232
- 3
- 23
- 31
Sure, there are a lot of free Push Notification servers - for example QuickBlox You don't need any server code, QuickBlox already wrote all for you.
Just look at Push Notifications iOS sample - This sample enables you to send notifications and alerts to particular user or group of users at any time through an API or easy-to-use admin panel. Just download it, move some code from it to your app - and enjoy it.

- 18,156
- 10
- 49
- 70