私は、アプリがバックグラウンドにあるとき、または実行していないときに、ポイントを獲得したゲームを作成しています。アプリケーションが完全に終了しても、ポイントを取得する必要があります。現在、私はNSTimerを使ってこれをやっていますが、タイマーがバックグラウンドで実行できない場所はどこでも読んでいます。ここで私が持っているものであり、私はそれをどのように修正する必要があります:あなたはapplicationDidEnterBackground
方法でNSUserDefaultと「終了時刻」を設定することができますバックグラウンドでのゲームでスコアリングタスクを実行するobjective-c
- (void)applicationDidEnterBackground:(UIApplication *)application {
score = [[NSUserDefaults standardUserDefaults] integerForKey:@"score"];
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(score) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
-(void) score{
score++;
[[NSUserDefaults standardUserDefaults] setInteger:score forKey:@"score"];
}
アプリがバックグラウンドのときにバックグラウンドタスクを実行できるようにする時間があります。その時間を過ぎると、もうタスクを実行できなくなります。バックグラウンドでタスクを実行する代わりに、通知を調べる必要があります。 –
私はそれを見てみましょう@TejaNandamuri – John55