iOS端Flutter集成TapKey SDK启动foregroundScan失败求助
iOS端TapKey SDK开锁功能异常排查
原本运行正常的Flutter+TapKey SDK开锁功能,iOS端突然报错,已确认蓝牙权限已授予:
- 错误1:
[CoreBluetooth] XPC connection invalid - 错误2:
[general] NetTpkyMcBleBleScannerImpl: failed to start foregroundScan: TapkeyMobileLib.TKMAsyncError
无法确定是权限问题还是SDK本身问题,相关代码如下:
相关代码
AppDelegate.swift
let tapKey = TapKey() methodChannel.setMethodCallHandler({ (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in switch call.method { case "login": let blueStart = tapKey.TKMBleLockScanner.startForegroundScan() blueStart let map : Dictionary = call.arguments as! [String: String] let token = map["access_token"] let lockID = map["lock_id"] let userID = tapKey.login(accessToken: token!) userID.continueOnUi{ (uID) -> Void in if(uID != nil) { tapKey.padlock(userID: uID!, lockID: lockID!).continueOnUi { (lock) -> Void in if(lock == "Lock is now open") { result(lock) blueStart.close() } else { tapKey.padlock(userID: uID!, lockID: lockID!).continueOnUi { (lock) -> Void in if(lock == "Lock is now open") { result(lock) blueStart.close() } else { tapKey.padlock(userID: uID!, lockID: lockID!).continueOnUi { (lock) -> Void in if(lock == "Lock is now open") { result(lock) blueStart.close() } else { result("Try again 1") } } } } } }.catchOnUi { TKMAsyncError in print(TKMAsyncError) blueStart.close() result("Try again") } } else { result("TapKey Account Error") } }.catchOnUi { TKMAsyncError in print(TKMAsyncError) result("TapKey Account Error") } default: result(FlutterMethodNotImplemented) } })
TapKey.swift
import TapkeyMobileLib import UIKit import Flutter // @UIApplicationMain @objc class TapKey: UIResponder, UIApplicationDelegate { var TKMServiceFactory: TKMServiceFactory! var TKMBleLockScanner: TKMBleLockScanner! override init() { self.TKMServiceFactory = TKMServiceFactoryBuilder() .build() self.TKMBleLockScanner = TKMServiceFactory.bleLockScanner } func login(accessToken: String ) -> TKMPromise<String>{ let ct = TKMCancellationTokens.None return TKMServiceFactory.userManager.logInAsync(accessToken: accessToken, cancellationToken: ct) } func padlock(userID: String, lockID: String) -> TKMPromise<String> { let result = TKMPromiseSource<String>() let sFS = self.TKMBleLockScanner.startForegroundScan() let ct = TKMCancellationTokens.None let nearbyLocks = self.TKMBleLockScanner.locks if(nearbyLocks.isEmpty) { result.setResult("No Locks nearby") } else { // let finalLock = nearbyLocks.values.first(where: {$0.physicalLockId == lockID}) let finalLock = nearbyLocks.first(where: {$0.value.physicalLockId == lockID}) if(finalLock != nil) { TKMServiceFactory.bleLockCommunicator.executeCommandAsync(bluetoothAddress: (finalLock?.value.bluetoothAddress)!, physicalLockId: finalLock?.value.physicalLockId, commandFunc:{ tlcpConnection -> TKMPromise<TKMCommandResult> in let triggerLockCommand = TKMDefaultTriggerLockCommandBuilder() .build() // Pass the TLCP connection to the command execution facade return self.TKMServiceFactory.commandExecutionFacade.executeStandardCommandAsync(tlcpConnection, command: triggerLockCommand, cancellationToken: ct) }, cancellationToken: ct).continueOnUi({ commandResult in let code: TKMCommandResult.TKMCommandResultCode = commandResult?.code ?? TKMCommandResult.TKMCommandResultCode.technicalError switch code { case TKMCommandResult.TKMCommandResultCode.ok: sFS.close() _ = self.TKMServiceFactory.userManager.logOutAsync(userId: userID, cancellationToken: ct) result.setResult("Lock is now open") return true default: result.setResult("Try again") return false } }).catchOnUi({ (_: TKMAsyncError) -> Bool in result.setResult("Try again") return false }) } else { result.setResult("Lock doesn't match the bike") } } return result.promise } }
内容的提问来源于stack exchange,提问作者czapelM
相关产品推荐
相关产品推荐

