0

アプリがバックグラウンドまたは実行されていないときに、ユーザーがポイントを獲得できるゲームを作成しています。アプリケーションが完全に閉鎖された場合でも、ポイントを獲得する必要があります。現在、私は NSTimer を使用してこれを行っていますが、タイマーがバックグラウンドで実行できないことをどこでも読んでいます。これが私が持っているものであり、どのように修正する必要がありますか:

- (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"];
}
4

1 に答える 1