Created
April 15, 2019 11:07
-
-
Save itinance/555a8e49e49116eb8626f8e2e84981f5 to your computer and use it in GitHub Desktop.
getCurrentTimelineEntryForComplication
This file contains hidden or 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
#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