在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结束(无论我是否点击权限对话框上的允许或拒绝按钮)。下次打开我的应用程序时,它会返回正确的授予状态。 如何解决?