iphone - AlertView 正在运行,但未显示 didReceiveRemoteNotification

标签 iphone ios objective-c push-notification

使用调试器,我已确保[alertView show];被调用,但对话框不可见,我还需要做什么才能让它显示?

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if( [[userInfo objectForKey:@"aps"] objectForKey:@"alert"] != NULL)
    {
        NSString *msg = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
        if(msg != nil) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Usage Alert"
            message:msg  delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
            [alertView show];
        }
    }
}

最佳答案

在 View Controller .h 文件中,您需要声明 <UIAlertViewDelegate>像这样,在左大括号之前,用大于和小于符号封装:

#import <UIKit/UIKit.h>

@interface YourViewControllersName : UIViewController <UIAlertViewDelegate> {

   // your variable declarations are here...
}

 // your method declarations are here...

关于iphone - AlertView 正在运行,但未显示 didReceiveRemoteNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14593874/

相关文章:

ios - Swift-UDP接收和发送

ios - Xcode - 将属性传递给 Storyboard 中的 View Controller

iphone - 提醒 IOS 5 UITableView 外观和设计

swift - 模糊框架顶部和底部的 UiImageView

iOS:使用 sqlite3 查询瑞典字母时出现问题

ios - 向 iOS 应用程序添加新语言

objective-c - Objective-C 中的二叉树

iphone - 如何在 UIScrollView 中找到 UIImageView 的缩放因子

iphone - 如何使用 Facebook Open graph api for fitness 步行通过 FacebookSDK

iphone - NSNumber 和 float ?