1
votes

I have implemented ray's awesome tutorials on apns, every thing is working fine, now i have a requirement that the message of push notification will contain a web url, and i have to get that url, the format will be that first there will be a text message in the notification and at the end the url will come, for example, a sample notification message can be

"Hi, Every one Plz. check this video. http:\designers99.com\video\abc.mp3"

now the first text message can be different from this and its length can also be varied so i cant get the substring of url using string index, my requirement is to break that message and retrieve that url from it, plz. guide me in this thanx and regards Saad.

2

2 Answers

2
votes

If you are sending the push notification from your server, then you can achieve it easily,

1) In payload add the key URL with the value http:\designers99.com\video\abc.mp3

2) In your application you can get the payload from notification.userinfo

3) Get the value of url as [notification.userinfo valueForKey:@"URL"]

1
votes

As we know, the message dictionary contains key 'alert', also, you can have your server send the JSON based notification message adding more key like 'url', then you can handle it at

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

NSLog(@"userInfo:%@",[userInfo description]);
NSLog(@"alert:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
NSLog(@"alert:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"url"]);
}

However, notice that there are character length limit in the push notification and you can send shortened urls.