Reputation: 143
I need to get deviceToken.
When I added push notification to my app I received deviceToken via didRegisterForRemoteNotificationsWithDeviceToken
but now I need to get it again and i didnt save is.
didRegisterForRemoteNotificationsWithDeviceToken
calls just once and other times app runs just registerUserNotificationSettings
I thought to save tokens from all new users to [NSUserDefaults standardUserDefaults]
but it will work just for new ones. What to do with current users?
Upvotes: 1
Views: 824
Reputation: 3706
Add the following code in “didFinishLaunchingWithOptions” method…
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
Then “didRegisterForRemoteNotificationsWithDeviceToken” method will be called on every call of “didFinishLaunchingWithOptions” during app launching.
Upvotes: 1