Skip to content

Instantly share code, notes, and snippets.

@itinance
Created April 15, 2019 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itinance/555a8e49e49116eb8626f8e2e84981f5 to your computer and use it in GitHub Desktop.
Save itinance/555a8e49e49116eb8626f8e2e84981f5 to your computer and use it in GitHub Desktop.
getCurrentTimelineEntryForComplication
#pragma mark - Timeline Population
- (void)getCurrentTimelineEntryForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationTimelineEntry * __nullable))handler {
ExtensionDelegate* myDelegate = (ExtensionDelegate*)[[WKExtension sharedExtension] delegate];
if (complication.family == CLKComplicationFamilyModularSmall) {
[myDelegate fetchRate:^(NSDictionary * data, NSError * _Nullable error) {
Rate* rate = [data valueForKey:@"btc"];
NSDate* now = [NSDate date];
NSString* valueString = rate == nil ? @"?" : rate.value;
CLKComplicationTemplateModularSmallStackText* textTemplate = [[CLKComplicationTemplateModularSmallStackText alloc] init];
textTemplate.line1TextProvider = [CLKSimpleTextProvider
textProviderWithText:@"BTC -> USD"
shortText:@"BTC -> USD"];
textTemplate.line2TextProvider = [CLKSimpleTextProvider
textProviderWithText:valueString
shortText:valueString];
textTemplate.tintColor = [UIColor whiteColor];
// Create the entry.
CLKComplicationTimelineEntry* entry = nil;
entry = [CLKComplicationTimelineEntry entryWithDate:now
complicationTemplate:textTemplate];
handler(entry);
}];
}
handler(nil);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment