Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios check if user has disabled push notifications

I want to tell if a user selected to disable push notifications on my app.

I call:

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

every time the app is launched. However, I want to send some info back to the server in the case where a user has disallowed my application from sending push notifications.

I was thinking about putting that logic in this callback:

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

However, I am unsure if this callback is fired when the user has disabled the app from receiving push notifs or if simply an an error case (connection error, etc). If so, what is the error that I should be looking for?

like image 932
Atul Bhatia Avatar asked Jan 22 '26 01:01

Atul Bhatia


1 Answers

Check below code it will help you:

UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

if (types == UIRemoteNotificationTypeNone) {
    // send info to the server that this user has disallowed push notifications
}
like image 90
jayraj m.g. Avatar answered Jan 24 '26 20:01

jayraj m.g.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!