私の問題は、UNUserNotificationCenterをPushNotificationsに使用するために、iOS 9とiOS 10をサポートするためにアプリケーションを更新する必要があります。iOS 10/9プッシュ通知
だから、iOSの9で、私たちは私
- (void)userNotificationsAuthorization :(void (^)(BOOL alertIsActive))completion {
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
completion(settings.alertSetting == UNNotificationSettingEnabled);
}];
}
のようなものは、それを呼び出し、完了ハンドラを経由して、それを手に入れたiOSの10で
- (BOOL)alertEnabled {
UIUserNotificationSettings *theSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
return [theSettings types] & UIUserNotificationTypeAlert;
}
ようUIUserNotificationSettingsの結果を返すメソッドを持っています。
私の質問:getNotificationSettingsWithCompletionHandlerと返り値の代わりに、私はが方法をalertEnabled私にそれを使用することができます完了ハンドラを使用するには、いくつかの可能性はありますか?
ありがとうございます。
アップデート:この方法で
それは
- (BOOL)alertIsEnabled {
__block BOOL alertIsActive = NO;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
alertIsActive = settings.alertSetting == UNNotificationSettingEnabled;
dispatch_semaphore_signal(sem);
}];
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
}
else {
UIUserNotificationSettings *theSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
alertIsActive = [theSettings types] & UIUserNotificationTypeAlert;
}
return alertIsActive;
}
を働いているが、おそらくよりよい解決策だから、