makerofthings7
makerofthings7

Reputation: 61473

What is incorrect about this Microsoft sample for iOS APNS notification in Azure Mobile Services?

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

Answers (1)

Lucas Eduardo
Lucas Eduardo

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

Related Questions