transferCurrentComplicationUserInfo和之间有什么区别transferUserInfo?
我想将数据从我的AppDelegate发送到时钟套件复杂功能.
transferCurrentComplicationUserInfo似乎完全一样transferCurrentUserInfo.我错过了什么吗?
apple-watch watchkit clockkit apple-watch-complication wcsession
我正在尝试定制ClockKit Complication工作.
CLKComplicationDataSource.它被添加到Watch Extension的plist中CLKComplicationPrincipalClass.我可以在手表上选择一个复杂功能并激活它,但我只看到"---------------"而不是我的实际占位符.
我override init(){…}在我的ComplicationController中添加了自定义,并在其中添加了一个断点用于调试.但即使运行Complication 构建方案,也永远不会达到这个断点.似乎我的自定义ComplicationController从未实例化.
我确实看到了一条日志消息,Extension received request to wake up for complication support.但我不清楚这是在代码中触发的位置.
我也试着从我的主人InterfaceController那里打电话给我,以了解我的主动并发症
if let server = CLKComplicationServer.sharedInstance() {
for complication in server.activeComplications {
server.reloadTimelineForComplication(complication)
}
}
Run Code Online (Sandbox Code Playgroud)
......但是server返回零.没有并发症似乎是活跃的并且重新加载.
如何成功连接我的自定义ComplicationController?
此外,欢迎任何其他调试技巧.
通常是否足以从手表模拟器或iPhone上的手表应用程序中删除并发症,或者您是否需要重新安装整个手表应用程序以查看有效的并发症相关更新?此外,当我在我的自定义ComplicationController中记录某些内容时,我应该只在使用Complications构建方案运行时或者使用正常的Watch App构建方案时才能看到它的输出吗?
欢迎任何寻找问题的想法.
我正在尝试构建一个watchOS 2复杂功能,它显示用户的健康数据,例如步骤(但理论上它应该能够显示用户已授予应用程序查看权限的任何健康数据).当复杂化首次启动时,我可以查询Healthkit并获取我想要的所有数据,因为第一次启动被认为是在前台.但是,当新的健康数据可用时,我在后台检索HealthKit数据时遇到问题.有两个地方我可以得到这些数据,手表和iPhone.
当从getNextRequestedUpdateDateWithHandler中设置的日期触发复杂的后台刷新时,我试图从手表本身获取数据.但是,当我调用HKHealthStore的execute方法时,如果应用程序(或者在这种情况下是复杂的)运行后台,它不会返回任何查询结果.我还尝试设置一个HKAnchoredObject查询,该查询应该在进程恢复时立即返回我的结果,但除非我在手表上手动启动应用程序扩展,否则这似乎也不会返回任何结果.这是我的监视代码,在请求运行状况工具包权限后从我的ExtensionDelegate的init方法调用:
func setupComplicationDataCache() {
let now = NSDate()
var startDate: NSDate? = nil
var interval: NSTimeInterval = 0
self.calendar.rangeOfUnit(NSCalendarUnit.Day, startDate: &startDate, interval: &interval, forDate: now)
let stepSampleType = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)!
// Match samples with a start date after the workout start
let predicate = HKQuery.predicateForSamplesWithStartDate(startDate, endDate: nil, options: .None)
let query = HKAnchoredObjectQuery(type: stepSampleType, predicate: predicate, anchor: nil, limit: 0) { (query, samples, deletedObjects, anchor, error) -> Void in
// Handle when the query first returns results …Run Code Online (Sandbox Code Playgroud) 我有一个公共交通应用程序,提供火车的实时出发数据.我想添加一个复杂功能,显示下一班火车的出发时间.
是否可以在并发症上显示(或刷新)实时数据?例如,显示"到X站3分钟".根据来自公共传输API的信息,数据可能每分钟都在变化.
我应该如何在watchOS 2或watchOS 3上完成此操作?
我知道ETA应用程序显示复杂的旅行时间,但我不确定他们是如何实现的.
apple-watch watchkit watchos clockkit apple-watch-complication
我想知道如果我不支持它,如何不显示复杂功能系列。
示例:超大表盘
在ComplicationController.swift'sgetLocalizableSampleTemplate和getCurrentTimelineEntry方法中,我只在handler(nil)打开complication.familyExtra Large时传入 a :
case .extraLarge:
handler(nil)
Run Code Online (Sandbox Code Playgroud)
但这一定不是正确的或所有要做的,因为我的 Extra Large 并发症仍然可以选择:
但它显然不起作用或有任何数据可显示:
有谁知道我错过了什么?谢谢!
更新:
我ComplicationController.swift的getComplicationDescriptors:
func getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void) {
let oneSupported = [
CLKComplicationFamily.circularSmall,
.modularSmall,
.utilitarianSmall,
.modularLarge,
.utilitarianLarge,
.graphicExtraLarge,
.graphicCircular
]
let twoSupported = [
CLKComplicationFamily.circularSmall,
.modularSmall,
.utilitarianSmall,
.utilitarianSmallFlat,
.extraLarge,
.graphicBezel,
.graphicCircular,
.graphicCorner,
.graphicRectangular,
.modularLarge,
.utilitarianLarge
]
let descriptors = [
CLKComplicationDescriptor(identifier: ComplicationIdentifier.height.rawValue, displayName: "Complication 1", supportedFamilies: oneSupported)
// Multiple …Run Code Online (Sandbox Code Playgroud) apple-watch watchkit watchos clockkit apple-watch-complication
我在让 Complications 工作时遇到问题。如果我能够可靠地刷新它们,那将会很有帮助。
因此,我将强制按下菜单按钮链接到以下方法
@IBAction func updateComplication() {
let complicationServer = CLKComplicationServer.sharedInstance()
for complication in complicationServer.activeComplications {
complicationServer.reloadTimelineForComplication(complication)
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这会导致应用程序崩溃。与fatal error: unexpectedly found nil while unwrapping an Optional value.
我知道电话reloadTimelineForComplication(complication)是有预算的,但这不是这里的问题,因为它从一开始就不起作用。
我目前正在使用 watchOS2 + Xcode 7 GM
我很感激有关在应用程序运行时刷新复杂功能的任何想法?
我有一个 Apple Watch 并发症,它可以正确初始化并显示我期望的数据。但是,当我的 getNextRequestedUpdateDateWithHandler 方法中返回的 NSDate 触发刷新时,我的委托中唯一被再次调用的方法是 getNextRequestedUpdateDateWithHandler 方法(我在每个方法上设置断点来确定这一点)。我本来希望在请求的更新日期发生时调用 requestsUpdateDidBegin ,但情况似乎并非如此。有谁知道是什么原因造成的?这是我的代码:
class ComplicationController: NSObject, CLKComplicationDataSource {
/// Provide the time travel directions your complication supports (forward, backward, both, or none).
func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void) {
handler(.Backward)
}
/// Depending on which time travel directions you support, you will be asked for the start/end dates of your timeline (or both, or neither).
/// The start/end dates will determine at what point during time travel we dim …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个watchOS 3应用程序,我想在后台任务中更新我的复杂功能.
首先,我从后台任务中的服务器获取新数据handle().在那之后,我通过电话更新我的主动并发症complicationServer.reloadTimeline(for:).
在控制台中,我看到消息"更新复制",因此代码被执行.
然而,重新加载后,并发症仍显示旧数据.如果我切换表盘并切换回来,那么复杂功能有时会重新加载.我是否必须做其他事情才能从后台任务重新加载复杂功能?
func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
for task : WKRefreshBackgroundTask in backgroundTasks {
if (WKExtension.shared().applicationState == .background) {
if task is WKApplicationRefreshBackgroundTask {
let dataProvider = DataProvider()
dataProvider.getData(station: "Name", completion: { (data, error) in
self.updateComplication()
self.scheduleNextBackgroundRefresh()
task.setTaskCompleted()
})
}
} else {
task.setTaskCompleted()
}
}
}
func updateComplication() {
let complicationServer = CLKComplicationServer.sharedInstance()
for complication in complicationServer.activeComplications! {
print("UPDATE COMPLICATION")
complicationServer.reloadTimeline(for: complication)
}
}
Run Code Online (Sandbox Code Playgroud) watchkit clockkit apple-watch-complication watchos-3 wkrefreshbackgroundtask
我无法在WatchOS 3中更新或刷新Apple Watch Complication。我在ComplicationController.swift文件中使用以下代码。
func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
handler([.forward])
}
func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
handler(Date())
}
func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
handler(Date(timeIntervalSinceNow: 60 * 30))
}
Run Code Online (Sandbox Code Playgroud)
我也曾尝试从中的handle后台任务方法安排更新,ExtensionDelegate.swift但它似乎也不起作用。
func scheduleNextRefresh() {
let fireDate = Date(timeIntervalSinceNow: 30 * 60)
let userInfo = ["lastActiveDate" : Date(),
"reason" : "updateWeekNumber"] as Dictionary
WKExtension.shared().scheduleBackgroundRefresh(withPreferredDate: fireDate, userInfo: userInfo as NSSecureCoding) { (error) …Run Code Online (Sandbox Code Playgroud) 我正在开发一个具有模块化大面复杂功能的 watchOS 应用程序。WatchKit 扩展中的 Assets.xcassets 文件包含一个 Complication 文件夹,其中分别为Circular、Extra Large和设置一个图像,但在我的例子中,我有多个可能Modular的Utilitarian模块化类型资源,我将以编程方式从中进行选择(称为Bottlefed、Breastfed和Pump)。我能够将Modular图像集重命名为Bottlefed,然后将其他两个图像集添加到 Complication 文件夹中并用图像填充它们:
但这样做最终会在 Xcode 中显示以下警告:
我找不到任何文档或人们使用多个图像作为资产的示例来向我展示我是否按预期方式执行此操作。
请注意,就将多个资产添加到资产目录并以编程方式从中进行选择而言,我的方法确实有效。但 Xcode 中的警告令人恼火,让我觉得我没有以正确的方式这样做。有什么想法吗?