私のアプリケーションでiphoneバックグラウンドプロセスを使用しています。それはバックグラウンドで実行されていますが、10分後にはアプリケーションが終了します。そして長い間働いていない。私のアプリケーションでiphoneのバックグラウンドプロセスが長時間働いていない
私のアプリケーションには、その時点でviewdidloadが開始され、ホームボタンをクリックするとバックグラウンドで実行されます。バックグラウンドでは完璧に走っていますが、10分後にはバックグラウンドプロセスが停止しています。以下は私のコードです。
in .hファイル。私.M
- (void)viewDidLoad {
UIBackgroundTaskIdentifier bgTask = nil;
UIApplication *app = [UIApplication sharedApplication];
counterTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:counterTask];
//counterTask = UIBackgroundTaskInvalid;
// If you're worried about exceeding 10 minutes, handle it here
theTimer=[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(countUp)
userInfo:nil
repeats:YES];
}];
count=0;
theTimer=[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(countUp)
userInfo:nil
repeats:YES];
[super viewDidLoad];
}
(ボイド)カウントアップ{
count++; NSString *currentCount; currentCount=[[NSString alloc] initWithFormat:@"%d",count]; NSLog(@"timer running in background :%@",currentCount); thecount.text=currentCount; [currentCount release];
}
で
IBOutlet UILabel *thecount;
int count;
NSTimer *theTimer;
UIBackgroundTaskIdentifier counterTask;
上記のコードだけの番号をカウントするために、サンプル地面と背景。 10分後には機能しません。
だから私に手伝ってください。私に助けてください。
よりグーグルグーグルでは、バックグラウンドプロセスを実装する方法を見つけました。これは、ios 3.0以外のすべてのiosで機能します。 http://www.mindsizzlers.com/2011/07/ios-background-location/ –