Skip to content

Instantly share code, notes, and snippets.

@naotokui
Created November 20, 2012 23:32
Show Gist options
  • Save naotokui/4122008 to your computer and use it in GitHub Desktop.
Save naotokui/4122008 to your computer and use it in GitHub Desktop.
Background execution with UIBackgroundTaskIdentifier
// バックグラウンド処理のスタートを宣言
UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}];
/* ここでやりたい処理をする */
// バックグラウンド処理の終了
if (bgTask != UIBackgroundTaskInvalid){
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment