TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Nov 2017 |
Maintained by Derrick Chao, chinkal.
The Loopd Beacon SDK provides apis to interact with the Loopd Beacons from Android/iOS devices, and includes ranging, connecting, and writing and reading data between Loopd Beacons.
Version | Minimum iOS Target |
---|---|
1.x | iOS 8 |
Drag the ./Pod/LoopdSDK.framework file into your project.
Clone the repo, and the example project in the Example directory.
LCBadgeManager
is a basic manager than helps the developer to control the Loopd Badge.
@interface ViewController () <LCBadgeManagerDelegate>
@property (strong, nonatomic) LCBadgeManager *badgeManager;
@end
- (void)viewDidLoad {
[super viewDidLoad];
self.badgeManager = [LCBadgeManager new];
self.badgeManager.delegate = self;
[self.badgeManager startScan];
}
You can also give limitations to it.
// config
LCScanningConfig *scanningConfig = [LCScanningConfig new];
scanningConfig.RSSI = -50;
scanningConfig.isAllowDuplicatesKey = YES;
[self.badgeManager startScanWithConfig:scanningConfig];
Try to connect with the badge.
When connected, you can execute commands to the badge.
#pragma mark - Badge Manager Delegate
- (void)badgeManager:(LCBadgeManager *)badgeManager didDiscoverBadge:(LCBadge *)badge {
[self.badgeManager connectBadge:badge];
}
- (void)badgeManager:(LCBadgeManager *)badgeManager didConnectBadge:(LCBadge *)badge {
// turn on red LED
[self.badgeManager executeCommandCode:@"0F"];
}
@protocol LCBadgeManagerDelegate <NSObject>
@optional
- (void)badgeManager:(LCBadgeManager *)badgeManager didDiscoverBadge:(LCBadge *)badge;
- (void)badgeManager:(LCBadgeManager *)badgeManager didConnectBadge:(LCBadge *)badge;
- (void)badgeManager:(LCBadgeManager *)badgeManager didFailToConnectBadge:(LCBadge *)badge error:(NSError *)error;
- (void)badgeManager:(LCBadgeManager *)badgeManager didDisconnectBadge:(LCBadge *)badge error:(NSError *)error;
- (void)badgeManager:(LCBadgeManager *)badgeManager didUpdateValueForBadge:(LCBadge *)badge;
@end
LCContactExchangeManager
is a manager that helps the developer implement contact exchange easily.
@interface ViewController () <LCContactExchangeManagerDelegate>
@property (strong, nonatomic) LCContactExchangeManager *contactExchangeManager;
@end
- (void)viewDidLoad {
[super viewDidLoad];
self.contactExchangeManager = [LCContactExchangeManager new];
self.contactExchangeManager.delegate = self;
// target badge id
NSString *badgeId = @"123abc";
[self.contactExchangeManager startScanningWithBadgeId:badgeId];
// if you need to scan all the badges, target badge id nil.
// [self.contactExchangeManager startScanningWithBadgeId:nil];
}
#pragma mark - Contact Exchange Manager Delegate
- (void)contactExchangeManager:(LCContactExchangeManager *)contactExchangeManager
didUpdateExchangedBadgeIds:(NSArray *)exchangedBadgeIds
targetBadge:(LCBadge *)targetBadge {
// targetBadge is the current badge
// exchangedBadgeIds is the array of other user's badge id
}
@protocol LCContactExchangeManagerDelegate <NSObject>
@optional
- (void)contactExchangeManager:(LCContactExchangeManager *)contactExchangeManager
didDetectBadge:(LCBadge *)badge;
- (void)contactExchangeManager:(LCContactExchangeManager *)contactExchangeManager
didUpdateExchangedBadgeIds:(NSArray *)exchangedBadgeIds;
- (void)contactExchangeManager:(LCContactExchangeManager *)contactExchangeManager
didUpdateExchangedBadgeIds:(NSArray *)exchangedBadgeIds
targetBadge:(LCBadge *)targetBadge;
@end
command | action |
---|---|
00 | Switch off both LEDs |
FF | Switch on both LEDs |
11 | Force the device to disconnect |
A0xx | advertise xx times per second |
07 | Read contact exchange data |
[comment]: # ( | 0F |
[comment]: # ( | F0 |
[comment]: # ( | 100004 |
[comment]: # ( | 10FF04 |
[comment]: # ( | 12 |
[comment]: # ( | 14 |
[comment]: # ( | 20 |
[comment]: # ( | 80 |
[comment]: # ( | 90 |
[comment]: # ( | 89 |
Example:
- (void)turnOnBothLEDs {
[self.badgeManager executeCommandCode:@"00"];
}
- (void)advertise4timesPerSecond {
[self.badgeManager executeCommandCode:@"A004"];
}
- (void)advertise8timesPerSecond {
[self.badgeManager executeCommandCode:@"A008"];
}
- (void)iBeaconExample {
// 0x80+16 bytes of Data + 1byte Major ID + 1 byte Minor ID
[self.badgeManager executeCommandCode:@"80FFEEDDCCBBAA99887766554433221100ABCD"];
}
- (void)eddystoneExample {
// 0x90+1 byte Frame Type + PDU based on Frame type
[self.badgeManager executeCommandCode:@"9000CEAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBB"];
}
Derrick Chao, [email protected]
Loopd-iOS-SDK is available under the MIT license. See the LICENSE file for more info.