watchOS复杂功能在自定义表盘时不显示为选项

时间:2017-03-18 02:40:45

标签: objective-c xcode watchkit apple-watch

这是我尝试添加的第一个并发症。我将它添加到当前项目中。我设法让它出现在模拟器中,但不是在我的实际手表上。它只是一个SimpleImage的复杂功能,所以我有点不知所措,我在网上找不到这个问题。

它显示复杂情况,但在自定义表盘时不作为选项。

以下是我的代码:

- (void)getSupportedTimeTravelDirectionsForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationTimeTravelDirections directions))handler {
    //handler(nil);
    handler(CLKComplicationTimeTravelDirectionForward|CLKComplicationTimeTravelDirectionBackward);
}

- (void)getTimelineStartDateForComplication:(CLKComplication *)complication withHandler:(void(^)(NSDate * __nullable date))handler {
    handler(nil);
}

- (void)getTimelineEndDateForComplication:(CLKComplication *)complication withHandler:(void(^)(NSDate * __nullable date))handler {
    handler(nil);
}

- (void)getPrivacyBehaviorForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationPrivacyBehavior privacyBehavior))handler {
    handler(CLKComplicationPrivacyBehaviorShowOnLockScreen);
}

#pragma mark - Timeline Population

- (void)getCurrentTimelineEntryForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationTimelineEntry * __nullable))handler {
    // Call the handler with the current timeline entry
    handler(nil);
}

- (void)getTimelineEntriesForComplication:(CLKComplication *)complication beforeDate:(NSDate *)date limit:(NSUInteger)limit withHandler:(void(^)(NSArray<CLKComplicationTimelineEntry *> * __nullable entries))handler {
    // Call the handler with the timeline entries prior to the given date
    handler(nil);
}

- (void)getTimelineEntriesForComplication:(CLKComplication *)complication afterDate:(NSDate *)date limit:(NSUInteger)limit withHandler:(void(^)(NSArray<CLKComplicationTimelineEntry *> * __nullable entries))handler {
    // Call the handler with the timeline entries after to the given date
    handler(nil);
}

#pragma mark - Placeholder Templates

- (void)getLocalizableSampleTemplateForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationTemplate * __nullable complicationTemplate))handler {
    handler(nil);
}

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

    if (complication.family == CLKComplicationFamilyCircularSmall){

        CLKComplicationTemplateCircularSmallSimpleImage *template = [[CLKComplicationTemplateCircularSmallSimpleImage alloc] init];

        UIImage *img = [UIImage imageNamed:@"Circular"];

        template.imageProvider = [CLKImageProvider imageProviderWithOnePieceImage:img];

        handler(template);

    } else  if(complication.family == CLKComplicationFamilyModularSmall) {

        CLKComplicationTemplateModularSmallSimpleImage *template = [[CLKComplicationTemplateModularSmallSimpleImage alloc] init];

        UIImage *img = [UIImage imageNamed:@"Modular"];

        template.imageProvider = [CLKImageProvider imageProviderWithOnePieceImage:img];

        handler(template);

    }

}

1 个答案:

答案 0 :(得分:3)

可以通过两种方式将复杂功能添加到watchface:

  1. 通过强制触摸观看
  2. 在iPhone上通过Face Gallery部分的Watch应用程序
  3. 对于这两种工作方式,您应该实现get​Localizable​Sample​Template(for:​with​Handler:​) method,这将被调用一次以填充占位符类型,同时用户将从列表中选择复杂性。

    为了让复杂功能出现在Watch.app中,您还应该包含特殊的&#34; complication bundle&#34;到你的项目。此捆绑包将存储在iOS应用程序中,Watch.app将在需要填充它的Face Gallery时找到它。