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 full-size 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 full-size slide

  3. Mise en place

    View full-size slide

  4. Configuration du projet

    View full-size slide

  5. Info.plist
    UIBackgroundModes

    fetch

    View full-size slide

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

    View full-size 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 full-size slide

  8. Configuration du scheme

    View full-size slide

  9. 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 full-size slide