我正在使用UILocalNotification通知用户他们的日程安排。一切正常,但我想知道当应用程序处于前台时,是否有办法在通知中心显示通知警报。
在运行应用程序主视图时不会触发警报。
请帮帮我。
答案 0 :(得分:2)
将此代码放入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
}