2016-02-12 82 views
1

我已閱讀過其他文章,因此無法通過編程方式禁用藍牙。如何禁用藍牙後取消訂閱附近的iOS與iOS快速?

這是否有意義?正如我以編程方式啓用它時,我訂閱(谷歌)附近的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 

回答

2

在谷歌附近取消訂閱不會禁用藍牙;它會停止執行任何BLE(藍牙低功耗)操作。

的確,蘋果公司沒有辦法在iOS上以編程方式禁用/啓用BT;這個想法是用戶應該完全控制它。

+0

雖然BT在掃描開始時切換到「啓用」?根據蘋果公司沒有提供編程方式禁用/啓用BT'這是不可能的 –

+0

當應用程序嘗試啓動BT操作時,它不會自動啓用。用戶必須打開它。附近的消息庫提供了一個回調,以保持應用程序與BT電源設置的最新。請參閱此頁面上的「影響附近的跟蹤用戶設置」部分:https://developers.google.com/nearby/messages/ios/pub-sub –