gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:45:35 27 4
gpt4 key购买 nike

我一直在构建一个使用 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 有可遵循的准则,您不能让应用程序“自行”打开它始终需要用户输入。

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

关于iOS 应用程序从后台连接低功耗蓝牙服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31965327/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com