2

내 프로그램은 업로드 아래 샘플 코드 캠에서 사진을 쓸 수 있습니다 :도메인 = NSURLErrorDomain 코드 = -1001 "작업을 완료 할 수 없습니다 (NSURLErrorDomain 오류 -1001입니다.)."



    #define WEBSERVICE_URL @"http://192.168.0.104/upload.php" 
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 

     [picker dismissViewControllerAnimated:YES completion:^{ 

      UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; 

      NSData *imageData = UIImagePNGRepresentation(selectedImage); 

      NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil constructingBodyWithBlock:^(id formData) { 
       [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test" mimeType:@"image/png"]; 
      } error:nil]; 

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

      NSProgress *progress = nil; 

      NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { 

       [progress removeObserver:self forKeyPath:@"fractionCompleted"]; 
       NSLog(error.debugDescription); 


       if (error) { 
        [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]]; 
       } else { 
        [self.view updateWithMessage:@"Great success!"]; 

       } 
      }]; 

      [progress addObserver:self forKeyPath:@"fractionCompleted" options:NSKeyValueObservingOptionNew context:NULL]; 

      [uploadTask resume]; 

      self.imageUploadProgress = [[TNSexyImageUploadProgress alloc] init]; 
      self.imageUploadProgress.radius = 100; 
      self.imageUploadProgress.progressBorderThickness = -10; 
      self.imageUploadProgress.trackColor = [UIColor blackColor]; 
      self.imageUploadProgress.progressColor = [UIColor whiteColor]; 
      self.imageUploadProgress.imageToUpload = selectedImage; 
      [self.imageUploadProgress show]; 

      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imageUploadCompleted:) name:IMAGE_UPLOAD_COMPLETED object:self.imageUploadProgress]; 

     }]; 
    } 

을 오류는 다음과 같습니다.

TNSexyImageUploadProgressDemo[5275:113032] Error Domain=NSURLErrorDomain Code=-1001 "The operation couldn’t be completed. (NSURLErrorDomain error -1001.)" UserInfo=0x7f92c2d907d0 {NSErrorFailingURLStringKey="http://192.168.0.104/upload.php", NSUnderlyingError=0x7f92c2dcd5c0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1001.)", NSErrorFailingURLKey="http://192.168.0.104/upload.php"}

시뮬레이터 나 iPhone에서 어떤 오류가 발생해도 URL에 액세스하는 데 사파리를 사용합니다. 올바른 것은 네트워크에 액세스하기 위해 wifi를 사용합니다. ping 192.168.0.104는 정상입니다.

서버의 프로그램은 PHP로 작성하고, 코드 blelow :



    100000000) { 
     $result_json['error'] = 'Exceeded filesize'; 
    } 

    $finfo = new finfo(FILEINFO_MIME_TYPE); 

    if (false === $ext = array_search(
     $finfo->file($_FILES['upfile']['tmp_name']), 
      array(   
       'png' => 'image/png'   
      ), 
      true 
     )) { 
      $result_json['error'] = 'Invalid file format'; 
    } 

    if (!move_uploaded_file(
     $_FILES['upfile']['tmp_name'], 
     sprintf('./uploads/%s.%s', 
      sha1_file($_FILES['upfile']['tmp_name']), 
      $ext 
     ) 
     )) { 
      $result_json['error'] = 'Failed to move uploaded file'; 
    } 

    // send the result now 
    echo json_encode($result_json); 

    /* 
    try { 

     if (!move_uploaded_file(
      $_FILES['upfile']['tmp_name'], 
      sprintf('./uploads/%s.%s', 
       sha1_file($_FILES['upfile']['tmp_name']), 
       $ext 
      ) 
      )) { 
       //throw new RuntimeException('Failed to move uploaded file.'); 
     } 

     //echo json_encode(array('succes'=>true)); 
    } catch (RuntimeException $e) { 

     //echo $e->getMessage(); 

    } 
    */ 
    ?> 

+0

누가 나를 도울 수 있습니까? –

+0

에 따르면 [이 답변] (http://stackoverflow.com/a/9415479/3702797) 연결 시간 제한으로 인해, 귀하의 서버에 액세스 할 수 있습니까? 추신 : 로컬 서버에서 작업 중이므로 전화에 문제가있을 수 있습니다. – Kaiido

+0

내 서버가 모바일 safiri 또는 pc safiri 또는 ie에서 액세스 할 수 있지만 시뮬레이터 또는 iphone 둘 다 실행 시간이 초과됩니다. –

답변

2

나는 AFNetworking 라이브러리를 업데이트 엑스 코드 (6)을 사용하기 시작한 이후이 같은 문제가 한 문제를 해결했습니다. 모든 것이 잘 작동합니다.

https://github.com/AFNetworking/AFNetworking

당신이 엑스 코드 6을 사용하는 경우, 그것을 시도를 제공합니다.

+0

2.4.1을 업데이트했으며 앱에는 아무런 영향이 없었습니다. 문제가 해결 될 수있는 것이 정확히 무엇이 었는지 알고 있습니까? – Kaili

+0

버전 2.5.0 도움 : –

관련 문제