From aa0be917b18ac1d1bb1d8bd44cc1f2dc402c664a Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Fri, 15 Aug 2025 17:32:13 +0800 Subject: [PATCH] =?UTF-8?q?iOS=20=E9=9F=B3=E4=B9=90=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=A4=9A=E6=AC=A1=E9=97=AE=E9=A2=98=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/qq_music/QPlayAutoManager.swift | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/local_plugins/qq_music/ios/qq_music/Sources/qq_music/QPlayAutoManager.swift b/local_plugins/qq_music/ios/qq_music/Sources/qq_music/QPlayAutoManager.swift index 57aa637a8..4c0f5bb0a 100644 --- a/local_plugins/qq_music/ios/qq_music/Sources/qq_music/QPlayAutoManager.swift +++ b/local_plugins/qq_music/ios/qq_music/Sources/qq_music/QPlayAutoManager.swift @@ -239,7 +239,12 @@ import QPlayAutoSDK guard retryCount > 0 else { print("QPlayAutoManager: ❌ 连接失败,所有重试次数已用完") print("QPlayAutoManager: 最终状态 - isConnected: \(isConnected), isLoginOK: \(isLoginOK)") - notifyLoginCompletion(false) + + // 只有在所有重试都失败且确实有待处理回调时才清理 + if !loginCompletionHandlers.isEmpty { + print("QPlayAutoManager: 清理登录回调队列") + notifyLoginCompletion(false) + } return } @@ -248,7 +253,7 @@ import QPlayAutoSDK QPlayAutoSDK.connectAndForceLogin(forceLogin) // If connection fails due to socket error, retry after cleanup - DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { + DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { let endTime = Date() let duration = endTime.timeIntervalSince(startTime) @@ -404,9 +409,9 @@ import QPlayAutoSDK // 强制登录,会跳转到QQ音乐 connect(forceLogin: true) - // 设置超时检查 - DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) { [weak self] in - self?.checkLoginTimeout() + // 设置超时监控(仅记录,不清理回调) + DispatchQueue.main.asyncAfter(deadline: .now() + 30.0) { [weak self] in + self?.logLoginTimeout() } } @@ -422,16 +427,16 @@ import QPlayAutoSDK return currentTime.timeIntervalSince(loginTime) <= Self.TOKEN_EXPIRE_TIME } - private func checkLoginTimeout() { - print("QPlayAutoManager: ⏰ 检查登录超时") + private func logLoginTimeout() { + print("QPlayAutoManager: ⏰ 登录超时监控") print("QPlayAutoManager: 当前状态 - 队列长度: \(loginCompletionHandlers.count), isLoginOK: \(isLoginOK)") + print("QPlayAutoManager: 连接状态 - isConnected: \(isConnected), isConnecting: \(isConnecting)") if !loginCompletionHandlers.isEmpty && !isLoginOK { - print("QPlayAutoManager: ❌ 登录超时,清理回调队列") - print("QPlayAutoManager: 超时时状态 - isConnected: \(isConnected), isQQMusicInstalled: \(isQQMusicInstalled)") - notifyLoginCompletion(false) + print("QPlayAutoManager: ⚠️ 登录可能超时,但保留回调等待最终结果") + print("QPlayAutoManager: 如果确实超时,将由重试机制或连接失败回调处理") } else if isLoginOK { - print("QPlayAutoManager: ✅ 登录已完成,无需超时处理") + print("QPlayAutoManager: ✅ 登录已完成") } else { print("QPlayAutoManager: 无待处理的登录请求") } @@ -811,13 +816,17 @@ extension QPlayAutoManager: QPlayAutoSDKDelegate { print("QPlayAutoManager: Login state changed to \(isLoginOK)") _isLoginOK = isLoginOK - // 登录成功时保存token + // 登录成功时保存token并通知回调 if isLoginOK { saveLoginToken() + print("QPlayAutoManager: ✅ 登录成功,通知所有等待的回调") notifyLoginCompletion(true) } else { // 登录失败时清除可能无效的token clearStoredToken() + print("QPlayAutoManager: ❌ 登录失败,但不立即清理回调(等待重试或最终失败)") + // 注意:这里不立即调用 notifyLoginCompletion(false) + // 让重试机制来决定是否最终失败 } // 通知所有代理