Browse Source

iOS 音乐授权连接多次问题修复

newdev_shunjiawei
liwei1dao 1 year ago
parent
commit
fb626c0acf
  1. 31
      local_plugins/qq_music/ios/qq_music/Sources/qq_music/QPlayAutoManager.swift

31
local_plugins/qq_music/ios/qq_music/Sources/qq_music/QPlayAutoManager.swift

@ -239,7 +239,12 @@ import QPlayAutoSDK
guard retryCount > 0 else { guard retryCount > 0 else {
print("QPlayAutoManager: ❌ 连接失败,所有重试次数已用完") print("QPlayAutoManager: ❌ 连接失败,所有重试次数已用完")
print("QPlayAutoManager: 最终状态 - isConnected: \(isConnected), isLoginOK: \(isLoginOK)") print("QPlayAutoManager: 最终状态 - isConnected: \(isConnected), isLoginOK: \(isLoginOK)")
// 只有在所有重试都失败且确实有待处理回调时才清理
if !loginCompletionHandlers.isEmpty {
print("QPlayAutoManager: 清理登录回调队列")
notifyLoginCompletion(false) notifyLoginCompletion(false)
}
return return
} }
@ -248,7 +253,7 @@ import QPlayAutoSDK
QPlayAutoSDK.connectAndForceLogin(forceLogin) QPlayAutoSDK.connectAndForceLogin(forceLogin)
// If connection fails due to socket error, retry after cleanup // 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 endTime = Date()
let duration = endTime.timeIntervalSince(startTime) let duration = endTime.timeIntervalSince(startTime)
@ -404,9 +409,9 @@ import QPlayAutoSDK
// 强制登录,会跳转到QQ音乐 // 强制登录,会跳转到QQ音乐
connect(forceLogin: true) connect(forceLogin: true)
// 设置超时检查 // 设置超时监控(仅记录,不清理回调)
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) { [weak self] in DispatchQueue.main.asyncAfter(deadline: .now() + 30.0) { [weak self] in
self?.checkLoginTimeout() self?.logLoginTimeout()
} }
} }
@ -422,16 +427,16 @@ import QPlayAutoSDK
return currentTime.timeIntervalSince(loginTime) <= Self.TOKEN_EXPIRE_TIME return currentTime.timeIntervalSince(loginTime) <= Self.TOKEN_EXPIRE_TIME
} }
private func checkLoginTimeout() { private func logLoginTimeout() {
print("QPlayAutoManager: ⏰ 检查登录超时") print("QPlayAutoManager: ⏰ 登录超时监控")
print("QPlayAutoManager: 当前状态 - 队列长度: \(loginCompletionHandlers.count), isLoginOK: \(isLoginOK)") print("QPlayAutoManager: 当前状态 - 队列长度: \(loginCompletionHandlers.count), isLoginOK: \(isLoginOK)")
print("QPlayAutoManager: 连接状态 - isConnected: \(isConnected), isConnecting: \(isConnecting)")
if !loginCompletionHandlers.isEmpty && !isLoginOK { if !loginCompletionHandlers.isEmpty && !isLoginOK {
print("QPlayAutoManager: ❌ 登录超时,清理回调队列") print("QPlayAutoManager: ⚠️ 登录可能超时,但保留回调等待最终结果")
print("QPlayAutoManager: 超时时状态 - isConnected: \(isConnected), isQQMusicInstalled: \(isQQMusicInstalled)") print("QPlayAutoManager: 如果确实超时,将由重试机制或连接失败回调处理")
notifyLoginCompletion(false)
} else if isLoginOK { } else if isLoginOK {
print("QPlayAutoManager: ✅ 登录已完成,无需超时处理") print("QPlayAutoManager: ✅ 登录已完成")
} else { } else {
print("QPlayAutoManager: 无待处理的登录请求") print("QPlayAutoManager: 无待处理的登录请求")
} }
@ -811,13 +816,17 @@ extension QPlayAutoManager: QPlayAutoSDKDelegate {
print("QPlayAutoManager: Login state changed to \(isLoginOK)") print("QPlayAutoManager: Login state changed to \(isLoginOK)")
_isLoginOK = isLoginOK _isLoginOK = isLoginOK
// 登录成功时保存token // 登录成功时保存token并通知回调
if isLoginOK { if isLoginOK {
saveLoginToken() saveLoginToken()
print("QPlayAutoManager: ✅ 登录成功,通知所有等待的回调")
notifyLoginCompletion(true) notifyLoginCompletion(true)
} else { } else {
// 登录失败时清除可能无效的token // 登录失败时清除可能无效的token
clearStoredToken() clearStoredToken()
print("QPlayAutoManager: ❌ 登录失败,但不立即清理回调(等待重试或最终失败)")
// 注意:这里不立即调用 notifyLoginCompletion(false)
// 让重试机制来决定是否最终失败
} }
// 通知所有代理 // 通知所有代理

Loading…
Cancel
Save