rik*_*rse 0 iphone notifications push apple-push-notifications
我正在为Iphone开发推送通知的应用程序.在我的应用程序中,我有两个列表视图(UITableView)第一个用于类别列表,第二个是内容列表.用户单击所需的类别,然后将显示与该类别相关的内容,然后用户将选择内容,并且内容将显示在详细视图中(通常是UIWebView).
推送通知已成功进入我的应用程序.我的要求是: - 点击Push alert的VIEW按钮后,应用程序将直接显示特定的详细视图(UIWebView)[省略类别和内容列表].我有类别和内容的唯一ID.那么请您指导我如何将特定内容与推送通知相关联并直接显示该内容.
感谢致敬.
HI,
我已经解决了这个问题.这就是我所做的.当应用程序收到推送通知时,它会在launchOptions NSDictionary中存储通知.
/* Push notification received when app is not running */
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *params=[[launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] objectForKey:@"contTag"];
if ([params length] > 0 ) {//app launch when VIEW button of push notification clicked
//do some processing
........
WebViewController *webViewController =
[[WebViewController alloc] initWithNibName:@"WebView" bundle:[NSBundle mainBundle]];
// Put your custom code
[[self navigationController ] pushViewController:webViewController animated:YES];
[window addSubview:navigationController.view];
/* Remote Notification Received while application was open. */
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"remote notification: %@",[userInfo description]);
NSString *contentsInfo = [userInfo objectForKey:@"contTag"];
NSLog(@"Received contents info : %@", contentsInfo);
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
NSString *alert = [apsInfo objectForKey:@"alert"];
NSLog(@"Received Push Alert: %@", alert);
NSString *sound = [apsInfo objectForKey:@"sound"];
NSLog(@"Received Push Sound: %@", sound);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
//-----------------------APNS HANDLE----------------
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive){
NSLog(@" It is in active state");
application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
}
else {
if ([contentsInfo length] > 0 ) {
// Do whatever u want for push notification handle
}
Run Code Online (Sandbox Code Playgroud)
注意:此处contTag是服务器端的键集,用于推送通知的工资负载.你可以在服务器端设置任何密钥.
希望它能帮助一些人.谢谢
| 归档时间: |
|
| 查看次数: |
5582 次 |
| 最近记录: |