I am not sure if I received it correctly, but if you do not want to disable push notifications for the application, you should not call unregisterForRemoteNotifications. What can you do when a user deletes the logout button, you can make a request to log out to your server, which then removes the notification ID from this account, and after completing the logout request, you simply do a local logout (update the interface, etc. d.).
Read more about comments:
Yes, first of all, you must call the registerForRemoteNotificationTypes method every time you start, because the device token can change. After the delegate method
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
Called
You can get the device token and save it in NSUserDefault. Thus, when the user logs in, you can get the updated device token (if changed) and send it to your server to add to this account.
So the code might look like this:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken { NSString *newToken = [devToken description]; newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""]; NSString *notificationID = [newToken description]; NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; [prefs setObject:notificationID forKey:@"notification_id"]; [prefs synchronize]; }
So, now that the user is logged in, just get the notification ID and send it to your server
- (IBAction)userTappedLoginButton {
mrt
source share