11
votes

i am trying to create complication for watchOS2. I have created new target for my iOS application - with Glances and Complications I want to have only one Modular Large Complication.

When I run trying to set complication Watch freezes (on both simulator and real Watch)

Here's my complication code:

-(void)getCurrentTimelineEntryForComplication:(CLKComplication *)complication withHandler:(void (^)(CLKComplicationTimelineEntry * _Nullable))handler {

if (complication.family == CLKComplicationFamilyModularLarge) {

    CLKComplicationTemplateModularLargeColumns *template = [[CLKComplicationTemplateModularLargeColumns alloc] init];
    NSString *title = NSLocalizedString(@"TODAYINTAKE", nil);
    template.row1Column1TextProvider = [CLKSimpleTextProvider textProviderWithText:title];
    template.row2Column2TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"kcal"];
    template.row3Column2TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"ml"];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([self isDateToday:[defaults objectForKey:@"dateSaved"]]) {
        template.row2Column1TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"%@",[defaults objectForKey:@"energy"]];
        template.row3Column1TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"%@", [defaults objectForKey:@"water"]];
    } else {
        template.row2Column1TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"0"];
        template.row3Column1TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"0"];
    }
    template.row2ImageProvider = [CLKImageProvider imageProviderWithOnePieceImage:[UIImage imageNamed:@"energy64"]];
    template.row3ImageProvider = [CLKImageProvider imageProviderWithOnePieceImage:[UIImage imageNamed:@"water64"]];
    template.row1ImageProvider = [CLKImageProvider imageProviderWithOnePieceImage:[UIImage imageNamed:@"64"]];
    template.row1Column2TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@" "];
    CLKComplicationTimelineEntry *entry = [CLKComplicationTimelineEntry entryWithDate:[NSDate new] complicationTemplate:template];

    handler(entry);
} else handler(nil);   
}

-(void)getPlaceholderTemplateForComplication:(CLKComplication *)complication withHandler:(void (^)(CLKComplicationTemplate * _Nullable))handler {
if (complication.family == CLKComplicationFamilyModularLarge) {


    CLKComplicationTemplateModularLargeTable *template = [[CLKComplicationTemplateModularLargeTable alloc] init];
    NSString *title = NSLocalizedString(@"TODAYINTAKE", nil);
    template.headerTextProvider = [CLKSimpleTextProvider textProviderWithText:title];
    template.row1Column2TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"kcal"];
    template.row2Column2TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"ml"];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([self isDateToday:[defaults objectForKey:@"dateSaved"]]) {
        template.row1Column1TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"%@",[defaults objectForKey:@"energy"]];
        template.row2Column1TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"%@", [defaults objectForKey:@"water"]];
    } else {
        template.row1Column1TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"0"];
        template.row2Column1TextProvider = [CLKSimpleTextProvider textProviderWithFormat:@"0"];
    }

handler(template);
} else handler(nil);

}

i am passing CLKComplicationTimeTravelDirectionNone as supported time travel directions

I am helpless since i am can't see any error in console and simulator or device just freezes.

From Carousel crash report I was able to read this information:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application is required. bundleID: ql.ManaEU.watchkitapp appToReplace: proxy: ql.ManaEU.watchkitapp <(null) Not found in database>' terminating with uncaught exception of type NSException abort() called CoreSimulator 191.4 - Device: Apple Watch - 42mm - Runtime: watchOS 2.0 (13S343) - DeviceType: Apple Watch - 42mm

2
Did you check the device log for a crash report? If the watchkit extension hung, the system would have terminated it, but that type of error won't show up in the console. - user4151918
Please provide your getPlaceholderTemplateForComplication code, since that is what ClockKit depends on to customize your watch face complication. - user4151918
Hi, i have edited the question and provided info that you wanted. - Matěj Mefjů Novák

2 Answers

0
votes

FYI, I was able to customize the watch face, using the extension code you provided. No problem there.

If you notice the bundle id in the crash log error, the system is reporting a problem with the watchkit app (which contains the watchkit extension).

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application is required. bundleID: ql.ManaEU.watchkitapp ...

You'll need to track down what's wrong with the watchkit bundle. The first place to start would be the Xcode watchkit app build target log. If there are no errors or warnings there, check the iPhone and Apple Watch console logs.

If that doesn't point you to the problem, check the Info.plist to make sure those values are valid, and the required keys are present. Also check the watchkit app target build settings.

You should be able to use the Version Editor to compare the Xcode project against its initial commit, to see if something was inadvertently changed or deleted.

0
votes

You are providing a placeholder template of CLKComplicationTemplateModularLargeTable for the current timeline entry of CLKComplicationTemplateModularLargeColumns. The complication placeholder template should match the current timeline entry.