|
@@ -158,15 +158,7 @@
|
|
|
}
|
|
|
|
|
|
if (needConnect) {
|
|
|
- NSString *access_token = UserDefault(TokenKey);
|
|
|
- // 设置推送别名
|
|
|
- [JPUSHService setAlias:UserDefault(UIDKey) completion:nil seq:0];
|
|
|
- // 上传registrationID
|
|
|
- [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
|
|
|
- if (![NSString isEmptyString:registrationID] && ![NSString isEmptyString:access_token]) {
|
|
|
- [self saveRegisterId:registrationID accessToken:access_token];
|
|
|
- }
|
|
|
- }];
|
|
|
+ [self bandJPush];
|
|
|
[Bugly setUserIdentifier:UserDefault(UIDKey)];
|
|
|
[self connectIM];
|
|
|
}
|
|
@@ -190,6 +182,26 @@
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
+- (void)bandJPush {
|
|
|
+ NSString *access_token = UserDefault(TokenKey);
|
|
|
+ // 因为账号切换,这里绑定别名时,需要增加延迟避免绑定错误
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ NSString *userID = UserDefault(UIDKey);
|
|
|
+ NSString *token = UserDefault(TokenKey);
|
|
|
+ // 确保在登录状态下才设置
|
|
|
+ if (![NSString isEmptyString:userID] && ![NSString isEmptyString:token]) {
|
|
|
+ NSLog(@"------- userId --- %@", userID);
|
|
|
+ [JPUSHService setAlias:UserDefault(UIDKey) completion:nil seq:0];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 上传registrationID
|
|
|
+ [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
|
|
|
+ if (![NSString isEmptyString:registrationID] && ![NSString isEmptyString:access_token]) {
|
|
|
+ [self saveRegisterId:registrationID accessToken:access_token];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
- (void)checkTokenEnableConnectIM {
|
|
|
[self checkTokenEnableCallback:^(BOOL enable) {
|
|
|
if (enable) {
|
|
@@ -342,15 +354,7 @@
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
// 请求头
|
|
|
[self addRequestHeader];
|
|
|
- NSString *access_token = UserDefault(TokenKey);
|
|
|
- // 设置推送别名
|
|
|
- [JPUSHService setAlias:UserDefault(UIDKey) completion:nil seq:0];
|
|
|
- // 上传registrationID
|
|
|
- [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
|
|
|
- if (![NSString isEmptyString:registrationID] && ![NSString isEmptyString:access_token]) {
|
|
|
- [self saveRegisterId:registrationID accessToken:access_token];
|
|
|
- }
|
|
|
- }];
|
|
|
+ [self bandJPush];
|
|
|
[Bugly setUserIdentifier:UserDefault(UIDKey)];
|
|
|
[self connectIM];
|
|
|
[self startUMCountAndLoginCount];
|