Reputation: 641
I read from the apple documentation that in today widget, system takes a snapshot and when the widget needs to be drawn, it first show the snapshot and then perform update if needed.
To help your widget look up to date, the system occasionally captures snapshots of your widget’s view. When the widget becomes visible again, the most recent snapshot is displayed until the system replaces it with a live version of the view.
To update a widget’s state before a snapshot is taken, be sure to conform to the NCWidgetProviding protocol. When your widget receives the widgetPerformUpdateWithCompletionHandler: call, update your widget’s view with the most recent content and call the completion handler, using one of the following constants to describe the result of the update:
From above, I expected my code to behave like this:
In the viewDidLoad or widgetPerformUpdateWithCompletionHandler or wherever, before calling NCWidgetProviding protocol(such as completionHandler(NCUpdateResult.NewData)) I set up the UI.
I then call completionHandler(NCUpdateResult.NewData).
The system then takes a snapshot of my UI.
When user closes and opens the today widget, the system present the snapshot immediately and then check if update is needed.
Update if needed.
However, if I close and open the today widget after the UI is drawn, it does not act as above.
Sometimes, it act as I expected: Immediately as I open the widget, my previous UI is shown immediately, and then it updates.
But in other times, blank is shown instead of my previous UI, then of course the UI is redrawn but this 'blinking' is annoying.
Have I done something wrong? Did I misunderstood the document? Can it be because I use auto layout and layout constraints??
I've tried everything I could think of, but it just works sometimes and not other times.
How can I avoid this annoying blinking?
Any help or advice is appreciated. Thanks!
Upvotes: 1
Views: 1506
Reputation: 641
I finally solved the problem. Thanks to this thread (Today Extension view flashes when redrawing)
It was because my widget was crashing for some reason. (Sometimes my today widget, and sometimes iOS widget itself-probably my fault..)
I got to work on why it crashes, but at least now I know where to dig.
Upvotes: 1