Last active
August 29, 2015 14:21
-
-
Save douglasjunior/850600368aeac1e9ab12 to your computer and use it in GitHub Desktop.
Exemplo de código Objective-C
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/Foundation.h> | |
#import <CoreBluetooth/CoreBluetooth.h> | |
@interface BluetoothWriter : NSObject | |
-(id) initWithPeripheral:(CBPeripheral *) peripheral characteristic:(CBCharacteristic *)characteristic; | |
- (void) writeString:(NSString *) value; | |
- (void) writeData:(NSData *) value; | |
-(void) writeColorWithRed:(int)red withGreen:(int)green withBlue:(int)blue; | |
@end |
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 "BluetoothWriter.h" | |
@interface BluetoothWriter (){ | |
} | |
@property (weak, nonatomic) CBPeripheral *peripheral; | |
@property (weak, nonatomic) CBCharacteristic *characteristic; | |
@end | |
@implementation BluetoothWriter | |
-(id) initWithPeripheral:(CBPeripheral *)per characteristic:(CBCharacteristic *)charac{ | |
if ((self = [super init])) { | |
self.peripheral = per; | |
self.characteristic = charac; | |
} | |
return self; | |
} | |
-(void) writeData:(NSData *)value{ | |
if (self.peripheral != nil && self.characteristic != nil) { | |
[self.peripheral writeValue:value forCharacteristic:self.characteristic type:CBCharacteristicWriteWithoutResponse]; | |
} | |
} | |
-(void) writeString:(NSString *)value{ | |
[self writeData:[value dataUsingEncoding:NSUTF8StringEncoding]]; | |
} | |
-(void) writeColorWithRed:(int)red withGreen:(int)green withBlue:(int)blue{ | |
[self writeString:[NSString stringWithFormat:@"c%d,%d,%d\n",red,green,blue]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment