2013-06-05 73 views
0

我正在使用分段上傳來上傳文件。但是,不要打電話給代表如何打電話給代表。亞馬遜s3中的分段上傳不會調用代理

這裏我的代碼:

AmazonS3Client *s31 = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY]; 
      s31.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2]; 
      s31.timeout = 240; 
      @try 
      { 
       [s31 createBucketWithName:bucket]; 

       S3InitiateMultipartUploadRequest *initReq = [[S3InitiateMultipartUploadRequest alloc] initWithKey:key inBucket:bucket]; 
       S3MultipartUpload *upload = [s31 initiateMultipartUpload:initReq].multipartUpload; 
       S3CompleteMultipartUploadRequest *compReq = [[S3CompleteMultipartUploadRequest alloc] initWithMultipartUpload:upload]; 

       int numberOfParts = [self countParts:imageData]; 
       for (int part = 0; part < numberOfParts; part++) { 
        NSData *dataForPart = [self getPart:part fromData:imageData]; 
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate]; 
        [appDelegate.dataArray addObject:dataForPart]; 

        // The S3UploadInputStream was deprecated after the release of iOS6. 
        NSInputStream *stream = [NSInputStream inputStreamWithData:dataForPart]; 
        //if (using3G) { 
        // If connected via 3G "throttle" the stream. 
        //stream.delay = 0.2; // In seconds 
        //stream.packetSize = 16; // Number of 1K blocks 
        // } 

        S3UploadPartRequest *upReq = [[S3UploadPartRequest alloc] initWithMultipartUpload:upload]; 
        upReq.partNumber = (part + 1); 
        upReq.contentLength = [dataForPart length]; 
        upReq.stream = stream; 

        S3UploadPartResponse *response = [s31 uploadPart:upReq]; 
        [compReq addPartWithPartNumber:(part + 1) withETag:response.etag]; 
        NSLog(@"Coming222"); 
       } 
       [s31 completeMultipartUpload:compReq]; 
       [self textfileupload]; 
      } 
      @catch (AmazonServiceException *exception) 
      { 
       isUpload=NO; 
       [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 

       NSLog(@"Multipart Upload Failed, Reason: %@", exception ); 
      } 

請幫助我。

回答

0

如果你想它來調用委託方法,您需要執行此,與依靠委託方法的任何對象:

putObjectRequest.delegate = self; 
[putObjectRequest setDelegate:self]; 

如果你的意思是你是如何使用的AppDelegate的一個實例:AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];,然後仔細檢查是否將類型轉換爲AppDelegate指針是正確的。也許嘗試另一種初始化/分配的方式,因爲我已經遇到了依賴於一個返回的對象,類型轉換爲可可指針。