Created
May 21, 2015 15:02
-
-
Save douglasjunior/0eb67d01f35516e16ad6 to your computer and use it in GitHub Desktop.
Exemplo de código Swift
This file contains 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
import Foundation | |
import CoreBluetooth | |
class BluetoothWriter : NSObject { | |
private weak var peripheral: CBPeripheral!; | |
private weak var characteristic: CBCharacteristic!; | |
init(peripheral : CBPeripheral, characteristic:CBCharacteristic) { | |
self.peripheral = peripheral; | |
self.characteristic = characteristic; | |
} | |
func writeData(value :NSData){ | |
if (self.peripheral != nil && self.characteristic != nil) { | |
self.peripheral.writeValue(value, forCharacteristic: self.characteristic, type: CBCharacteristicWriteType.WithoutResponse); | |
} | |
} | |
func writeString(value : NSString){ | |
self.writeData(value.dataUsingEncoding(NSUTF8StringEncoding)!); | |
} | |
func writeColorWithRed(red : Int, green: Int, blue:Int){ | |
self.writeString(NSString(format:"c%d,%d,%d\n",red,green,blue)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment