2

我在使用iOS SDK進行簡單的分段上傳到S3時遇到了問題。無法找出未被處理的參數異常,並且剩餘約65秒的背景時間([UIApplication sharedApplication] .backgroundTimeRemaining)。這裏的日誌中的錯誤:因使用AWS iOS SDK未捕獲的異常'NSInvalidArgumentException'而終止應用程序

2014-03-12 15:16:04.506 Test App[1247:60b] didSendData called: 32768 - 20938752/50553329 
2014-03-12 15:16:05.308 Test App[1247:60b] didSendData called: 32768 - 20971520/50553329 
2014-03-12 15:16:09.363 Test App[1247:60b] S3Response.m|-[S3Response connectionDidFinishLoading:]|182|Response: 
2014-03-12 15:16:09.364 Test App[1247:60b] S3MultipartUploadOperation_Internal.m|-[S3MultipartUploadOperation_Internal request:didCompleteWithResponse:]|412|UploadPart succeeded: 4 
2014-03-12 15:16:09.366 Test App[1247:4a0f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** NSAllocateMemoryPages(4294967295) failed' 
*** First throw call stack: 
(0x3038cf03 0x3ab21ce7 0x3038ce45 0x30d180e5 0x30cef675 0x30cbcbe3 0x30cbcb5d 0x30cbcb0b 0x30ce48ef 0xbc6b3 0xbcdd7 0x3b00ad53 0x3b010689 0x3b0108dd 0x3b13bc17 0x3b13badc) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

和這裏的代碼:

#import "S3Upload.h" 
    #import <Cordova/CDV.h> 
    #import "S3Constants.h" 

    NSString* cordovaCallback; 
    NSString* clipName; 
    NSString* clipPath; 
    NSString* projectBucket; 

    @interface S3Upload() 

    @property (nonatomic, strong) S3TransferOperation *uploadFileOperation; 
    @property (nonatomic) UIBackgroundTaskIdentifier backgroundUpload; 

    @end 

    @implementation S3Upload 

    - (void)upload:(CDVInvokedUrlCommand*)command 
    { 
     cordovaCallback = command.callbackId; 
     clipName = [command.arguments objectAtIndex:0]; 
     clipPath = [command.arguments objectAtIndex:1]; 
     projectBucket = [command.arguments objectAtIndex:2]; 

     NSLog(@"[S3Upload] Initializing the S3 Client"); 
     // Using a background thread 
     [self.commandDelegate runInBackground:^{ 

      // Initialize the S3 Client. 
      AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID 
                  withSecretKey:SECRET_KEY]; 
      s3.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2]; 

      [AmazonLogger verboseLogging]; 
      NSLog(@"[S3Upload] Initializing the S3TransferManager"); 

      // Initialize the S3TransferManager 
      self.tm = [S3TransferManager new]; 
      self.tm.s3 = s3; 
      self.tm.delegate = self; 

      NSLog(@"[S3Upload] UPLOADING: %@", clipName); 

      self.uploadFileOperation = [self.tm uploadFile: clipPath bucket: projectBucket key: clipName]; 

      self.backgroundUpload = UIBackgroundTaskInvalid; 
      self.backgroundUpload = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ 
       NSLog(@"[S3Upload] Background handler called. Not running background tasks anymore."); 
       NSLog(@"[S3Upload] Pausing the transfer"); 
       [self.uploadFileOperation pause]; 
       NSLog(self.uploadFileOperation.isPaused ? @"[S3Upload] Operation paused" : @"[S3Upload] Operation not paused"); 
       NSLog(self.uploadFileOperation.isFinished ? @"[S3Upload] Operation finished" : @"[S3Upload] Operation not finished"); 
       [[NSNotificationCenter defaultCenter] addObserver:self 
                 selector:@selector(appBecameActive) 
                  name:UIApplicationDidBecomeActiveNotification 
                  object:nil]; 

       [[UIApplication sharedApplication] endBackgroundTask:self.backgroundUpload]; 
       self.backgroundUpload = UIBackgroundTaskInvalid; 
      }]; 

      if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) { 
       NSLog(@"[S3Upload] Background time remaining = %.1f seconds", [UIApplication sharedApplication].backgroundTimeRemaining); 
      } 

     }]; 

    } 

    - (void)appBecameActive 
    { 
     NSLog(@"[S3Upload] App became active again, checking if need to resume upload"); 
     NSLog(self.uploadFileOperation.isPaused ? @"[S3Upload] Operation paused" : @"[S3Upload] Operation not paused"); 
     NSLog(self.uploadFileOperation.isFinished ? @"[S3Upload] Operation finished" : @"[S3Upload] Operation not finished"); 
     if(!self.uploadFileOperation.isFinished && self.uploadFileOperation.isPaused){ 
      NSLog(@"[S3Upload] Resuming upload of %@", clipName); 
      self.uploadFileOperation = [self.tm resume:self.uploadFileOperation requestDelegate:self]; 

      self.backgroundUpload = UIBackgroundTaskInvalid; 
      self.backgroundUpload = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ 
       NSLog(@"[S3Upload] Background handler called. Not running background tasks anymore."); 
       NSLog(@"[S3Upload] Pausing the transfer"); 
       [self.uploadFileOperation pause]; 

       [[NSNotificationCenter defaultCenter] addObserver:self 
                 selector:@selector(appBecameActive) 
                  name:UIApplicationDidBecomeActiveNotification 
                  object:nil]; 

       [[UIApplication sharedApplication] endBackgroundTask:self.backgroundUpload]; 
       self.backgroundUpload = UIBackgroundTaskInvalid; 
      }]; 
     } 
    } 

    - (void)endBgTask:(CDVInvokedUrlCommand*)command 
    { 
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"bg task done"]; 
     [result setKeepCallbackAsBool:false]; 
     [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 

     if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) { 
      NSLog(@"[S3Upload] Background time remaining = %.1f seconds", [UIApplication sharedApplication].backgroundTimeRemaining); 
     } 

     if (self.backgroundUpload == UIBackgroundTaskInvalid) { 
      NSLog(@"[S3Upload] No Background task to invalidate"); 
      return; 
     } 

     NSLog(@"[S3Upload] Invalidating background task"); 
     [[UIApplication sharedApplication] endBackgroundTask:self.backgroundUpload]; 
     self.backgroundUpload = UIBackgroundTaskInvalid; 
     NSLog(@"[S3Upload] Background task invalidated"); 
    } 


    #pragma mark - AmazonServiceRequestDelegate 


    -(void)request:(AmazonServiceRequest *)request didReceiveResponse:(NSURLResponse *)response 
    { 
     NSLog(@"didReceiveResponse called: %@", response); 
    } 

    -(void)request:(AmazonServiceRequest *)request didReceiveData:(NSData *)data 
    { 
     NSLog(@"didReceiveData called"); 
    } 

    -(void)request:(AmazonServiceRequest *)request didSendData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten totalBytesExpectedToWrite:(long long)totalBytesExpectedToWrite 
    { 
     NSLog(@"didSendData called: %lld - %lld/%lld", bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); 
    } 

    -(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response 
    { 
     NSLog(@"didCompleteWithResponse called: %@", response); 
    } 

    -(void)request:(AmazonServiceRequest *)request didFailWithError:(NSError *)error 
    { 
     NSLog(@"didFailWithError called: %@", error); 
    } 

    -(void)dealloc 
    { 
     [[NSNotificationCenter defaultCenter] removeObserver:self]; 
    } 

    @end 
+0

您是否找到解決方案?乾杯 –

回答

0

看看墜毀的這部分:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** NSAllocateMemoryPages(4294967295) failed' 

您試圖在分配設備的內存4294967295字節,這是4GB。 NSAllocateMemoryPages

相關問題