Kinvey-Xamarin:如何从用户实例接收数据?

时间:2016-07-28 13:19:52

标签: xamarin kinvey

我正在研究一个Kinvey项目,我在从用户实例中读取用户名或特殊属性时遇到一些问题。我首先尝试通过调用_User.ID来获取_User.UserName,但这并没有返回任何内容(但ID很奇怪)。我也在Google上搜索过,但没有任何关于它的文章。希望你能提供帮助,非常感谢!

1 个答案:

答案 0 :(得分:1)

对于特殊属性,请使用.Attributes类上的User数组。 喜欢这段代码:

Console.WriteLine ("custom attribute is: " + kinveyClient.User ().Attributes["myAttribute"]);

对于用户名,请尝试.UserName(),但在填写此字段之前,您似乎必须明确检索User对象

User retrieved;
try {
    retrieved = await kinveyClient.User().RetrieveAsync();
} catch (Exception e) {
    Console.WriteLine("{0} caught exception: ", e);
    retrieved = null;
}
Console.WriteLine ("logged in as: " + retrieved.Username );
Console.WriteLine ("custom attribute is: " + retrieved.Attributes["myAttribute"]);

文档:http://devcenter.kinvey.com/xamarin/guides/users#UserClass

(答案适用于SDK版本1.6.11)