身份验证后在iOS中使用DynamoDB [英] Using DynamoDB within iOS after authentication
问题描述
为了在 AWS
上建立一个系统,在该系统上可以从iOS应用程序创建和使用用户帐户,我最近关注了本教程。它使用 AWSMobileClient
, AWSAuthCore
和 AWSAuthUI
。
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.
现在我想利用 DynamoDB
允许用户存储某些内容。为此,我尝试集成在其他应用程序中工作的 DynamoDB
代码。但是显然,两个应用程序环境并不完全相同,因此它无法按我的意愿运行。
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.
这是我想要的DynamoDB数据的代码处理:
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.
推荐答案
检查您的 awsconfiguration.json
包含以下条目:
Check that your awsconfiguration.json
has the following entry:
"DynamoDBObjectMapper": {
"Default": {
"Region": "AWS_REGION_NAME"
}
}
设置您自己的 AWS_REGION_NAME
(例如, us-east-1
)。
setting your own AWS_REGION_NAME
(e.g., us-east-1
).
这篇关于身份验证后在iOS中使用DynamoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!