【问题标题】:aws Rekognition not initializing on iOSaws Rekognition 未在 iOS 上初始化
【发布时间】:2019-06-06 20:42:34
【问题描述】:

关于图像中 AWS iOS 文本识别的文档似乎很少甚至没有。我已经完成了 AWS 创建具有 Rekognition 等权限的 IAM 的过程,我从该配置文件在 AWS 上创建了我的“移动应用程序”,并且我得到了一个包含在我的项目中的 json 文件。

我在 App Delegate 中也没有问题地初始化 AWS“堆栈”

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
    AWSDDLog.sharedInstance.logLevel = .info

    return AWSMobileClient.sharedInstance().interceptApplication(
        application,
        didFinishLaunchingWithOptions: launchOptions)
}

我的 ViewController 崩溃了:

    override func viewDidLoad() {
    super.viewDidLoad()

    let rekognitionClient = AWSRekognition.default() // CRASH HERE BOOM

    let sourceImage = UIImage(named: "corolla")

    let image = AWSRekognitionImage()
    image!.bytes = UIImageJPEGRepresentation(sourceImage!, 0.7)

    guard let request = AWSRekognitionDetectLabelsRequest() else {
        puts("Unable to initialize AWSRekognitionDetectLabelsRequest.")
        return
    }

    request.image = image
    request.maxLabels = 3
    request.minConfidence = 90

    rekognitionClient.detectLabels(request) { (response:AWSRekognitionDetectLabelsResponse?, error:Error?) in
        if error == nil {
            print(response!)
        }
    }

}

崩溃表明:

2018-07-27 11:22:10.064126-0400 Plater[13491:5229604] *** Terminating app due    to uncaught exception 'NSInternalInconsistencyException', reason: 'The service configuration is `nil`. You need to configure `awsconfiguration.json`, `Info.plist` or set `defaultServiceConfiguration` before using this method.'
*** First throw call stack:
(
0   CoreFoundation                      0x0000000110d3e1e6 __exceptionPreprocess + 294
1   libobjc.A.dylib                     0x000000010d7d4031 objc_exception_throw + 48
2   AWSRekognition                      0x000000010caf19ac __36+[AWSRekognition defaultRekognition]_block_invoke + 492
3   libdispatch.dylib                   0x0000000111dc97ec _dispatch_client_callout + 8
4   libdispatch.dylib                   0x0000000111dcad64 dispatch_once_f + 285
5   AWSRekognition                      0x000000010caf1794 +[AWSRekognition defaultRekognition] + 84
6   Plater                              0x000000010bd6c5ec _T06Plater14ViewControllerC11viewDidLoadyyF + 124
7   Plater                              0x000000010bd6d364 _T06Plater14ViewControllerC11viewDidLoadyyFTo + 36
8   UIKit                               0x000000010e214131 -

据我所知,我似乎应该在我的 json 文件中配置 Rekognition?在 AWS 网站上创建 json 文件时,我没有看到该选项...

有什么想法吗?

【问题讨论】:

  • 您找到解决方案了吗?请分享

标签: ios swift aws-sdk amazon-rekognition


【解决方案1】:

我在尝试使用不同的 AWS 服务时遇到了同样的问题。像这样将服务添加到我的awsconfiguration.json 文件中:

"Rekognition": {
    "Default": {
        "Region": "us-east-1"
    }
}

来源:我在文档中找不到这个,但 SDK 是 open source

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-01
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多