我正在使用 UILocalNotification 通知用户他们的日程安排。一切正常,但我想知道是否有一种方法可以在应用程序处于前台时在通知中心显示通知警报。
警报不会在正在运行的应用程序主视图上触发。
请帮帮我。
最佳答案
将这段代码放在 didReceiveRemoteNotification 方法中。
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
{
NSString *cancelTitle = @"OK";
NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Test"
message:message
delegate:self
cancelButtonTitle:cancelTitle
otherButtonTitles:nil, nil];
[alertView show];
} else
{
//Do stuff that you would do if the application was not active
}
关于ios - 当应用程序处于前台时,UILocalNotification 在通知中心显示警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21409989/