,
#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 @"";
}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
call, [AppDelegate setDeviceToken:token]; ,
Now in the project, in any view controller, you can call NSString *token = [AppDelegate getDeviceToken];to get the saved token, here, note that we call it with AppDelegateyour delegate file name, and we call it with the class name, because we create a class method to set and receive the token .
At the time of receipt, you can check for the presence of a stored token
NSString *token = [AppDelegate getDeviceToken];
if(token.length) {
}
source
share