Skip to content

Instantly share code, notes, and snippets.

@itinance
Created April 15, 2019 11:07
Show Gist options
  • Select an option

  • Save itinance/555a8e49e49116eb8626f8e2e84981f5 to your computer and use it in GitHub Desktop.

Select an option

Save itinance/555a8e49e49116eb8626f8e2e84981f5 to your computer and use it in GitHub Desktop.

Revisions

  1. itinance created this gist Apr 15, 2019.
    37 changes: 37 additions & 0 deletions ComplicationController.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #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);
    }
    }