How do I populate getPlaceholderTemplateForComplication using Objective C?

1.3k views Asked by At

so this tutorial here is excellent

http://www.sneakycrab.com/blog/2015/6/10/writing-your-own-watchkit-complications

and this tells me that I need to set the fillFraction, ringStyle and textProvider, but its not jumping out to me from the docs what I need to do in objective c, and I've tried many combinations I can think of. can anyone assist in my understanding of completing the boiler plate code in the new watchOS complication template?

- (void)getPlaceholderTemplateForComplication:(CLKComplication *)complication withHandler:(void(^)(__nullable CLKComplicationTemplate *complicationTemplate))handler {
    /

    switch (complication.family) {
        case CLKComplicationFamilyCircularSmall:

            // WHAT DO I PUT HERE? confused.com

            break;

        default:
            break;
    }

}

i'm wanting to test out a small circular complication with updates from my ios app.

anyone aid my understanding before I go all in on swift?

many thanks Nik

update after a brief chat with @mipadi :-) and a minor tweak.

- (void)getPlaceholderTemplateForComplication:(CLKComplication *)complication withHandler:(void(^)(__nullable CLKComplicationTemplate *complicationTemplate))handler {
    switch (complication.family) {
        case CLKComplicationFamilyCircularSmall:
        {
            CLKComplicationTemplateCircularSmallRingText *myComplicationTemplate; // Create template object
            myComplicationTemplate.fillFraction = 0.7;
            myComplicationTemplate.ringStyle = CLKComplicationRingStyleOpen;
            handler(myComplicationTemplate);
        }
        default:
            break;
    }   
}
1

There are 1 answers

6
mipadi On BEST ANSWER

You would create an instance of a CLKComplicationTemplate and pass it to the handler:

- (void)getPlaceholderTemplateForComplication:(CLKComplication *)complication withHandler:(void(^)(__nullable CLKComplicationTemplate *complicationTemplate))handler {
    switch (complication.family) {
    case CLKComplicationFamilyCircularSmall: {
        CLKComplicationTemplate *myComplicationTemplate = [CLKComplicationTemplate new]; 
        // Create your template object
        handler(myComplicationTemplate);
        break;
    }
    default:
        break;
    }

}