每次用户登录时,我都需要为设备注册推送通知。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]);
}];
}
问:什么我需要做的,每次打电话给我的应用程序委托,上述方法中用户登录?即该应用程序正在运行。用户注销并以不同的用户名重新登录,现在我需要用该用户名注册设备,我该怎么办?