1

私はストローを引いていることを知っていますが、答えを望んでいます.

ユーザーの介入なしに、バックグラウンドでサーバーと通信する必要があるアプリがあります。プッシュ通知が到着したとき、または少なくとも定期的 (5 分ごとなど) のいずれかです。

場所の更新を追加してサーバーに送信できる可能性があります。大まかな場所を使用して正当化することさえできるので、Apple はそれを承認します。最悪の場合、エンタープライズ デベロッパー ライセンスに 299 ドルを支払い、ローカル ディストリビューションを使用します (これは私が気にかけている唯一のものです)。

私の最後の希望は、NSTimer でバックグラウンド タスクの定期的なディスパッチを使用することです。 この方法を使用するアプリは、許可されるバックグラウンド タスクの種類に関する Apple の制限に引き続き該当しますか? (media/location/voip/newsstand/external device) とても差別的なように思えます...

PS。アプリは、サーバーとの定期的な通信を含め、iPod touch の開発モードで動作します。バックグラウンドモードに関しては、plistで何も宣言していません。これは私が大丈夫ということですか?

4

1 に答える 1

1

私は以下を実装し、昨日アップルからアプリの承認を得ました。アプリが機能しない (メディア/場所/voip/ニューススタンド/外部デバイス)

applicationDidEnterBackground で次のコードを使用して、最大 600 秒 (10 分) の時間を取得できます。

if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) { //Check if our iOS version supports multitasking I.E iOS 4
if ([[UIDevice currentDevice] isMultitaskingSupported]) { //Check if device supports mulitasking
UIApplication *application = [UIApplication sharedApplication]; //Get the shared application instance
__block UIBackgroundTaskIdentifier background_task; //Create a task object
background_task = [application beginBackgroundTaskWithExpirationHandler: ^ {
    [application endBackgroundTask: background_task]; //Tell the system that we are done with the tasks
    background_task = UIBackgroundTaskInvalid; //Set the task to be invalid
    //System will be shutting down the app at any point in time now
}];
//Background tasks require you to use asyncrous tasks
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    //Perform your tasks that your application requires
    NSLog(@"\n\nRunning in the background!\n\n");
    [application endBackgroundTask: background_task]; //End the task so the system knows that you are done with what you need to perform
    background_task = UIBackgroundTaskInvalid; //Invalidate the background_task
});
}

}

ドキュメントはここにありますhttp://disanji.net/iOS_Doc/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

backgroundTaskIdentifier オブジェクトを実装し、background_task を無効にして時間を確認しました。これを使用して残り時間を取得することもできます

NSLog(@"Time remaining: %f", application.backgroundTimeRemaining);
于 2013-03-09T06:08:47.080 に答える