ios - 注册 Parse 通知 iOS7 和 iOS8,编译器警告

标签 ios parse-platform

我已将我的应用程序编码为在 iOS8 中接收 Parse 通知,最近发现这些在 iOS 中不起作用&因此不得不将我的代码更改为 AppDelegate.m 中的如下代码:

viewDidLoad:

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        NSLog(@"Requesting permission for push notifications...iOS8"); // iOS 8
        UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                        UIUserNotificationTypeBadge |
                                                        UIUserNotificationTypeSound);
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
        [application registerUserNotificationSettings:settings];
        [application registerForRemoteNotifications];
    } else {
        NSLog(@"Registering device for push notifications..."); // iOS 7 and earlier
        [UIApplication.sharedApplication registerForRemoteNotificationTypes:
         UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |
         UIRemoteNotificationTypeSound];
    }

和:

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    // Store the deviceToken in the current Installation and save it to Parse.
    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    [currentInstallation setDeviceTokenFromData:deviceToken];
    [currentInstallation saveInBackground];
}

我在两个版本的 iOS 上都进行了测试,似乎都运行良好。但是,如果我将 Xcode 中的部署目标更改为 iOS8 或更高版本,我会收到以下编译器警告:

AppDelegate.m:62:10: 'UIRemoteNotificationTypeAlert' is deprecated: first deprecated in iOS 8.0 - Use UIUserNotificationType for user notifications and registerForRemoteNotifications for receiving remote notifications instead.

AppDelegate.m:62:42: 'UIRemoteNotificationTypeBadge' is deprecated: first deprecated in iOS 8.0 - Use UIUserNotificationType for user notifications and registerForRemoteNotifications for receiving remote notifications instead.

AppDelegate.m:63:10: 'UIRemoteNotificationTypeSound' is deprecated: first deprecated in iOS 8.0 - Use UIUserNotificationType for user notifications and registerForRemoteNotifications for receiving remote notifications instead.

/AppDelegate.m:61:42: 'registerForRemoteNotificationTypes:' is deprecated: first deprecated in iOS 8.0 - Please use registerForRemoteNotifications and registerUserNotificationSettings: instead

看到这些警告是否正常,是否只是因为我在更高的部署目标中工作?还是我必须在某处更改代码?我不得不看到这些警告似乎很奇怪。任何指针将不胜感激。谢谢!

最佳答案

如果您将部署目标更改为 iOS 8,则无需检查是否支持 iOS 8(在 iOS 8 之前,因为您的应用程序只能在 iOS 8 设备上运行),这就是为什么它会向您发出这些警告。所以只需像这样注册:

[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

关于ios - 注册 Parse 通知 iOS7 和 iOS8,编译器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29674222/

相关文章:

ios7 - 在 Parse 后端删除一个 tableview 对象

ios - 无法从 AppDelegate 中实例化 rootViewController

ios - 分组的 UITableView 和水平边距

ios - 快速保存变量

ios - 将用户输入从文本字段存储到解析数据库

ios - 我正在尝试在我的应用程序中实现搜索栏,以便我可以搜索从 parse.com 检索到的对象

ios - 如何访问 Parse 数据库中的指针值

iPhone- Twitter API GET Users Followers/Following 用户

objective-c - 使用异常处理程序捕获iOS中低内存崩溃的统计信息

php - 查看 JSON 提要 Swift 3.0