代码之家  ›  专栏  ›  技术社区  ›  Vincent

如何在Swift中从AWS Mobile Hub检索电子邮件和电话号码?

  •  0
  • Vincent  · 技术社区  · 8 年前

    是否有人知道如何在Swift中从AWS Mobile Hub检索电子邮件和电话号码(如下图所示)?

    Picture

    我只知道如何使用以下代码检索用户名:

      let serviceConfiguration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:nil)
      let configuration = AWSCognitoIdentityUserPoolConfiguration(clientId: "clientId", clientSecret: "clientSecret", poolId: "poodId")
      AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: configuration, forKey: "Users")
      let pool = AWSCognitoIdentityUserPool(forKey: "Users")
      print(pool.currentUser()?.username)
    

    如有任何建议,将不胜感激。

    1 回复  |  直到 8 年前
        1
  •  0
  •   Vincent    8 年前

    以下是正确的方法:

    @objc func retrieveFromAttributes() {
    
            let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default()
            let newProfileAttributes: ProfileAttributes = ProfileAttributes()
            newProfileAttributes._userId = AWSIdentityManager.default().identityId
            dynamoDbObjectMapper.load(ProfileAttributes.self, hashKey: newProfileAttributes._userId, rangeKey: "Vincent Sun", completionHandler: { (objectModel: AWSDynamoDBObjectModel?, error: Error?) -> Void in
                if let error = error {
                    print("Amazon DynamoDB Read Error: \(error)")
                    return
                }
                    print("An item was read.")
    
                    DispatchQueue.main.async {
                    self.nameTextField.text = objectModel?.dictionaryValue["_nickname"] as? String
                }
    
    
            })
    
    
        }
    
    推荐文章