每次用戶登錄時,我都需要爲設備註冊推送通知。iOS:推送通知並在登錄時重新註冊設備。
在我AppDelete.m現在我有以下代碼:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert];
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [[token componentsSeparatedByString:@" "] componentsJoinedByString:@""];
[self.pushClient registerDeviceToken:token withUser:loggedInUserName onSuccess:^{
NSLog(@"successful registration");
} onFailure:^(NSError *error) {
NSLog(@"error: %@", [error userInfo]);
}];
}
問:什麼我需要做的,每次打電話給我的應用程序委託,上述方法中用戶登錄?即該應用程序正在運行。用戶註銷並以不同的用戶名重新登錄,現在我需要用該用戶名註冊設備,我該怎麼辦?