0

HTTP投稿を使用してサーバーにビデオをアップロードしています。

私は次のコードを使用しています

 NSString *urlString =@"http://sampleurl.com/upload_video";

 NSMutableURLRequest *request= [[[NSMutableURLRequest alloc] init] autorelease];
 [request setURL:[NSURL URLWithString:urlString]];
 [request setHTTPMethod:@"POST"];


  [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"user_id\"\r\n\r\n%@", appDelegate.userid] dataUsingEncoding:NSUTF8StringEncoding]];
  [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];


   [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"video\"; filename=\"%@\"\r\n", @"a.mov"] dataUsingEncoding:NSUTF8StringEncoding]];
   [postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
   [postbody appendData:[NSData dataWithData:file]];
   [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
   [request setHTTPBody:postbody];

    conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    if (conn) {
    webData = [[NSMutableData data] retain];
     }    

これは、書き込まれたバイト数と合計バイト数を調べるために使用している関数です。

 -(void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(    NSInteger)totalBytesExpectedToWrite{



    NSLog(@"------%i------%i-----------",totalBytesWritten ,totalBytesExpectedToWrite);



  NSDictionary *uploadStatus=[[NSDictionary alloc]initWithObjectsAndKeys:
                            [NSString stringWithFormat:@"%i",totalBytesWritten],@"bytesWritten",
                            [NSString stringWithFormat:@"%i",totalBytesExpectedToWrite],@"totalBytes",
                            nil];

   [uploadStatus release];
      }

アプリがバックグラウンドに戻るとアップロードが一時停止され、フォアグラウンドに戻るとアップロードが再開されます 私の問題は...長いビデオをアップロードすると時間がかかり、電話が自動的にロックされます。その後、アップロードプロセスが機能しません。アップロードがスタックし、アプリを再起動する必要があります

なぜそれが起こっているのか..事前にこの感謝をクリアするのを手伝ってください

4

1 に答える 1

0

Apple は、アプリケーションのマルチタスク サポートを導入しました。マルチタスクのサポートは、アプリをバックグラウンド状態にすることに依存しています。この状態では、完全なインタラクティブ モードにすばやく復元できますが、バックグラウンドでリソースを消費することはありません。これは、ネットワーク アプリケーションに問題を引き起こす可能性があります。たとえば、RestKit:長時間実行される重要な要求で構築されたアプリケーションは、ユーザーがアプリを切り替えることによって中断される可能性があります。beginBackgroundTaskWithExpirationHandlerありがたいことに、Apple は、 のメソッドを使用してバックグラウンド タスクを作成することにより、プロセスの寿命を延ばすための限定的なサポートも提供しましたUIApplication。このメソッドは、Objective-C ブロックを受け入れ、UIBackgroundTaskIdentifier作成されたバックグラウンド タスクの値を返します。iOS 3.0 展開との下位互換性が維持されるように、バックグラウンド タスクを作成するときは注意が必要です。

からのバックグラウンド アップロード/ダウンロードのトピックを参照してください。

http://mobile.tutsplus.com/tutorials/iphone/advanced-restkit-development_iphone-sdk/リンク。

これも参照してくださいhttp://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html

http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW28

https://developer.apple.com/library/ios/#technotes/tn2277/_index.html

次の行は、iOS デバイスのスリープ時間を無効にします。

[[UIApplication sharedApplication] setIdleTimerDisabled:YES]
于 2013-03-14T05:19:01.640 に答える