【问题标题】:UILocalNotification display alert on notification center when app is in foreground当应用程序处于前台时,UILocalNotification 在通知中心显示警报
【发布时间】:2014-01-28 15:37:11
【问题描述】:

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

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

请帮帮我。

【问题讨论】:

  • 请帮助我,如果应用程序在前台,是否可以在通知中心显示通知。

标签: ios iphone uilocalnotification


【解决方案1】:

将此代码放入 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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-13
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多