我已将我的应用程序编码为在 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/