强制重新加载watchOS 2并发症 [英] Force reload watchOS 2 Complications

查看:105
本文介绍了强制重新加载watchOS 2并发症的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了使并发症起作用的问题.如果我能够可靠地刷新它们,将会很有帮助.

I have issues getting Complications to work. It would be helpful if I was able to reliably refresh them.

因此,我将强制按下菜单按钮链接到以下方法

Therefore I linked a force-press menu button to the following method

@IBAction func updateComplication() {
    let complicationServer = CLKComplicationServer.sharedInstance()
    for complication in complicationServer.activeComplications {
        complicationServer.reloadTimelineForComplication(complication)
    }        
}

不幸的是,这导致应用程序崩溃.和fatal error: unexpectedly found nil while unwrapping an Optional value.

Unfortunately this leads to the app crashing. with a fatal error: unexpectedly found nil while unwrapping an Optional value.

我知道调用reloadTimelineForComplication(complication)已在预算之内,但这并不是问题,因为它从一开始就不起作用.

I understand that calling reloadTimelineForComplication(complication) is budgeted but that can't be the issue here as it doesn't work from the very beginning.

我当前正在使用watchOS2 + Xcode 7 GM

I am currently using watchOS2 + Xcode 7 GM

我希望在应用程序运行时获得有关刷新并发症的任何想法吗?

I'd appreciate any ideas on making Complications refresh while the app is running?

推荐答案

跟踪或使用异常断点,并专注于阅读完整的错误消息,它告诉您确切在哪一行意外找到了nil(我怀疑complicationServer ).使用'if let'而不是'let'来强制展开相应的变量.

Trace or use the exception breakpoint and focus on reading the whole error message where it tells you exactly on which line it found the nil unexpectedly (I do suspect the complicationServer). Use 'if let' instead of 'let' to force unwrap the respective variable.

private func reloadComplications() {        
    if let complications: [CLKComplication] = CLKComplicationServer.sharedInstance().activeComplications {
        if complications.count > 0 {
            for complication in complications {
                CLKComplicationServer.sharedInstance().reloadTimelineForComplication(complication)
                NSLog("Reloading complication \(complication.description)...")
            }
            WKInterfaceDevice.currentDevice().playHaptic(WKHapticType.Click) // haptic only for debugging
        }
    }
}

这篇关于强制重新加载watchOS 2并发症的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆