Quellcode durchsuchen

解决ios插件disconnect之后再connect导致事件多监听一次

heavyrian2012 vor 4 Monaten
Ursprung
Commit
63d2a7c7ec

+ 20 - 38
uni-iOS-SDK/HBuilder-ExampleDemo/WFClientUniPlugin/WFClientUniPlugin/ClientModule.m

@@ -49,27 +49,7 @@ UNI_EXPORT_METHOD_SYNC(@selector(initProto))
 - (void)initProto {
     NSLog(@"call client init");
     [WFCCNetworkService sharedInstance].sendLogCommand = @"*#marslog#";
-}
-
-UNI_EXPORT_METHOD_SYNC(@selector(startBugly:))
-- (void)startBugly:(NSString *)appId {
-    NSLog(@"startBugly:%@", appId);
-    [Bugly startWithAppId:appId];
-}
-
-//@UniJSMethod(uiThread = false)
-//public void connect(String imServerHost, String userId, String token) {
-//    this.userId = userId;
-//    this.token = token;
-//    if (mUniSDKInstance.getContext() instanceof Activity) {
-//        ChatManager.Instance().setIMServerHost(imServerHost);
-//        ChatManager.Instance().connect(userId, token);
-//    }
-//}
-UNI_EXPORT_METHOD_SYNC(@selector(connect:userId:token:))
-- (int64_t)connect:(NSString *)host userId:(NSString *)userId token:(NSString *)token {
     [WFCCNetworkService startLog];
-    [[WFCCNetworkService sharedInstance] setServerAddress:host];
     [WFCCNetworkService sharedInstance].connectionStatusDelegate = self;
     [WFCCNetworkService sharedInstance].connectToServerDelegate = self;
     [WFCCNetworkService sharedInstance].receiveMessageDelegate = self;
@@ -93,7 +73,26 @@ UNI_EXPORT_METHOD_SYNC(@selector(connect:userId:token:))
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaUploadProgress:) name:kUploadMediaMessageProgresse object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMessageStatusUpdated:) name:kSendingMessageStatusUpdated object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMessageUpdated:) name:kMessageUpdated object:nil];
-    
+}
+
+UNI_EXPORT_METHOD_SYNC(@selector(startBugly:))
+- (void)startBugly:(NSString *)appId {
+    NSLog(@"startBugly:%@", appId);
+    [Bugly startWithAppId:appId];
+}
+
+//@UniJSMethod(uiThread = false)
+//public void connect(String imServerHost, String userId, String token) {
+//    this.userId = userId;
+//    this.token = token;
+//    if (mUniSDKInstance.getContext() instanceof Activity) {
+//        ChatManager.Instance().setIMServerHost(imServerHost);
+//        ChatManager.Instance().connect(userId, token);
+//    }
+//}
+UNI_EXPORT_METHOD_SYNC(@selector(connect:userId:token:))
+- (int64_t)connect:(NSString *)host userId:(NSString *)userId token:(NSString *)token {
+    [[WFCCNetworkService sharedInstance] setServerAddress:host];
     return [[WFCCNetworkService sharedInstance] connect:userId token:token];
 }
 //
@@ -187,23 +186,6 @@ UNI_EXPORT_METHOD_SYNC(@selector(setProxyInfo:ip:port:username:password:))
 UNI_EXPORT_METHOD_SYNC(@selector(disconnect:clearSession:))
 - (void)disconnect:(BOOL)disablePush clearSession:(BOOL)clearSession {
     [[WFCCNetworkService sharedInstance] disconnect:disablePush clearSession:clearSession];
-    
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:kGroupInfoUpdated object:nil];
-
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:kGroupMemberUpdated object:nil];
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:kUserInfoUpdated object:nil];
-
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:kFriendListUpdated object:nil];
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:kFriendRequestUpdated object:nil];
-
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:kSettingUpdated object:nil];
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:kChannelInfoUpdated object:nil];
-
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:kUserOnlineStateUpdated object:nil];
-
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:kUploadMediaMessageProgresse object:nil];
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:kSendingMessageStatusUpdated object:nil];
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:kMessageUpdated object:nil];
 }
 
 UNI_EXPORT_METHOD_SYNC(@selector(setSendLogCommand:))