Apple Push notification with user data submission

I am sending push notifications from a php application on iphone. I am sending push notifications of new jobs. Is it possible that when the user clicks on the push notification view, pops up, then the user is redirected to a specific task on the device.

I would like to know if I can send any user data with a push notification, such as jobId, something else ... so that the end of the Iphone can retrieve and show the specific work?

Thank.

+47
php iphone apple-push-notifications
Nov 15 '11 at 9:32
source share
3 answers

Regardless of the language and library you are using, the push message payload is the JSON payload:

{ "aps": { "badge": 10, "alert": "Hello world!", "sound": "cat.caf" } } 

aps current is Apple APN data. You can also add your data to your payload:

 { "aps": { "badge": 10, "alert": "Hello world!", "sound": "cat.caf" }, "job_id": 1 } 

When you receive a notification in the application, check your setting in the notification dictionary:

 - (void)handleBackgroundNotification:(NSDictionary *)notification { NSDictionary *aps = (NSDictionary *)[notification objectForKey:@"aps"]; NSMutableString *alert = [NSMutableString stringWithString:@""]; if ([aps objectForKey:@"alert"]) { [alert appendString:(NSString *)[aps objectForKey:@"alert"]]; } if ([notification objectForKey:@"job_id"]) { // do something with job id int jobID = [[notification objectForKey:@"job_id"] intValue]; } } 

Keep in mind that the total payload size is 256 bytes, and this of course includes your user parameters. Thus, you may need to (in order to reduce readability) call your own parameter "ji" instead of "job_id" to compress the bytes.

All of this is described in the Local and Push Notification Programming Guide in the iOS documentation. Definitely recommend reading because it is more complex than it originally sounds (at least what I thought).

+113
Nov 15 2018-11-11T00:
source share

Yes, you can send user data, check the apns-php library for all the needs of push notifications:

+8
Nov 15 2018-11-11T00:
source share

We can add some user data, but if I use sub_action as the name, my iPhone cannot receive push msg

Java:

 PayLoad payLoad = new PayLoad(); payLoad.addCustomDictionary("action", action_type); payLoad.addCustomDictionary("subaction", sub_action_type); 
0
May 19 '15 at 8:34
source share



All Articles