Parse.com-如何刷新用户信息 [英] Parse.com - How to refresh the User's information
问题描述
例如,当我在解析后端中更改布尔值时,我无法在我的iOS应用中检索此值.请查看以下屏幕截图,其中用户对象的第一个布尔值已手动更改,第二个已从应用程序中更改.
When I'm changing for example a bool in the Parse backend I can not retrieve this value in my iOS app. Please see the following screenshot where the first bool of the user object was changed manually and the second was changed from the app.
第一个不起作用,而第一个(从应用程序更改的)起作用. 我通过以下代码获得价值:
The first one does not work whereas the one (that was changed from the app) does work. I'm getting the value with the following piece of code:
[[PFUser currentUser] objectForKey:@"is_pro"]
在第一种情况下,返回对象始终为nil
(在这里我手动更改了布尔值).
In the first case the return object is always nil
(where I've changed the bool manually).
推荐答案
对用户的Parse表进行更改后,调用
After you've made changes to your user's Parse table, call
[[PFUser currentUser] fetch]; //synchronous
或
[[PFUser currentUser] fetchInBackground]; //asynchronous
或
[[PFUser currentUser] fetchInBackgroundWithBlock:^(PFObject *object, NSError *error) { //asynchronous with completion block
之前
[[PFUser currentUser] objectForKey:@"is_pro"]
获取[PFUser currentUser]
对象的更新副本.
注意: refresh
和 refreshInBackgroundWithBlock:
是现在已弃用,并已替换为 fetch
和 fetchInBackgroundWithBlock:
Note: refresh
and refreshInBackgroundWithBlock:
are now deprecated and have been replaced with fetch
and fetchInBackgroundWithBlock:
更新:
正如Ryan Kreager在评论中指出的那样,使用 fetchIfNeededInBackground
或 fetchIfNeededInBackgroundWithBlock:
因为它们将在可用时使用本地缓存."
As Ryan Kreager pointed out in the comments, it's probably better/more efficient to use fetchIfNeeded
, fetchIfNeededInBackground
, or fetchIfNeededInBackgroundWithBlock:
"since they will use the local cache when available."
这篇关于Parse.com-如何刷新用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!