Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.