iOS 7 - Background Fetching (CocoaHeads Lyon octobre 2013)

iOS 7 - Background Fetching (CocoaHeads Lyon octobre 2013)

74079210c61f36dff0a74f24da5727e7?s=128

Vincent Tourraine

October 11, 2013
Tweet

Transcript

  1. Background Fetching CocoaHeads Lyon - octobre 2013 Vincent Tourraine -

    shazino
  2. Pour quoi faire ? ➡ Télécharger des nouvelles données sans

    ouvrir l’application ➡ Exécution régulière en tâche de fond
  3. Mise en place

  4. Configuration du projet

  5. Info.plist <key>UIBackgroundModes</key> <array> <string>fetch</string> </array>

  6. Définir l’intervalle - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [application setMinimumBackgroundFetchInterval:

    UIApplicationBackgroundFetchIntervalMinimum]; // ... }
  7. Appel en tâche de fond - (void)application:(UIApplication *)application performFetchWithCompletionHandler: (void

    (^)(UIBackgroundFetchResult))completionHandler { [self.manager GET:@"http://example.com/resources.json" parameters:nil success:^(id operation, id responseObject) { completionHandler(UIBackgroundFetchResultNewData); } failure:^(id operation, NSError *error) { completionHandler(UIBackgroundFetchResultFailed); }]; }
  8. Debug

  9. Configuration du scheme

  10. Plus d’infos • UIApplication Class Reference https://developer.apple.com/library/ios/documentation/uikit/reference/ UIApplication_Class/Reference/Reference.html • UIApplicationDelegate

    Protocol Reference https://developer.apple.com/library/ios/documentation/uikit/reference/ UIApplicationDelegate_Protocol/Reference/Reference.html