每次用户登录时,我都需要为设备注册推送通知。
现在在我的 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]);
}];
}
Q. 每次用户登录时,我需要怎么做才能在我的 App Delegate 中调用上述方法?即应用程序正在运行。用户注销并使用不同的用户名重新登录,现在我需要使用该用户名注册设备,我该怎么办?