Parse.com - 如何刷新用户信息 [英] Parse.com - How to refresh the User's information

查看:16
本文介绍了Parse.com - 如何刷新用户信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,当我在 Parse 后端更改 bool 时,我无法在我的 iOS 应用程序中检索此值.请查看以下屏幕截图,其中用户对象的第一个 bool 是手动更改的,第二个是从应用程序更改的.

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(我手动更改了 bool).

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] 对象的更新副本.

to get an updated copy of your [PFUser currentUser] object.

注意:refreshrefreshInBackgroundWithBlock: 现已弃用并已替换为 fetchfetchInBackgroundWithBlock:

更新:

正如 Ryan Kreager 在评论中指出的那样,使用 fetchIfNeeded, fetchIfNeededInBackgroundfetchIfNeededInBackgroundWithBlock: 因为它们将在可用时使用本地缓存."

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆