Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS自定义键盘扩展蓝牙访问_Ios_Swift_Bluetooth_Custom Keyboard_Cbcentralmanager - Fatal编程技术网

iOS自定义键盘扩展蓝牙访问

iOS自定义键盘扩展蓝牙访问,ios,swift,bluetooth,custom-keyboard,cbcentralmanager,Ios,Swift,Bluetooth,Custom Keyboard,Cbcentralmanager,我想从自定义键盘扩展插件中访问蓝牙设备。 但是,CBCentralManager将始终处于不受支持的状态。我在info.plist>NSExtension中启用了RequestsOpenAccess 还有其他人面临同样的问题吗 我的代码如下。它基于苹果默认的自定义键盘扩展名目标代码 class KeyboardViewController: UIInputViewController { @IBOutlet var nextKeyboardButton: UIButton! in

我想从
自定义键盘扩展插件中访问蓝牙设备。
但是,
CBCentralManager
将始终处于
不受支持的状态。我在
info.plist>NSExtension
中启用了
RequestsOpenAccess

还有其他人面临同样的问题吗

我的代码如下。它基于苹果默认的
自定义键盘扩展名
目标代码

class KeyboardViewController: UIInputViewController {
    @IBOutlet var nextKeyboardButton: UIButton!
    internal var manager: BLManager?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Perform custom UI setup here
        self.nextKeyboardButton = UIButton(type: .system)
        self.nextKeyboardButton.setTitle(NSLocalizedString("Next Keyboard", comment: "Title for 'Next Keyboard' button"), for: [])
        self.nextKeyboardButton.sizeToFit()
        self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = false
        self.nextKeyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: .allTouchEvents)
        self.view.addSubview(self.nextKeyboardButton)
        self.nextKeyboardButton.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
        self.nextKeyboardButton.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        print("> BL - Keyboard")
        manager = BLManager.shared
    }
    
    override func viewWillLayoutSubviews() {
        self.nextKeyboardButton.isHidden = !self.needsInputModeSwitchKey
        super.viewWillLayoutSubviews()
    }
}
具有相应的
BLManager
对象

internal class BLManager: NSObject, CBCentralManagerDelegate {
    public static var shared: BLManager = BLManager()
    public var manager: CBCentralManager
    
    override init() {
        manager = CBCentralManager(delegate: nil, queue: nil)
        super.init()
        manager.delegate = self
    }
    
    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        if central.state == .poweredOn {
            manager.scanForPeripherals(withServices: nil, options: nil)
        }
        print("> BL \(central.state)")
    }
}

你是在模拟器中测试的吗?不是,是在真正的设备上(iPhone12Pro/iPhone8)。在一个常规项目中使用相同的代码,一切都按照预期工作。我在使用模拟器时遇到了
。不受支持的