swift - AWS - Swift 中此身份池不支持未经身份验证的访问。
问题描述
我有用于注册和唱歌的自定义 UI,所以不使用 AWSAuthUI
我能够按照文档成功设置注册,并且能够在用户池中看到确认用户。
我在 DynamoDB 访问中遇到问题(身份验证问题)
波纹管是用于登录的代码
@IBAction func btn_login(_ sender: UIButton) {
ActivityIndicator.start()
if(txt_soul_id.text != "" && txt_pwd.text != ""){
let emailTextField = txt_soul_id.text!
let passwordTextField = txt_pwd.text!
let len = passwordTextField.count
if(len > 7){
if(Validations.isValidPassword(password: passwordTextField)){
let mypool = configuration.pool?.getUser(emailTextField)
mypool?.getSession(emailTextField, password: passwordTextField, validationData: nil).continueWith(block: { (task) in
if(task.error != nil){
ActivityIndicator.stop()
Alerts.normal_display(msg_title: "", msg_desc: (task.error?._userInfo!["message"])!, action_title: "OK", myVC: self)
}else{
ActivityIndicator.stop()
DispatchQueue.main.async {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "EditProfileVC_sid") as! EditProfileVC
self.navigationController?.pushViewController(vc, animated: true)
}
}
return nil
})
}else{
ActivityIndicator.stop()
Alerts.normal_display(msg_title: "", msg_desc: "Password must require number, special character, uppercase and lowercase letter.", action_title: "Ok", myVC: self)
}
}else{
ActivityIndicator.stop()
Alerts.normal_display(msg_title: "Minimum 8 Character", msg_desc: "Your password must be at least 8 characters", action_title: "Ok", myVC: self)
}
}else{
ActivityIndicator.stop()
Alerts.normal_display(msg_title: "Required", msg_desc: "Username and password required", action_title: "OK", myVC: self)
}
}
成功登录后,我试图保存到我创建的 dynamodb 模型中
@IBAction func save_profile(_ sender: UIButton) {
let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default()
// Create data object using data models you downloaded from Mobile Hub
let userItem: User = User()
var stype : [String]? = nil
stype?.append("soltype1")
userItem._userId = AWSIdentityManager.default().identityId
//userItem._soultypes = stype
userItem._about = "About Me"
userItem._bday = "19-19-1991"
userItem._culture = "Jain"
userItem._email = "abc@gmail.com"
userItem._mobile = 1234567890
userItem._mobilePrefix = "+32"
userItem._soulid = "mysid"
//Save a new item
dynamoDbObjectMapper.save(userItem, completionHandler: {
(error: Error?) -> Void in
if let error = error {
print("Amazon DynamoDB Save Error: \(error)")
return
}
print("An item was saved.")
})
}
userItem._userId 为零
为 identityId 提供错误 nil 以及 Amazon DynamoDB 保存错误:错误 Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=此身份池不支持未经身份验证的访问。}
解决方案
推荐阅读
- java - Java中的中位数和平方根
- python - 如何使用循环将列表附加到字典
- php - 是否可以使用 Migrating 和 Seed Once 进行 InMemory 测试
- python - 代码不能作为函数工作,但可以在主代码中工作。(Python,pygame)
- django - Ajax - LocalHost 上的 500 内部服务器错误
- angular - 在更改事件之前以角度形式将先前选择的值存储在选择框中
- react-native - 如何使用 react-native-testing-library 提交表单或在输入上按 enter 键
- image - 大的 png 文件不会在 Chrome/Chromium 中呈现
- javascript - 如何使用 nodeJS 获取当前系统音量
- android - 您是否需要 android sdk 才能在真正的 android 设备上使用 appium?