我在尝试请求远程通知权限时遇到问题。
它在 iOS 10 上完美运行,但是当我尝试在 iOS 9 设备上执行此操作时,它没有显示任何警报,并且 UIApplication 委托方法“application:didRegisterForRemoteNotificationsWithDeviceToken:”没有被调用。既不是“失败”的方法。
我只在真实设备上测试,而不是模拟器。我目前用于请求权限的代码如下:
-(void)requestPushPermissions {
NSLog(@"Starting register for remote Notification");
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
NSLog(@"Got a yes!");
}
else {
NSLog(@"Got a no...");
}
}];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else {
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}
有人有线索吗?