2017-10-27 1 views
-1

AWSS3TransferManagerからデフォルトを取得しようとしているときにエラーが発生します。それはInfo.Plistを設定してAWSS3TransferManager.defaultを取得する方法

'NSInternalInconsistencyException'と表示されます、理由: 'サービス設定はnilです。この方法を使用する前にInfo.plistを設定するか、defaultServiceConfigurationに設定する必要があります。

はここにあなたがapplication:didFinishLaunchingWithOptions:アプリケーションデリゲートメソッドでdefaultServiceConfigurationを設定する必要が私のコード

func downloadFromS3() { 

    var downloadCount = 0 
    for index in 0...2 { 
     let downloadingFilePath = NSTemporaryDirectory().appendingFormat("banner%d.jpg", index+1) 
     let downloadingFileURL = NSURL.fileURL(withPath: downloadingFilePath) 

     let transferManager = AWSS3TransferManager.default() 
     let downloadRequest = AWSS3TransferManagerDownloadRequest() 

     downloadRequest?.bucket = BPAWSBannerBucketName 
     downloadRequest?.key = String(format: "banner%d.jpg",index+1) 
     downloadRequest?.downloadingFileURL = downloadingFileURL 

     print("started download process") 

     let task = transferManager.download(downloadRequest!) 
     task.continueWith (block: { 
      (task) -> AnyObject! in 

      if task.error != nil { 
       print("Error: \(String(describing: task.error))") 
      } else { 
       print("Download successful") 

       let image = UIImage(contentsOfFile: downloadingFilePath) 
       self.bannerImageArr?.add(image!) 
       downloadCount += 1 
       if downloadCount == 3 { 
        DispatchQueue.main.async { 
         self.bannerCollectionView.reloadData() 

        } 
       } 
      } 
      return nil 
     } 
     ) 
    } 
} 

答えて

0

です。

let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId") 
let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialProvider) 
AWSServiceManager.default().defaultServiceConfiguration = configuration 
+0

identityPoolIdの取得方法は? poolIdを追加するinfo.plistの変更 – krishna

+0

これは役に立ちます... https://github.com/awslabs/aws-sdk-ios-samples/blob/master/S3TransferManager-Sample/Swift/S3TransferManagerSampleSwift/Info.plist – NSAdi

+0

私はすでにこれを使用しましたが、私はアクセスを使用しました(:BPAWSAccessKey、秘密鍵:BPAWSSecretKeyアクセスキー) せdefaultServiceConfiguration = AWSServiceConfiguration(地域:AWSRegionType.USEast1、credentialsProvider:credentialsProvider) // defaultServiceConfiguration.maxRetryCount = 5 AWSServiceManager.default()キー.hereは私のコード せcredentialsProvider = AWSStaticCredentialsProviderです.defaultServiceConfiguration = defaultServiceConfiguration – krishna

関連する問題