1

iOS (バージョン 5 ~ 6.2) アプリケーションに多数の UIWebView があります。アプリがバックグラウンドに入ると、すべてがスムーズに実行されます。ただし、約 10 分後にフォアグラウンドに入ると、「有効なホスト名が見つかりません」または「接続タイムアウト」などのエラー メッセージが表示されます。

applicationDidEnterBackground:これは、呼び出されたときにこれらの UIWebViews に対するアクションが不足していることに関係していると思います。これらの接続をどのように切断できますか? 通知センターを使用する必要があることは理解していますが、このような以前の質問とは異なり、ARC を使用しているためdealloc、オブザーバーを削除する方法はありません。

編集

これが私の Web ビュー コードの一部です: WebViewController.m

NSURLRequest *request = [NSURLRequest requestWithURL:urlToLoad  cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0f];
// load the request to the UIWebView _webView
[_webView loadRequest:request];

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:TRUE];
if (connection) {
    receivedData = [NSMutableData data];
}

どんな助けでも大歓迎です。ありがとうございました。

4

1 に答える 1

0

重要または貴重なダウンロードまたはアップロード操作を実行していて、アプリがバックグラウンドに入った場合、「IOS」から追加の時間をリクエストして作業を完了することができます。アプリがバックグラウンドにある間に、それを完了するために追加の 10 分間が許可されます。モード。

ただし、オペレーションは重要で受け入れ可能でなければならないことに注意してください。そうしないと、アプリが Apple レビュー プロセスから拒否される可能性があります。

詳細については、バックグラウンド実行とマルチタスクに関する Apple ドキュメントを参照してください。

さて、いくつかのアクションのポイントと時間を締めくくり、バックグラウンドでタスクを続行するには、次のメソッドで実行できます。アプリケーション デリゲート メソッドを管理する必要はありません。次のスニペットを使用するだけで、ダウンロードまたはアップロードにデリゲートを使用しないでください。

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");

            NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"YOUR HOST URL"]];
            NSURLResponse *response = nil;
            NSError *requestError = nil;
            NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];

            NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
            NSLog(@"ResponseString:%@",responseString);

            [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
        });
    }
}
于 2013-04-11T04:08:20.970 に答える