【问题标题】:iOS App connection Bluetooth Lower Energy Service from BackgroundiOS App 连接来自后台的蓝牙低能耗服务
【发布时间】: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


【解决方案1】:

Apple 有要遵循的准则,您不能让应用程序打开“自身”,它总是需要用户输入。

监控信标时我所做的是弹出 UILocalnotification,当用户与之交互时,您的应用就会打开。

【讨论】:

  • 感谢凯恩的回答。这是我的想象,但希望有一个解决方案。
猜你喜欢
  • 2012-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-28
  • 2015-02-17
  • 1970-01-01
  • 2016-09-13
相关资源
最近更新 更多