我刚刚按照本教程推送通知,我成功地为我的 iPhone 应用程序实现了推送通知。我现在可以获得通知详细信息。但是,我想将通知 alertBody 放在为通知 alertBody 提供的标签上。
我有一个代码可以显示来自本地通知的通知 alertBody。但我知道它与推送通知不同,因为它仅用于本地通知。
在我的 AppDelagate.m
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
NSLog(@"Recieved Notification %@",notif);
NSString *_stringFromNotification = notif.alertBody;
[[NSNotificationCenter defaultCenter] postNotificationName:@"Notification" object:_stringFromNotification];
}
在我的 ViewController.m
- (void)viewDidLoad{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserverForName:@"Notification" object:nil queue:nil usingBlock:^(NSNotification *note)
NSString *_string = note.object;
//Do something with the string--------
}];
}
它在本地通知上完美运行,但对于推送通知,它不起作用。如何实施?需要你的帮助。我需要将通知警报正文放在标签或字符串中。