似乎无法确定是否已显示允许弹出窗口。我依靠用户默认值来跟踪这一点:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
BOOL didRegisterForPush = [[NSUserDefaults standardUserDefaults] boolForKey:@"didRegisterForPush"];
if (!didRegisterForPush) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"didRegisterForPush"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
// .. send deviceToken to server
}
现在您可以使用以下方法确定授权状态:
- (PushAuthorizationStatus)pushAuthorizationStatus
{
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types) {
return kPushAuthorizationStatusAuthorized;
}
BOOL didRegisterForPush = [[NSUserDefaults standardUserDefaults] boolForKey:@"didRegisterForPush"];
if (didRegisterForPush) {
return kPushAuthorizationStatusDenied;
}
return kPushAuthorizationStatusNotDetermined;
}
使用它,您可以将NotDetermined
状态发送到服务器而不是Denied
.