轻松愉悦地使用 Pebble。
特性
pod 'Pebbleton’, '~> 1.0’
以下密钥应添加到目标的 .plist 中
'Requires Background Mode' => 'App communicates with external device'
'Supported external accessory protocols' => 'com.getpebble.public'
#include <Pebbleton/Pebbleton.h>
Pebbleton *sharedPebbleton = [Pebbleton sharedInstance];
[sharedPebbleton initializeWithAppUUID:@"87c5be2a-b1dc-41bf-bc4f-b653c54ee7ae" andShowLogs:YES];
[sharedPebbleton printInfo];
// pass nil as callback if not needed
[sharedPebbleton printFirmwareInfoWithCallback:nil];
[sharedPebbleton launchAppWithCallback:^(PBWatch *watch, NSError *error){
NSLog(@"My launch app callback");
}];
[sharedPebbleton checkCompatibilityWithCallback:^(PBWatch *watch, BOOL isAppMessagesSupported){
NSLog(@"My compatibility callback");
}];
[sharedPebbleton setPebbleCentralWatchDidConnectCallback:^(PBPebbleCentral *central, PBWatch *watch, BOOL isNew){
NSLog(@"My conncection callback");
}];
[sharedPebbleton setAppMessageReceiveUpdateHandler:^(PBWatch *watch, NSDictionary *update){
NSLog(@"My received message callback");
}];
// dictionary must be small enough to keep payload under 124 bytes
[[Pebbleton sharedInstance] sendMessage:@{@(KEY_TITLE_DATA): @"Title",
@(KEY_DESC_DATA_1): @"Description"}
withCallback:nil];
// each key/value set must be small enough to keep payload under 124 bytes
NSDictionary *messages = @{@(KEY_TITLE_DATA): @"Long Title",
@(KEY_DESC_DATA_1): @"Long Description.",
@(KEY_DESC_DATA_2): @"Long Description gets cut-off",
@(KEY_START_DATA): @"Jan 03, 2015 2:00pm",
@(KEY_END_DATA): @"Jan 06, 2015 2:00pm"};
void (^callbackBlock)(PBWatch *watch, NSArray *errors) = ^(PBWatch *watch, NSArray *errors){
if (errors.count) {
NSLog(@"Errors sending my dictionary: %@", errors);
} else {
NSLog(@"Successfully my sent dictionary.");
}
};
[[Pebbleton sharedInstance] sendDictionary:messages withCallback:callbackBlock];
- (void)pebbleCentral:(PBPebbleCentral*)central
watchDidConnect:(PBWatch*)watch
isNew:(BOOL)isNew {
// YOUR CODE HERE
[Pebbleton sharedInstance].watch = watch;
}
- (void)pebbleCentral:(PBPebbleCentral*)central
watchDidDisconnect:(PBWatch*)watch {
// YOUR CODE HERE
if ([Pebbleton sharedInstance].watch == watch ||
[watch isEqual:[Pebbleton sharedInstance].watch]) {
[Pebbleton sharedInstance].watch = nil;
}
}