CLKComplicationServer.sharedInstance() returns nil

I'm seeing crash reports on my Apple watch where CLKComplicationServer.sharedInstance() returns nil.

The function signature states it returns an unwrapped optional Self

Code sample of where it is being called:

func session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]) {
    NSLog("UserInfo recieved from iPhone\n%@", userInfo.description)
     
    let theComplication = WatchComplication(withData: userInfo)
     
    updateComplication(theComplication)
     
    let complicationServer = CLKComplicationServer.sharedInstance()
    for complication in complicationServer.activeComplications {
        complicationServer.reloadTimelineForComplication(complication)
    }
}



Anyone else seeing this? It seems to cause my complication to bug out and eventually stop working.

Accepted Reply

Update:


I've found a way to replicate this every time with my sample project.


1, launch app and install on Watch, note how it works perfectly and updates when you change the iPhone Apps reminder date

2, Turn off your iPhone and back on again

3, Complication no longer updates.


Only way I have found to get it working again is to un-install and then re-install the Watch App

Replies

That sounds odd. Would you be able to file a bug report where you include the crash log and ideally a sample project where this reproduces? If you do, please report back here with the radar number!

Hi Viking, thanks again for replying


I've filed a bug report for this, 22947535


I managed to catch the issue in the debugger today so uploaded a screenshot of that and a crash report taken from my watch.


I've not uploaded a sample project as I've not been able to nail down what causes the problem. The only real thing I have noticed is this seems to only happend when activating WCSession from the ExtensionDelegate's init func along with trying to update the complication from the session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]) delegate function


    func session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]) {
        NSLog("UserInfo recieved from iPhone\n%@", userInfo.description)
       
        let theComplication = WatchComplication(withData: userInfo)
       
        updateComplication(theComplication)
       
        /
        let complicationServer = CLKComplicationServer.sharedInstance() <--- nil returned
        for complication in complicationServer.activeComplications {    <--- crashes here
            NSLog("Notifying complication server %@", complication.description)
            complicationServer.reloadTimelineForComplication(complication)
        }
    }

I've got a very simple sample project which works perfectly, until you leave it for a few hours, and then it exhibits the same problem as my App. The complication no longer updates as WCSession fails to deliver the new UserInfo to its delegate until the Watch App is launched. Checking the crash logs I can also see it has crashed several times with the CLKComplicationServer.sharedInstance() returning nil


Sample project has been attached to radar mentioned above

Update:


I've found a way to replicate this every time with my sample project.


1, launch app and install on Watch, note how it works perfectly and updates when you change the iPhone Apps reminder date

2, Turn off your iPhone and back on again

3, Complication no longer updates.


Only way I have found to get it working again is to un-install and then re-install the Watch App

thanks for the bug report and the details. I'll make sure the right engineers look at it promptly!