objective-c - 自定义表盘时,watchOS 复杂功能未显示为选项

标签 objective-c xcode watchkit apple-watch

这是我尝试添加的第一个复杂功能。我正在将其添加到当前项目中。我已经设法让它显示在模拟器中,但没有显示在我的实际 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. 通过强制触摸在 watch 本身上
  2. 在 iPhone 上通过 Face Gallery 部分的 Watch 应用程序

对于这两种工作方式,您应该实现get​Localized​Sample​Template(for:​with​Handler:​) method当用户从列表中选择复杂性时,将调用一次以填充占位符类型。

为了使 Watch.app 中显示复杂功能,您还应该在项目中添加特殊的“complication bundle ”。该 bundle 将存储在 iOS 应用程序中,并且 Watch.app 在需要填充其 Face Gallery 时会找到它。

关于objective-c - 自定义表盘时,watchOS 复杂功能未显示为选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42869884/

相关文章:

iphone - writeToFile 原子地返回 NO

ios - userNotificationCenter didReceive 响应包含空通知(watchOS)

iphone - 在 firstResponder 上显示 UITextField 键盘,即使 userInteractionEnabled = NO

ios - UITableViewCell 框架没有根据给定的宽度和高度

iphone - 测试模拟器和设备时自动切换 Xcode Config

iphone - 在 Xcode 中的 Clean/Clean All 期间运行脚本

arrays - Swift:音频文件数组

ios - Apple Watch 背景模式?

ios - 如何减少 WKInterfaceTable 中的行间距

objective-c - 以编程方式将应用程序的内容复制到桌面