iOS 来自后台的应用程序连接蓝牙低功耗服务

iOS App connection Bluetooth Lower Energy Service from Background

我一直在构建一个使用 BLE 与小型传感器连接的小应用程序。它工作正常。但是现在我想将应用程序置于后台,当检测到来自蓝牙的服务时打开应用程序(或将状态从后台更改为前景)。这可能吗?

现在我可以使用这段代码:

func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) {

    let localName = advertisementData[CBAdvertisementDataLocalNameKey] as! String
    if !localName.isEmpty {

        println("Found the \(localName)")

        // Trying to open the app but it does not work
        dispatch_async(dispatch_get_main_queue(), { () in
            UIApplication.sharedApplication().openURL(NSURL(string: "app_url_scheme://")!)
        })

        self.centralManager!.stopScan()
        peripheral.delegate = self

        self.centralManager!.connectPeripheral(peripheral, options: nil)

    }

}

关闭应用程序并放置外设后发现,但现在我不知道如何打开应用程序。我试图按照此 tutorial 使用 openURL 功能打开。但是它不起作用。

知道如何让应用程序自行打开吗?

非常感谢您的宝贵时间!

Apple 有可遵循的准则,您不能让应用程序打开 "Itself" 它始终需要用户输入。

我在监视信标时所做的是弹出一个 UILocalnotification,当用户与之交互时,您的应用程序将打开。