如何在接收远程通知和当我使用应用程序时显示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