ios 检查用户是否禁用了推送通知

标签 ios objective-c push-notification

我想知道用户是否选择在我的应用上禁用推送通知。

我打电话:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];

每次应用程序启动时。但是,如果用户不允许我的应用程序发送推送通知,我想将一些信息发送回服务器。

我正在考虑将此逻辑放入此回调中:

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error

但是,我不确定当用户禁用应用程序接收推送通知时是否会触发此回调,或者是否只是一个错误情况(连接错误等)。如果是这样,我应该查找的错误是什么?

最佳答案

检查下面的代码,它会帮助你:

UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

if (types == UIRemoteNotificationTypeNone) {
    // send info to the server that this user has disallowed push notifications
}

关于ios 检查用户是否禁用了推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22241281/

相关文章:

ios - 添加一个按钮来隐藏键盘

ios - aps-environment 始终在发展

objective-c - 如何检测两个图像的碰撞?

ios - 通过通知打开应用时打开特定 View

ios - 如何从通知区域中删除特定的远程通知

ios - 使用 Parse 的 iOS SDK pod 子规范

ios - Swift - 在后台推送 CollectionView

ios - 无法调用 UIWebView 上的所有功能

ios - UIVIew中的UIButton不在iPhone应用程序中居中

android - react native /博览会 : Push notifications for standalone Apps