Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from sfroment/dev/sfromnet/ios-bluetooth
IOS ble library
- Loading branch information
Showing
7 changed files
with
677 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,6 @@ indent_size = 2 | |
|
||
[*.diff] | ||
indent_size = 1 | ||
|
||
[*.m] | ||
indent_size = 2 |
23 changes: 23 additions & 0 deletions
23
client/react-native/mobile/ios/berty/BertyBluetoothModule.h
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// BertyBluetoothModule.h | ||
// bluetooth | ||
// | ||
// Created by sacha on 04/09/2018. | ||
// Copyright © 2018 Facebook. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <React/RCTBridgeModule.h> | ||
#import <React/RCTEventEmitter.h> | ||
|
||
#import "BertyCentralManager.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface BertyBluetoothModule : RCTEventEmitter <RCTBridgeModule> | ||
|
||
@property(nonatomic, strong) BertyCentralManager* bcm; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
63 changes: 63 additions & 0 deletions
63
client/react-native/mobile/ios/berty/BertyBluetoothModule.m
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// BertyBluetoothModule.m | ||
// bluetooth | ||
// | ||
// Created by sacha on 04/09/2018. | ||
// Copyright © 2018 Facebook. All rights reserved. | ||
// | ||
|
||
#import "BertyBluetoothModule.h" | ||
|
||
@implementation BertyBluetoothModule | ||
|
||
RCT_EXPORT_MODULE(); | ||
|
||
- (instancetype)init { | ||
self = [super init]; | ||
if (self) { | ||
self.bcm = [[BertyCentralManager alloc] initWithSender:self]; | ||
} | ||
return self; | ||
} | ||
|
||
- (dispatch_queue_t)methodQueue | ||
{ | ||
return dispatch_get_main_queue(); | ||
} | ||
|
||
+ (BOOL)requiresMainQueueSetup | ||
{ | ||
return YES; | ||
} | ||
|
||
- (NSArray<NSString *> *)supportedEvents | ||
{ | ||
return @[@"NEW_DEVICE", @"NEW_MESSAGE"]; | ||
} | ||
|
||
RCT_EXPORT_METHOD(updateValue) | ||
{ | ||
[self.bcm updateValue]; | ||
} | ||
|
||
RCT_EXPORT_METHOD(startDiscover) | ||
{ | ||
[self.bcm discover]; | ||
} | ||
|
||
RCT_EXPORT_METHOD(subscribe) | ||
{ | ||
[self.bcm subscribe]; | ||
} | ||
|
||
RCT_EXPORT_METHOD(connect:(NSString *)addr) | ||
{ | ||
[self.bcm connect:addr]; | ||
} | ||
|
||
RCT_EXPORT_METHOD(writeTo:(NSString *)addr msg:(NSString *)msg) | ||
{ | ||
[self.bcm writeTo:addr msg:msg]; | ||
} | ||
|
||
@end |
37 changes: 37 additions & 0 deletions
37
client/react-native/mobile/ios/berty/BertyCentralManager.h
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// BertyCentralManager.h | ||
// bluetooth | ||
// | ||
// Created by sacha on 05/09/2018. | ||
// Copyright © 2018 Facebook. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <CoreBluetooth/CoreBluetooth.h> | ||
#import <React/RCTEventEmitter.h> | ||
#import "BertyPeripheral.h" | ||
#import "BertyDevice.h" | ||
|
||
@interface BertyCentralManager : NSObject <CBCentralManagerDelegate, CBPeripheralDelegate, CBPeripheralManagerDelegate> | ||
|
||
@property (nonatomic, strong) NSMutableDictionary *connectedDevice; | ||
@property (nonatomic, strong) NSMutableDictionary *discoveredDevice; | ||
@property (nonatomic, strong) CBCentralManager *centralManager; | ||
@property (nonatomic, strong) CBPeripheralManager *peripheralManager; | ||
@property (nonatomic, strong) CBMutableService *bertyService; | ||
@property (nonatomic, strong) CBMutableCharacteristic *bertyReaderCharacteristic; | ||
@property (nonatomic, strong) CBMutableCharacteristic *bertyCounterReaderCharacteristic; | ||
@property (nonatomic, strong) CBUUID *serviceUUID; | ||
@property (nonatomic, strong) CBUUID *readerUUID; | ||
@property (nonatomic, strong) CBUUID *readerCounterUUID; | ||
@property (nonatomic, strong) NSMutableArray<NSData*>* toSend; | ||
@property (nonatomic, weak) id sender; | ||
|
||
- (instancetype)initWithSender:(id)sender; | ||
- (void)discover; | ||
- (void)connect:(NSString *)name; | ||
- (void)writeTo:(NSString *)addr msg:(NSString *)msg; | ||
- (void)subscribe; | ||
- (void) updateValue ; | ||
@end | ||
|
Oops, something went wrong.