1

我在 SO 上的其他帖子中读到,无法以编程方式禁用蓝牙。

这有意义吗?当我订阅(谷歌)附近的 api 时,我以编程方式启用它。

这是我的代码。取消订阅不会禁用 BT。

还有其他方法可以实现吗?

/// Stops publishing/subscribing.
public func unsubscribeNearbyApi() {
    subscription = nil
    //                    self.messageMgr?.removeObserver(<#T##observer: NSObject##NSObject#>, forKeyPath: <#T##String#>)
    //                    self.messageMgr?.removeObserver(<#T##observer: NSObject##NSObject#>, forKeyPath: <#T##String#>, context:<#T##UnsafeMutablePointer<Void>#>)
}

/// Starts scanning for nearby devices that are publishing
// their names.
func subscribeNearbyApi() {

    let params: GNSSubscriptionParams = GNSSubscriptionParams.init(
        messageNamespace: "inline-beacon",
        type: "line",
        strategy:
        GNSStrategy.init(paramsBlock: { (params: GNSStrategyParams!) -> Void in
            params.includeBLEBeacons = true;
        }))

    if (self.messageMgr == nil)
    {
        getPermissions()
    }
    if let messageMgr = self.messageMgr {
        subscription = messageMgr.subscriptionWithParams(params,
            messageFoundHandler:{[unowned self] (message: GNSMessage!) -> Void in
4

1 回答 1

2

在 Google Nearby 中取消订阅不会禁用蓝牙;它会简单地停止执行任何 BLE(蓝牙低功耗)操作。

确实,Apple 没有提供在 iOS 上以编程方式禁用/启用 BT 的方法。这个想法是用户应该专门控制它。

于 2016-02-12T19:00:56.150 回答