Reputation: 61473
I'm a new Objective C programmer and am following the directions here to set up push notification.
When I add the following "optional" code I get an error, and am unable to compile:
- (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];
}
The error is "unexpected "@" in program", located here userInfo objectForKey:@"aps"
.
What is the correct way to write this code?
Upvotes: 1
Views: 74
Reputation: 11675
Checking the page, I could see that there's a minor mistake in the code:
In [[userInfo objectForKey:@"aps"] valueForKey:@”alert”]
, where is @”alert”
should be @"alert"
(” is a different character from ")
This should be enough to get rid of the error.
- (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];
}
Upvotes: 3