ios - 当应用程序处于前台时,UILocalNotification 在通知中心显示警报

标签 ios iphone uilocalnotification

我正在使用 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/

相关文章:

ios - 带有自定义 init 的 UIView 不起作用

ios - UITableViewCell 中的 UIButton

iphone - 如何在 OpenGLES 中翻转 Sprite /纹理?

iphone - Xcode ProcessPCH iPhone模拟器编译报错

ios - 确定用户是否允许 iOS 7 中的本地通知

ios - 获取地址簿权限会使应用程序 iOS 崩溃

ios - 为什么 ubiquityIdentityToken 总是为零?

iphone - UISearch 不显示结果

objective-c - 在后台安排 LocalNotifications 时应用卡住

ios - 如何从日期数组创建 ios LocalNotification?