我剛剛按照本教程Push notification,我成功實現了我的iPhone應用程序的推送通知。我能夠得到現在的通知細節。但是,我想將通知alertBody放在提供通知alertBody的標籤上。如何從我的應用程序從遠程推送通知中獲取notification.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--------
}];
}
它完美對本地通知,但對於推送通知,它不工作。如何實現這一點?需要你的幫助。我需要將通知警報主體放在標籤或字符串處。