我試圖更新動作的目標值(HMCharacteristicWriteAction
),但它總是與EXC_BAD_ACCESS(代碼= 1,地址= 0x50)崩潰。swift - HomeKit updateTarget值HMCharacteristicWriteAction崩潰
我的代碼片段:
print("\(action) --> \(action.dynamicType)") // <HMCharacteristicWriteAction: 0x14cf7ba20> --> HMCharacteristicWriteAction
print("current: \(action.targetValue)") // current: 1
print("next: \(value) --> \(value.dynamicType)") // next: 0 --> Int
action.updateTargetValue(value, completionHandler: { [weak self] error -> Void in
if let error = error {
// display some message
return
}
// do something else when succeeded
})
正如你看到的,action
不是零和正確類型(HMCharacteristicWriteAction
)的。我可以成功讀取它的targetValue
。
我使用Product - Analyze
分析了項目,一切正常(沒有任何警告)。我也在Scheme - Diagnostics
中啓用了Zombie,但仍然沒有運氣。
根據updateTargetValue
文檔:
/*!
* @brief This method is used to change target value for the characteristic.
*
* @param targetValue New target value for the characteristic.
*
* @param completion Block that is invoked once the request is processed.
* The NSError provides more information on the status of the request, error
* will be nil on success.
*/
public func updateTargetValue(targetValue: NSCopying, completionHandler completion: (NSError?) -> Void)
什麼混淆我是targetValue: NSCopying
。 value
的Int
是否符合'NSCopying'?我曾嘗試value as NSCopying
爲targetValue
,但它不是更好。
你能告訴我如何解決這個問題嗎?可以通過Int
到targetValue
嗎?什麼可能導致這次崩潰?
謝謝。
喜瑪麗亞,我沒有嘗試的NSNumber但事情沒有得到改善。我的代碼是'let targetValue = NSNumber(integer:value)',然後'actionSet.updateTargetValue(targetValue,...' - >仍然會崩潰,使用EXC_BAD_ACCESS(code = 1,address = 0x50)''。 – quanguyen