Skip to content

Instantly share code, notes, and snippets.

@neiraza
Created December 3, 2013 01:55
Show Gist options
  • Save neiraza/7762630 to your computer and use it in GitHub Desktop.
Save neiraza/7762630 to your computer and use it in GitHub Desktop.
Background Fetch (iOS7) sample
if ([UiUtil isNotLessiOS7]) {
//UIApplicationBackgroundFetchIntervalMinimum or NN seconds
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:600];
}
- (void)updateAppIconBadge
{
LOG(@">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>updateAppIconBadge<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
// 設定する前に、設定済みの通知をキャンセルする
UILocalNotification *localNotification = [UILocalNotification new];
localNotification.alertAction = @"キタ━━━━(゚∀゚)━━━━!!";
localNotification.alertBody = @"('A`)マンドクセ ('A`)マンドクセ ('A`)マンドクセ";
localNotification.fireDate = [NSDate date];
localNotification.timeZone = [NSTimeZone localTimeZone];
localNotification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[self updateAppIconBadge];
// 失敗時には UIBackgroundFetchResultFailed を渡して completionHandler を呼ぶ
//completionHandler(UIBackgroundFetchResultFailed);
// 成功時には UIBackgroundFetchResultNewData を渡して completionHandler を呼ぶ
completionHandler(UIBackgroundFetchResultNewData);
}
SystemCapabilities = {
com.apple.BackgroundModes = {
enabled = 1;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment