IOS7 Background Sampling

I am trying to update an iOS7 application. I do not think it is working properly.

I add to info.plist

Required background modes - The application downloads content from the network

In my main view controller

  • UIApplicationDelegate set as a delegate
  • In Viewdidload I put [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:1.0];

  • I add the following method

     - (void)application:(UIApplication *)application performFetchWithCompletionHandler: (void (^)(UIBackgroundFetchResult result))completionHandler { NSLog(@"Refresh from Background"); } 


I plug in my iPhone and run the application, and then got to Debug -> Simulate Background Selection

NSLog does not print. (If my application is in the foreground, it will be placed in the background)

Thanks!

+6
source share
2 answers

You can view the demo code of the apple at the link below.

http://adcdownload.apple.com/wwdc_2013/wwdc_2013_sample_code/52012_ios_simplebackgroundtransfer.zip

I tried to extract data in the background in my application. It is working fine.

+3
source

You added

 [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum]; 

in the method

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

also this method

  (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult result)) 

completeHandler should be added to the application delegate class, not the UIViewController, see this tutorial: http://www.objc.io/issue-5/multitasking.html

0
source

Source: https://habr.com/ru/post/955438/


All Articles