Closed duyquang91 closed 8 years ago
How are you using it from the widget? Can you post a sample?
Also, is it taking a long time every time you launch the widget, or only after you dismiss the notification center and then come back later?
@interface TodayViewController ()
-(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated];
UIDeviceListener *listener = [UIDeviceListener sharedUIDeviceListener];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listenerDataUpdated:) name: kUIDeviceListenerNewDataNotification object:nil];
[listener startListener];
}
(void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
completionHandler(NCUpdateResultNewData); }
@end
first launch is working perfect, then I dissmiss and show the widget again, it take long time for "(void)listenerDataUpdated: (NSNotification *) notification" response
Well, the data is only updated every 20 seconds or so. There probably just isn't any new data to present. One thing you could do is call stopListener whenever they exit the Notification Center, then call startListener again whenever they reopen it. That way you'd always get the latest available data as soon as they come back.
thanks, I set stopListener when viewWillDisappear and it working perfect
I have tested on today widget and it take a long time to update data, on main App working perfect