我想对部署目标 8.1 和 xcode 6.1 使用远程通知
我正在使用以下代码
if ([application respondsToSelectorselector(registerUserNotificationSettings]) {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
但它在其他部分向我展示了 deprecated 方法......所以现在我该如何摆脱它......
我尝试的其他代码是:
Best Answer-推荐答案 strong>
您可以像这样忽略不推荐使用的警告:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
if ([application respondsToSelectorselector(registerUserNotificationSettings]) {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#pragma clang diagnostic pop
}
#else
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#endif
见 this post :
关于ios - 对部署目标 8.1 和 XCODE 6.1 使用远程通知,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/28980696/
|