2014-03-07 40 views
3

我想告诉用户是否选择在我的应用上禁用推送通知。ios检查用户是否禁用推送通知

我呼吁:每一个应用程序启动时间

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

。但是,我想在用户拒绝我的应用程序发送推送通知的情况下将一些信息发送回服务器。

我还想着把这个逻辑在这个回调:

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

不过,我不能确定这是否回调,当用户已禁用从接收推notifs的应用程序,或者只是一个错误的情况下解雇(连接错误等)。如果是这样,我应该寻找哪些错误?

+0

好问题。尝试在标准用户默认值中维护和保存BOOL值。 – 2014-03-07 04:14:22

回答

3

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

UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 

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

这不起作用。如果您禁用了推送通知,但未将单个开关关闭,您仍然会收到一个大于0的值。 –

相关问题