Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOS 7 - Background Fetching (CocoaHeads Lyon octobre 2013)

iOS 7 - Background Fetching (CocoaHeads Lyon octobre 2013)

Vincent Tourraine

October 11, 2013
Tweet

More Decks by Vincent Tourraine

Other Decks in Programming

Transcript

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

    View Slide

  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

    View Slide

  3. Mise en place

    View Slide

  4. Configuration du projet

    View Slide

  5. Info.plist
    UIBackgroundModes

    fetch

    View Slide

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

    View Slide

  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);
    }];
    }

    View Slide

  8. Debug

    View Slide

  9. Configuration du scheme

    View Slide

  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

    View Slide