我是一名新的Objective C程序员和am following the directions here to set up push notification。
当我添加以下“可选”代码时,我收到错误,无法编译:
- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo {
NSLog(@"%@", userInfo);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notification" message:
[[userInfo objectForKey:@"aps"] valueForKey:@”alert”] delegate:nil cancelButtonTitle:
@"OK" otherButtonTitles:nil, nil];
[alert show];
}
错误是“意外”@“在程序中”,位于这里userInfo objectForKey:@"aps"
。
编写此代码的正确方法是什么?
检查页面,我可以看到代码中有一个小错误:
在[[userInfo objectForKey:@"aps"] valueForKey:@”alert”]
,@”alert”
应该是@"alert"
(“与...不同”)
这应该足以摆脱错误。
- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo {
NSLog(@"%@", userInfo);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notification" message:
[[userInfo objectForKey:@"aps"] valueForKey:@"alert"] delegate:nil cancelButtonTitle:
@"OK" otherButtonTitles:nil, nil];
[alert show];
}