2

在 AppDelegate 的 didFinishLaunchingWithOptions 中,我实现了获取授权状态的代码。

UNAuthorizationOptions authOptions = (UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound);
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
    if (granted) {
        [application registerForRemoteNotifications];
    }
}];

但是, UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions 在完成处理程序中总是以granted = false 结束(无论我是点击权限对话框上的允许还是拒绝按钮)。下次我打开我的应用程序时,它会返回正确的授予状态。如何解决?

4

0 回答 0