2016-05-12 8 views
0

私のビデオアップロードが進行中で、アプリケーションがdidEnterbackgroundメソッドを呼び出していなくても、バックグラウンドに入ると、私のiOSアプリがクラッシュしています。 私のアプリがバックグラウンドであっても、それを引き起こす原因は何ですか?私のアプリがバックグラウンドのときにビデオをアップロードすることはできますか?

+0

投稿してくださいクラッシュの詳細は、あなたのアプリケーションがバックグラウンドにある場合でも(ビデオファイルのような)大きなファイルをアップロードするには、 'NSURLSessionUploadTask'を使用することができ – Shubhank

+1

。 – Larme

+0

接続中にアプリがクラッシュすることはありません。だから私は見つけることができません。それはシミュレータまたは接続されたデバイス上で完全に動作します。 –

答えて

1

バックグラウンドセッションを試しましたか?このように:

let configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("com.you.uoload") 
let session = NSURLSession(configuration: configuration, delegate: nil, delegateQueue: NSOperationQueue.mainQueue()) 
1

あなたは、非同期アップロード要求を行うためにNSURLSessionUploadTaskを使用する必要があります。

あなたのリクエストは同期している可能性があり、エラーが発生していると思います。あなたはあなたがより多くの詳細についてはthis answerを参照することができ

NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://example.com/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { 
    [formData appendPartWithFileURL:[NSURL fileURLWithPath:@"file://path/to/image.jpg"] name:@"file" fileName:@"filename.jpg" mimeType:@"image/jpeg" error:nil]; 
} error:nil]; 

AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; 

NSURLSessionUploadTask *uploadTask; 
uploadTask = [manager 
      uploadTaskWithStreamedRequest:request 
      progress:^(NSProgress * _Nonnull uploadProgress) { 
       // This is not called back on the main queue. 
       // You are responsible for dispatching to the main queue for UI updates 
       dispatch_async(dispatch_get_main_queue(), ^{ 
        //Update the progress view 
        [progressView setProgress:uploadProgress.fractionCompleted]; 
       }); 
      } 
      completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { 
       if (error) { 
        NSLog(@"Error: %@", error); 
       } else { 
        NSLog(@"%@ %@", response, responseObject); 
       } 
      }]; 

    [uploadTask resume]; 

、のような何かを行うことができますAFNetworkingを使用

希望これは役立ちます:)

関連する問題