ios - 使用ios swift取消订阅附近的api后如何禁用蓝牙?

标签 ios swift bluetooth google-nearby

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

这有意义吗?当我订阅 (google) 附近的 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

最佳答案

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

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

关于ios - 使用ios swift取消订阅附近的api后如何禁用蓝牙?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35365568/

相关文章:

ios - 关于 Swift 中 alert view 下 view controller 可控性的问题

swift 3. xCode8.为实体的 bool 类型属性赋值会引发错误

Swift - 访问函数外部的变量

ios - GKSession 将获取后台其他设备的对等 ID

ios - 如何删除 UITextView Swift 中文本的顶部填充

ios - RuTube MPMoviePlayerController initWithContentURL :

bluetooth - Peerfinder 中 AlternateIdentities 的可能键

android - 如何设置安卓蓝牙权限

ios - 如何获得在作为 UIImageView 的 subview 的 UIView 层中绘制的形状的不透明度?

ios - 在 NSMutableArray 中查找 NSMutableDictionary 的索引