0

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.

Bernd
  • 11,133
  • 11
  • 65
  • 98
  • Is it the actual call itself that is blocking the main thread, or the time it took to gather the user info? Could you please show the code related to that call, so we can see how the whole process is invoked, and what it does that might block the UI? –  May 06 '16 at 22:33
  • In addition to the code, the output from the Time Profiler Instrument would be helpful in determining in what is taking the time. – Robotic Cat May 06 '16 at 23:31
  • @PetahChristian Thanks. I checked it definitely is the gathering of user info that's blocking. I also added a bit more code as context – Bernd May 07 '16 at 15:21
  • @RoboticCat I added more information to my description. Thanks. I tried to profile but I have issues switching to the iOS app when I launch the Watch App with the profiler. – Bernd May 07 '16 at 15:22
  • Thanks for adding the info. Your title says it's the iOS app that freezes. Why are you profiling the watch app instead of the iOS app? If it's the gathering of info that's blocking, can you show that code, please? –  May 07 '16 at 17:18

0 Answers0