Force reload watchOS 2 Complications

后端 未结 1 1398
一向
一向 2020-12-18 11:54

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 followin

相关标签:
1条回答
  • 2020-12-18 12:09

    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
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题