自定义

时间:2015-12-11 20:39:39

标签: ios watchkit watch-os-2 apple-watch-complication

我正在尝试为watchOS2创建复杂功能。我为我的iOS应用程序创建了新目标 - 使用Glances和Complications 我想只有一个Modular Large Complication。

当我试图设置复杂功能时,手表冻结(在模拟器和真实手表上)

这是我的复杂功能代码:

-(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);

}

我正在通过CLKComplicationTimeTravelDirectionNone作为支持的时间旅行路线

我很无奈,因为我无法在控制台和模拟器或设备中看到任何错误只是冻结。

从Carousel崩溃报告中我能够阅读这些信息:

  

***由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:'应用程序是必需的。 bundleID:ql.ManaEU.watchkitapp appToReplace:proxy:ql.ManaEU.watchkitapp<(null)在数据库中找不到>'   以NSException类型的未捕获异常终止   abort()调用   CoreSimulator 191.4 - 设备:Apple Watch - 42mm - 运行时间:watchOS 2.0(13S343) - DeviceType:Apple Watch - 42mm

2 个答案:

答案 0 :(得分:0)

仅供参考,我可以使用您提供的扩展代码自定义表盘。没问题。

如果您在崩溃日志中发现了包ID错误,系统将报告watchkit应用程序(包含watchkit扩展程序)的问题。

  

由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:'应用程序是必需的。 bundleID:ql.ManaEU.watchkitapp ......

您需要追踪watchkit捆绑包的错误。首先要做的是Xcode watchkit app构建目标日志。如果没有错误或警告,请检查iPhone和Apple Watch控制台日志。

如果这并未指出您的问题,请检查Info.plist以确保这些值有效,并且存在所需的密钥。另请查看watchkit app目标构建设置。

您应该能够使用版本编辑器将Xcode项目与其初始提交进行比较,以查看是否无意中更改或删除了某些内容。

答案 1 :(得分:0)

您为CLKComplicationTemplateModularLargeTable当前时间轴条目提供了CLKComplicationTemplateModularLargeColumns占位符模板。并发占位符模板应与当前时间轴条目匹配。