如何在接收遠程通知和當我使用應用程序時顯示UILocalNotification
?不是UIAlertView
?如何在接收遠程通知時顯示UILocalNotification?
我使用此代碼,但它沒有顯示任何
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
for (id key in userInfo) {
NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
}
localNotification = [[UILocalNotification alloc] init];
NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
localNotification.applicationIconBadgeNumber = 0;
localNotification.alertBody = message;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertAction = @"ok!!!";
[application scheduleLocalNotification:localNotification];
}
我也試過:
[application presentLocalNotificationNow:localNotification];
但它不工作了。
任何人都可以幫忙嗎?
雖然這可能在理論上回答這個問題,但[這將是更可取的](// meta.stackoverflow.com/q/8259)在這裏包括答案的基本部分,並提供供參考的鏈接。 – 2016-04-16 12:31:58