Elad Benda
Elad Benda

Reputation: 36654

how to disable bluetooth after unsubscribing to nearby api with ios swift?

I have read in other posts on SO that it's not possible to disable the bluetooth programatically.

Does this make sense? As i enable it programmatically when I subscribe to (google) nearby api.

Here is my code. Unsubscribing doesn't disable the BT.

Any other way to achieve that?

/// 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

Upvotes: 1

Views: 440

Answers (1)

Dan Webb
Dan Webb

Reputation: 348

Unsubscribing in Google Nearby will not disable Bluetooth; it will simply stop doing any BLE (Bluetooth Low Energy) operations.

And it's true that Apple provides no way to programmatically disable/enable BT on iOS; the idea is that the user should have control it exclusively.

Upvotes: 2

Related Questions