Declare and define below methods in your delegate file,
#pragma mark - Get / Set Device Token
+ (void)setDeviceToken:(NSString *)token {
if(token) {
[[NSUserDefaults standardUserDefaults] setObject:token forKey:@"DeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
+ (NSString *)getDeviceToken {
NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"DeviceToken"];
if(token) {
return token;
}
return @"";
}
In -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
method
call, [AppDelegate setDeviceToken:token];
once you get the token and
Now in project, in any view controller, you can call NSString *token = [AppDelegate getDeviceToken];
to get saved token, here note that, we call it with AppDelegate
its name of your delegate file, and we call it with the class name, as we make a class method to set and get a token.
At the time of getting you can check for availability of saved token
NSString *token = [AppDelegate getDeviceToken];
if(token.length) {
// do something
}