Today Extension view flashes when redrawing
I had this same issue and finally figured out the issue I was having with my widget. It turns out it was related to a misunderstanding about the Widget Life Cycle on my behalf.
From the documentation I thought that the today view would keep a 'snapshot' of my widgets state until the widgetPerformUpdateWithCompletionHandler
method completion handler was called with success.
This does not seem to be the case. From what I can see the 'snapshot' is just used when the Today View is animating in (when the user pulls down the notification centre). As soon as the today view is loaded and stationary your widget is loaded from scratch (inflated from xib if using) and viewDidLoad
is called. At this moment you should populate you widget with cached data (not from a web request). If you don't you will see temporary data from your nib. This is what causes the flashing.
When viewDidLoad
is complete widgetPerformUpdateWithCompletionHandler
is called which allows you to fetch fresh data. When the fresh data is fetched you should call the completion handler and cache the data it so it can be used when the widget is loaded later on from scratch (in viewDidLoad
).
A simple way to cache the data is in user defaults.
Refreshing a Today extension view
You can use shared NSUserDefaults and observer it.
In your app:
After you update database, execute the below:
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.yourcompany.sharedDefaults"];
[userDefaults setObject:[NSDate date] forKey:@"updatedDate"];
[userDefaults synchronize];
In your Today Widget:
add a observer in viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userDefaultsDidChange:)
name:NSUserDefaultsDidChangeNotification
object:nil];
then
- (void)userDefaultsDidChange:(NSNotification *)notification {
// check updatedDate and update widget UI
}
refer: http://www.glimsoft.com/06/28/ios-8-today-extension-tutorial/
Today Widget tableView freezes
What the system does is that it takes a Snapshot. I have also been struggling a bit with this issue and I have checked this post but it did not solve my issue.
For the widgetPerformUpdateWithCompletionHandler
there are three options
NCUpdateResultNewData
— The new content required you to redraw the viewNCUpdateResultNoData
— The widget doesn’t require updatingNCUpdateResultFailed
— An error occurred during the update process
It does not matter which one of these is called it´s always the same result. And the system does take a Snapshot.
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
Reference.
I think that we´re maybe trying to load to "heavy" data and this could occur because of that. This is my answer, but I started a bounty to check if someone else has another answer or if you agree with my post.
Today widgets height issue
From my experience, this option is not currently available to third-party today extensions. The extension environment limits the height, and requesting more has no effect. What's worse is that the actual limit varies depending on screen size, and there's no way to discover the limit at run time except by trial and error.
Apple's apps, and now extensions, have often been exempt from rules that govern third party software. This appears to be another case where this is happening.
I filed a bug (rdar://18408718 in case anyone from Apple sees this) and I encourage you to do the same.
Unable to load Today Extension with table view
From your stack trace, it looks like you're trying to display a UIAlertController:
frame #6: 0x0000000186143b24 UIKit`+[UIAlertController alertControllerWithTitle:message:preferredStyle:] + 100
frame #7: 0x0000000100133518 TodayExtension_Dev`__20+[a5987398 a2489290]_block_invoke + 64
UIAlertController is presented modally over the entire screen, and your widget does not have access to the entire screen, so they are not allowed in Today Widgets.
I think you need to get to the bottom of why an alert is showing. Perhaps a side effect of your SOAP client?
Related Topics
iOS Facebook Login "Given Url Is Not Allowed by the Application Configuration"
How to Properly Add Child View Controller in iOS 8 with Swift
In-App Purchase Sandbox Environment Loop
Uilabel, Uifont and Utf-8 Triangle
How to Sign Out of Apple After Being Authenticated
Getting the Action of Uigesturerecognizer in iOS
Ios: Diddiscoverperipheral Not Called in Background Mode
Programmatically Determine Current Target (Run or Test) in iOS Project
iOS - Another Thread Needs to Send Reloaddata to the Mainthread
Avplayer with Playback Controls of Avplayerviewcontroller
Phimageresultisdegradedkey/Phimagefileurlkey Is Not Found
Changing Uipageviewcontroller's Page Programmatically Doesn't Update the Uipagecontrol
Game Center Login Dialog Not Shown Again After Cancelling It for the First Time (Ios7)
Capture Location in All States App