Complication update causes short iOS app freeze

122 Views Asked by At

I am updating an Apple Watch complication. But when I am calling session.transferCurrentComplicationUserInfo(userInfo) on iOS my app freezes for a fraction of a second, sometimes longer. When it's during a drag gesture or animation it is noticeable.

How can I avoid this but still update the complication?

Additional context

This is how I call the complication to update

private var validSession: WCSession? {
    if let session = session where session.paired && session.watchAppInstalled {
        return session
    }
    return nil
}

func updateApplicationContext(userInfo: [String : AnyObject]) {
    if let session = validSession {
        if session.complicationEnabled {
            do {
                session.transferCurrentComplicationUserInfo(userInfo)
            }
        }            
    }
}

Interestingly when I do the same with session.updateApplicationContext(userInfo) it doesn't cause the freeze (of course it also doesn't update the complication).

func updateApplicationContext(userInfo: [String : AnyObject]) {
    if let session = validSession {
        do {
            try session.updateApplicationContext(userInfo)
        } catch let error {
            print("[Update] \(error)")
        }
    }
}

I am also tried to profile the app. Unfortunately I have trouble switching from the watch extension to the iOS app while the Profiler is running. (any tips on this are welcome as well) Funnily I did manage to do it once and remember seeing the freeze as zero activity for a while in the time profiler. Strangely I spotted the call of session.transferCurrentComplicationUserInfo(userInfo) at the end not the beginning of the freeze. Puzzling.

I hope some of this is helpful. To me this is still quite confusing. I appreciate any ideas.

0

There are 0 best solutions below