Created
February 4, 2014 22:02
-
-
Save mombrea/8813243 to your computer and use it in GitHub Desktop.
Example of enabling background app refresh and updating the app icon badge number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum]; | |
return YES; | |
} | |
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler | |
{ | |
if ([[ItemManager new] reloadItemDataSynchronous]) { | |
ItemHelper *helper = [ItemHelper new]; | |
NSArray *items = [helper getNewItems]; | |
if(items.count > 0){ | |
int newItemCount = [helper getNewItemCount]; | |
[UIApplication sharedApplication].applicationIconBadgeNumber = newItemCount; | |
} | |
} | |
completionHandler(UIBackgroundFetchResultNewData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These type of background tasks just active whenever iOS feels like it. For most apps I've done you're lucky if you get called twice a day.
iOS 11 has a new API that lets you schedule real background network operations. https://developer.apple.com/documentation/foundation/url_loading_system/downloading_files_in_the_background?language=objc