当app在前台时,UILocalNotification在通知中心显示警报

时间:2014-01-28 15:37:11

标签: ios iphone uilocalnotification

我正在使用UILocalNotification通知用户他们的日程安排。一切正常,但我想知道当应用程序处于前台时,是否有办法在通知中心显示通知警报。

在运行应用程序主视图时不会触发警报。

请帮帮我。

1 个答案:

答案 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
}