Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS unregisterForRemoteNotifications does not work in airplane mode

One of the feature in my app is to unregister user from the remote pushnotification when user logs-out from the app. Is there way I can unregister the app from push notification when user logs out while the device is in airplane(offline) mode?

I tried this code but I still receive notifications when I come back online, [[UIApplication sharedApplication] unregisterForRemoteNotifications];

Could some one help how to remove app from notification center when the device is in airplane mode?

like image 523
user1732255 Avatar asked Oct 09 '12 15:10

user1732255


1 Answers

Apple controls remote push notifications. If you are offline you logically cannot disable it. When Apple first sees you online and pushes are not disabled, it will send you pushes. There is no way to stop the iDevice from showing the pushes that apple sends to the user, as it is not in the hands of the app.

So there is only one possibility: You have to disable the pushes IMMEDIATELY after the device went online again. And still it is a question of luck, what message Apple obtains first, that you are online or that you disable push. And also there is the question, what will happen to the notifications that Apple wanted to send to the device while it was offline. Will it resend them anyway when online or discard them when disabling first? I don't know. You'll need to do the research.

So the only chance you have is if your app is in the background while the user goes online. You'll need to prevent your app from getting suspended (here's how to achieve that) in order to be able to respond to system notifications. The notification that you need is that of change of online status, I only know it exists. This resource may be helpful. When the device goes online it therefore will notify your app which waits in the background (not suspended). Then you can react by unregistering frm remote pushes immediately.

That's the best you possibly could achieve in that direction. Hope this helps.

like image 94
ilmiacs Avatar answered Nov 16 '22 08:11

ilmiacs