2017-06-22 106 views
0

我正在創建一個cordova插件以將圖像上傳到s3。AWSS3TransferManager - 由於未捕獲的異常而終止應用程序

當我建立了項目,我得到以下錯誤:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The service configuration is `nil`. You need to configure `Info.plist` or set `defaultServiceConfiguration` before using this method.' 

我已經跟着就到這裏其他的答案,並添加額外的鑰匙,info.plist中:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
    <key>CFBundleDevelopmentRegion</key> 
    <string>en</string> 
    <key>CFBundleDisplayName</key> 
    <string>${PRODUCT_NAME}</string> 
    <key>CFBundleExecutable</key> 
    <string>${EXECUTABLE_NAME}</string> 
    <key>CFBundleIcons~ipad</key> 
    <dict> 
     <key>CFBundlePrimaryIcon</key> 
     <dict> 
      <key>CFBundleIconFiles</key> 
      <array> 
       <string>icon-small</string> 
       <string>icon-40</string> 
       <string>icon-50</string> 
       <string>icon-76</string> 
       <string>icon-72</string> 
       <string>icon</string> 
      </array> 
     </dict> 
    </dict> 
    <key>CFBundleIdentifier</key> 
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> 
    <key>CFBundleInfoDictionaryVersion</key> 
    <string>6.0</string> 
    <key>CFBundleName</key> 
    <string>${PRODUCT_NAME}</string> 
    <key>CFBundlePackageType</key> 
    <string>APPL</string> 
    <key>CFBundleShortVersionString</key> 
    <string>4.28.1</string> 
    <key>CFBundleSignature</key> 
    <string>????</string> 
    <key>CFBundleVersion</key> 
    <string>0.0.1</string> 
    <key>Fabric</key> 
    <dict> 
     <key>APIKey</key> 
     <string></string> 
     <key>Kits</key> 
     <array> 
      <dict> 
       <key>KitInfo</key> 
       <dict/> 
       <key>KitName</key> 
       <string>Crashlytics</string> 
      </dict> 
     </array> 
    </dict> 
    <key>LSRequiresIPhoneOS</key> 
    <true/> 
    <key>DynamoDBObjectMapper</key> 
    <dict> 
    <key>Default</key> 
    <dict> 
     <key>Region</key> 
     <string>eu-west-1</string> 
    </dict> 
    </dict> 
    <key>NSAppTransportSecurity</key> 
    <dict> 
     <key>NSExceptionDomains</key> 
     <dict> 
      <key>amazonaws.com</key> 
      <dict> 
       <key>NSThirdPartyExceptionMinimumTLSVersion</key> 
       <string>TLSv1.0</string> 
       <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> 
       <false/> 
       <key>NSIncludesSubdomains</key> 
       <true/> 
      </dict> 
      <key>amazonaws.com.cn</key> 
      <dict> 
       <key>NSThirdPartyExceptionMinimumTLSVersion</key> 
       <string>TLSv1.0</string> 
       <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> 
       <false/> 
       <key>NSIncludesSubdomains</key> 
       <true/> 
      </dict> 
      <key>localhost</key> 
      <dict> 
       <key>NSExceptionAllowsInsecureHTTPLoads</key> 
       <true/> 
      </dict> 
     </dict> 
     <key>NSAllowsArbitraryLoads</key> 
     <true/> 
    </dict> 
    <key>NSLocationUsageDescription</key> 
    <string>Geolocation information is used to tag assessments and assessment contents with the users location. This is only used when conducting an assessment.</string> 
    <key>NSLocationWhenInUseUsageDescription</key> 
    <string>Geolocation information is used to tag assessments and assessment contents with the users location. This is only used when conducting an assessment.</string> 
    <key>UIRequiredDeviceCapabilities</key> 
    <array> 
     <string>armv7</string> 
    </array> 
    <key>UIRequiresFullScreen</key> 
    <true/> 
    <key>UIStatusBarHidden~ipad</key> 
    <true/> 
    <key>UISupportedInterfaceOrientations</key> 
    <array> 
     <string>UIInterfaceOrientationLandscapeLeft</string> 
     <string>UIInterfaceOrientationLandscapeRight</string> 
     <string>UIInterfaceOrientationPortrait</string> 
     <string>UIInterfaceOrientationPortraitUpsideDown</string> 
    </array> 
    <key>UISupportedInterfaceOrientations~ipad</key> 
    <array> 
     <string>UIInterfaceOrientationLandscapeLeft</string> 
     <string>UIInterfaceOrientationLandscapeRight</string> 
     <string>UIInterfaceOrientationPortrait</string> 
     <string>UIInterfaceOrientationPortraitUpsideDown</string> 
    </array> 
    <key>AWS</key> 
    <dict> 
     <key>S3TransferManager</key> 
     <dict> 
      <key>Default</key> 
      <dict> 
       <key>Region</key> 
       <string>eu-west-1</string> 
      </dict> 
     </dict> 
    </dict> 
</dict> 
</plist> 

這是功能在插件中。

- (void)uploadImage:(CDVInvokedUrlCommand*)command 
{ 
    AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager]; 

    NSString* filePath = [command argumentAtIndex:0 withDefault:nil]; 
    NSURL *uploadingFileURL = [NSURL fileURLWithPath: filePath]; 

    AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new]; 

    uploadRequest.bucket = @"my-test-bucket"; 
    uploadRequest.key = @"mykey"; 
    uploadRequest.body = uploadingFileURL; 

    [[transferManager upload:uploadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor] 
      withBlock:^id(AWSTask *task) { 
    if (task.error) { 
     if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) { 
      switch (task.error.code) { 
       case AWSS3TransferManagerErrorCancelled: 
       case AWSS3TransferManagerErrorPaused: 
        break; 

       default: 
        NSLog(@"Error: %@", task.error); 
        break; 
      } 
     } else { 
      // Unknown error. 
      NSLog(@"Error: %@", task.error); 
     } 
    } 

    if (task.result) { 
     AWSS3TransferManagerUploadOutput *uploadOutput = task.result; 
     // The file uploaded successfully. 
    } 
    return nil; 
    }]; 
} 

唯一的例外是在行拋出:

AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager]; 

回答

0

我在AppDelegate發現使用https://stackoverflow.com/a/39957439/3191747

提供了答案添加以下解決didFinishLaunchingWithOptions解決了這個問題:

AWSStaticCredentialsProvider *credentialsProvider = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:AWS_ACCESS_KEY secretKey:AWS_SECRET_KEY]; 

    AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionAPSoutheast1 
                    credentialsProvider:credentialsProvider]; 

    AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration; 
相關問題