Created
March 15, 2017 16:06
-
-
Save yostane/2c69da69839747f20b3099ef823f8954 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func read(){ | |
| //read a value from the characteristic | |
| let readFuture = self.dataCharacteristic?.read(timeout: 5) | |
| readFuture?.onSuccess { (_) in | |
| //the value is in the dataValue property | |
| let s = String(data:(self.dataCharacteristic?.dataValue)!, encoding: .utf8) | |
| DispatchQueue.main.async { | |
| self.valueLabel.text = "Read value is \(s)" | |
| print(self.valueLabel.text!) | |
| } | |
| } | |
| readFuture?.onFailure { (_) in | |
| self.valueLabel.text = "read error" | |
| } | |
| } | |
| func write(){ | |
| self.valueToWriteTextField.resignFirstResponder() | |
| guard let text = self.valueToWriteTextField.text else{ | |
| return; | |
| } | |
| //write a value to the characteristic | |
| let writeFuture = self.dataCharacteristic?.write(data:text.data(using: .utf8)!) | |
| writeFuture?.onSuccess(completion: { (_) in | |
| print("write succes") | |
| }) | |
| writeFuture?.onFailure(completion: { (e) in | |
| print("write failed") | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment