首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AWSS3TransferManager -由于非正常异常而终止应用程序

AWSS3TransferManager -由于非正常异常而终止应用程序
EN

Stack Overflow用户
提问于 2017-06-22 16:22:42
回答 1查看 682关注 0票数 0

我正在创建一个科尔多瓦插件,以上传图片到s3。

当我构建项目时,我会得到以下错误:

代码语言:javascript
复制
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中:

代码语言:javascript
复制
<?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>

这是插件中的函数。

代码语言:javascript
复制
- (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;
    }];
}

异常将抛出:

代码语言:javascript
复制
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-23 10:13:58

我找到了一个使用https://stackoverflow.com/a/39957439/3191747中提供的答案的解决方案

didFinishLaunchingWithOptions中添加以下内容解决了这个问题:

代码语言:javascript
复制
AWSStaticCredentialsProvider *credentialsProvider = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:AWS_ACCESS_KEY secretKey:AWS_SECRET_KEY];

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

    AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44704763

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档