geekyaleks
geekyaleks

Reputation: 1291

aws Rekognition not initializing on iOS

there seems to be very little to no documentation for AWS iOS text recognition inside an image. I have gone through the process of AWS create IAM with permissions to do Rekognition etc, I created my "mobile app" on AWS from that profile, and I got a json file which is included in my project.

enter image description here

I am initializing the AWS "stack" with no problems also in App Delegate

    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)
}

I get a crash in my 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!)
        }
    }

}

The crash shows this:

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 -

From what I can gather, it seems that I am somehow supposed to configure Rekognition inside of my json file? I did not see that option when the json file was being created on the AWS web site...

Any ideas?

Upvotes: 2

Views: 454

Answers (1)

corym
corym

Reputation: 402

I ran into the same issue trying to use a different AWS service. Adding the service to my awsconfiguration.json file like this worked:

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

Source: I couldn't find this in the documentation, but the SDK is open source

Upvotes: 2

Related Questions