KvnH
KvnH

Reputation: 506

AWSS3TransferManager - Terminating app due to uncaught exception

I am creating a cordova plugin to upload images to s3.

When I build the project I get the following error:

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.'

I have followed other answers on here and added the extra keys to the 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>

This is the function in the plugin.

- (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;
    }];
}

The exception is thrown at line:

AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];

Upvotes: 0

Views: 713

Answers (1)

KvnH
KvnH

Reputation: 506

I found a solution using the answer provided in https://stackoverflow.com/a/39957439/3191747

Adding the following to didFinishLaunchingWithOptions in the AppDelegate solved the problem:

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

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

    AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;

Upvotes: 1

Related Questions