【发布时间】:2015-08-12 12:31:32
【问题描述】:
我一直在构建一个使用 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 功能打开。但是它不起作用。
知道如何让应用自行打开吗?
非常感谢您的宝贵时间!
【问题讨论】:
-
您所能做的就是发布本地通知。您无法将您的应用置于前台。
-
感谢保罗的评论。这是我的想象,但希望有一个解决方案。
标签: ios iphone swift bluetooth core-bluetooth