查明用户是否已接受接收推送通知?

Find out if user has accepted to receive Push Notifications?

我正在使用这段代码来查明用户是否已接受接收远程通知UIApplication.sharedApplication().isRegisteredForRemoteNotifications() - 但是,即使我点击 "Don't Allow" - 我得到了在我的设备上测试它true 我也得到了设备令牌?

另一方面,在“设置”应用 =>“通知”中,应用设置为不接收任何通知...

那么是否有正确的方法来查明用户是否必须不允许该应用程序接收 APN?

您可以通过currentUserNotificationSettings获取当前的通知设置:

let notificationSettings = UIApplication.sharedApplication().currentUserNotificationSettings()
print("Notification types allowed by user is: \(notificationSettings.types).")

如果用户已禁用通知,类型将为 None