AlertView正在运行但未显示didReceiveRemoteNotification

时间:2013-01-29 23:16:47

标签: 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];
        }
    }
}

2 个答案:

答案 0 :(得分:2)

在你的视图控制器.h文件中,你需要声明<UIAlertViewDelegate>这样,在开始花括号之前,用大于和小于符号封装:

#import <UIKit/UIKit.h>

@interface YourViewControllersName : UIViewController <UIAlertViewDelegate> {

   // your variable declarations are here...
}

 // your method declarations are here...

答案 1 :(得分:0)

对不起大家来说,这对我的编译器/ xCode来说是一个问题,实际上并没有认识到我放入的代码或者其他类似的东西,环境被破坏了。