eldade / UIDeviceListener

Obtain power information (battery health, charger details) for iOS without any private APIs.
GNU General Public License v3.0
240 stars 38 forks source link

Today widget take a long time to update data #1

Closed duyquang91 closed 8 years ago

duyquang91 commented 8 years ago

I have tested on today widget and it take a long time to update data, on main App working perfect

eldade commented 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?

duyquang91 commented 8 years ago

import "TodayViewController.h"

import <NotificationCenter/NotificationCenter.h>

@interface TodayViewController () @end @implementation 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];

}

@end

duyquang91 commented 8 years ago

first launch is working perfect, then I dissmiss and show the widget again, it take long time for "(void)listenerDataUpdated: (NSNotification *) notification" response

eldade commented 8 years ago

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.

duyquang91 commented 8 years ago

thanks, I set stopListener when viewWillDisappear and it working perfect