2016-01-09 32 views
0

我試圖從我的iOS應用程序通知我的Mac應用程序使用CoreBluetooth,但我在中央側的peripheral:didUpdateNotificationStateForCharacteristic:方法中得到此錯誤:Error Domain=CBErrorDomain Code=1 "One or more parameters were invalid." UserInfo={NSLocalizedDescription=One or more parameters were invalid.}CoreBluetooth setNotifyValue無效參數

外設應用程序使用屬性通知和讀取權限初始化onlineUUID特徵。

func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) { 
    for characteristic in service.characteristics! { 
     if characteristic.UUID.isEqual(self.onlineUUID) { 
      print("Found online characteristic") // this prints 
      print("Properties are \(characteristic.properties.rawValue)") // 16==Notify 
      peripheral.setNotifyValue(true, forCharacteristic: characteristic) 
     } 
    } 
} 

這看起來像在線教程,但它不工作。我重新啓動了這兩個應用程序,清理了項目並重新啓動了Xcode。在iOS 9.2和OS X 10.11.2上使用Xcode 7.2和Swift 2.1.1。非常困惑;請幫忙。

+0

看看這個教程可能可以幫助你,我已經完全爲我的健康設備做了工作。這可能會有助於你的例子 - http://www.raywenderlich.com/52080/introduction-core-bluetooth-building-heart-rate-monitor – KiranJasvanee

+0

你是否通過self.onlineUUID清除if條件? – KiranJasvanee

回答

0

我覺得你的問題都可以整理出來,如果你只需要添加的函數內部自我:

self.sensorPeripheral.setNotifyValue(true, forCharacteristic: thisCharacteristic) 
0

道歉大家的時間;這個確切的代碼工作時,我重新啓動外設的藍牙。正在註冊的特性,但setNotifyValue()導致這個不尋常的錯誤信息,直到我重新啓動藍牙。

我發現代碼通過交換哪個設備是外設,哪個是中心。