Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS - How to disable push notification at logout?

My app registers the account at login in my server to enable push notification for a chat. Yet I haven't implemented yet the unregistration of the account at logout, so in this moment if I do the login with 2 accounts in the same device it can take the notification of both the accounts. At the same time, my notification center has a POST service which unregisters the 'login_name+ device token' from receive notification center. Where should I call it? Do I have to use unregisterForRemoteNotifications? I just want to unregister the account+Device token from push notification, not to disable the entire app notification forever.

Can I save my device token on didRegisterForRemoteNotificationsWithDeviceToken function like

 $ [[NSUserDefaults standardUserDefaults] setObject:hexToken forKey:DEVICE_KEY];

and then, at logout, call my POST function "removeDeviceToken" like

  NSString *deviceToken = [userDefaults objectForKey:DEVICE_KEY];
    if(deviceToken != NULL){
       [self.engine removeDeviceToken:deviceToken];
     }
like image 547
Alessio Crestani Avatar asked Dec 03 '13 08:12

Alessio Crestani


People also ask

How do I turn off push notifications on my iPad?

If you are using an iPad, it is located on the left of the screen. In any version of iOS preceding iOS 5, navigating to Notifications settings opens a list of apps that send push notifications and the kind of notifications they send. Above this list, the Notifications swipe button lets you disable all notifications entirely.

How do I resubmit my App ID for push notification?

If your app uses the Apple Push Notification service, make sure your App ID is enabled for Push Notification in the Provisioning Portal, and resubmit after signing your app with a Distribution provisioning profile that includes the "aps-environment" entitlement.

What are the different types of push notifications on iOS devices?

In general, push notifications on iOS devices can be classified into two types – Temporary and persistent. Temporary: These type of Push Notifications appear momentarily at the top of the screen and then disappear after about 3-4 seconds.

Why are my Push Notification signatures not working?

Missing Push Notification Entitlement - Your app appears to include API used to register with the Apple Push Notification service, but the app signature's entitlements do not include the "aps-environment" entitlement.


1 Answers

In general it is a bad idea to unregisterForRemoteNotifications after logout and reregister after login. The reason is simple: if the user logins with another account and you don't specifically check for token overlapping in server, the user will start receiving double notifications.

like image 73
TheLegend27 Avatar answered Nov 01 '22 19:11

TheLegend27