自定义表盘时 watchOS 并发症未显示为选项

Jos*_*ork 2 xcode objective-c apple-watch watchkit

这是我尝试添加的第一个复杂功能。我正在将它添加到当前项目中。我设法让它出现在模拟器中,但没有出现在我的实际手表上。这只是一个 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);

    }

}
Run Code Online (Sandbox Code Playgroud)

abj*_*ato 5

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

  1. 通过强制触摸在手表本身
  2. 在 iPhone 上通过 Face Gallery 部分的 Watch 应用程序

对于这两种工作方式,您应该实现get?Localizable?Sample?Template(for:?with?Handler:?) 方法,该方法将被调用一次以填充一种占位符,而用户将从列表中选择复杂性。

为了让复杂功能出现在 Watch.app 中,您还应该在您的项目中额外包含特殊的“复杂功能包”。这个包将存储在 iOS 应用程序中,Watch.app 会在需要填充它的 Face Gallery 时找到它。