【发布时间】:2014-01-28 15:37:11
【问题描述】:
我正在使用 UILocalNotification 来通知用户他们的日程安排。一切正常,但我想知道当应用程序处于前台时是否有办法在通知中心显示通知警报。
在运行应用程序主视图时不会触发警报。
请帮帮我。
【问题讨论】:
-
请帮助我,如果应用程序在前台,是否可以在通知中心显示通知。
标签: ios iphone uilocalnotification
我正在使用 UILocalNotification 来通知用户他们的日程安排。一切正常,但我想知道当应用程序处于前台时是否有办法在通知中心显示通知警报。
在运行应用程序主视图时不会触发警报。
请帮帮我。
【问题讨论】:
标签: ios iphone 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
}
【讨论】: