Azure移动服务中针对iOS APNS通知的此Microsoft示例有何不正确之处?

问题描述 投票:1回答:1

我是一名新的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"

编写此代码的正确方法是什么?

ios objective-c azure azure-mobile-services
1个回答
3
投票

检查页面,我可以看到代码中有一个小错误:

[[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];
}
© www.soinside.com 2019 - 2024. All rights reserved.