自定义表盘时,watchOS Complication 未显示为选项
watchOS Complication not showing as an option when customizing watch face
这是我尝试添加的第一个并发症。我正在将它添加到当前项目中。我设法让它出现在模拟器中,但没有出现在我的实际手表上。这只是一个 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);
}
}
可以通过两种方式向表盘添加复杂功能:
- 通过强制触摸在手表上
- 在 iPhone 上,通过 Face Gallery 部分中的 Watch 应用程序
对于这两种工作方式,您应该实现 getLocalizableSampleTemplate(for:withHandler:)
method ,当用户从列表中选择复杂功能时,它将被调用一次以填充占位符类型。
为了使复杂性出现在 Watch.app 中,您还应该在您的项目中包含特殊的“complication bundle”。此捆绑包将存储在 iOS 应用程序中,并且 Watch.app 会在需要填充它的 Face Gallery 时找到它。
这是我尝试添加的第一个并发症。我正在将它添加到当前项目中。我设法让它出现在模拟器中,但没有出现在我的实际手表上。这只是一个 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);
}
}
可以通过两种方式向表盘添加复杂功能:
- 通过强制触摸在手表上
- 在 iPhone 上,通过 Face Gallery 部分中的 Watch 应用程序
对于这两种工作方式,您应该实现 getLocalizableSampleTemplate(for:withHandler:)
method ,当用户从列表中选择复杂功能时,它将被调用一次以填充占位符类型。
为了使复杂性出现在 Watch.app 中,您还应该在您的项目中包含特殊的“complication bundle”。此捆绑包将存储在 iOS 应用程序中,并且 Watch.app 会在需要填充它的 Face Gallery 时找到它。