In order to set up a system on AWS where one can create and use user accounts from an iOS app, I recently followed this tutorial. It uses AWSMobileClient, AWSAuthCore and AWSAuthUI.
I got up something working where I can create accounts and log in and out.
Now I would like to make use of DynamoDB to allow the user to store something. For that, I have tried to integrate DynamoDB code that I have working in another app. But obviously the two apps environment are not quite the same, so it does not work as I would like it to.
Here is the code for the DynamoDB data that I want to handle:
import Foundation
import AWSDynamoDB
@objcMembers
class DynamoDBData: AWSDynamoDBObjectModel, AWSDynamoDBModeling {
var _message,_timeStamp,_user: String?
class func dynamoDBTableName() -> String {
return "DynamoDBData"
}
class func hashKeyAttribute() -> String {
return "_timeStamp"
}
class func rangeKeyAttribute() -> String {
return "_user"
}
override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
return [
"_message" : "message",
"_timeStamp" : "timeStamp",
"_user" : "user"
]
}
}
And here is the code for where I try to save something to the DB and get a crash:
@objc func handleTap() {
print(#function)
let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default() // Here the app is crashing.
// Create data object using the data model:
let dataBlock = DynamoDBData()
dataBlock?._message = "message-TEST"
dataBlock?._timeStamp = "timeStamp-TEST"
dataBlock?._user = "user-TEST"
// Save the new item:
dynamoDbObjectMapper.save(dataBlock!, completionHandler: {
(error: Error?) -> Void in
if let error = error {
print("Amazon DynamoDB Save Error: \(error)")
return
}
print("An item was saved.")
})
}
Finally, this is the message I get when the app is crashing:
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.'
Some guidance (even partial) on how to move forward from here would be very helpful.