I have an application configured with an API server, and each user creates an account via email or facebook when the application is downloaded. This information is stored in the back. I want to enable push notifications so that they are user specific. I know what needs to be done on the back with an APNS server, etc. My question connects the device token with the user account, so I can send the correct user the correct information based on the logic from my servers.
I know that I put this code in applicationDidFinishLaunching :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible];
And then I take the device id from here:
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { NSLog(@"My token is: %@", deviceToken); } - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { NSLog(@"Failed to get token, error: %@", error); }
I understand correctly that when a user signs up, can I just send the device token to my server and associate it with this user? I can just add an API call attribute to handle it, I just want to make sure that this is in line with expected Apple practices. Then, when the user logs out, I simply clear the device token from my username so that if another user logs on to the same device, I will not have a duplicated token.
Jeffn source share