Kex*_*Ari 3 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];
}
Run Code Online (Sandbox Code Playgroud)
和:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
我测试了两个版本的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
Run Code Online (Sandbox Code Playgroud)
看到这些警告是否正常,是否因为我在更高的部署目标中工作?或者我必须在某处更改代码?似乎很奇怪我必须看到这些警告.任何指针都会非常感激.谢谢!
如果您将部署目标更改为iOS 8,那么无需检查iOS 8(在iOS 8之前,因为您的应用程序仅适用于iOS 8设备),这就是为什么它会为您提供这些警告.所以只需这样注册:
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
Run Code Online (Sandbox Code Playgroud)