Parse.com - How to refresh the User's information

后端 未结 3 2071
不知归路
不知归路 2021-02-06 07:18

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 obje

3条回答
  •  不知归路
    2021-02-06 08:11

    After you've made changes to your user's Parse table, call

    [[PFUser currentUser] fetch]; //synchronous
    

    or

    [[PFUser currentUser] fetchInBackground]; //asynchronous
    

    or

    [[PFUser currentUser] fetchInBackgroundWithBlock:^(PFObject *object, NSError *error) { //asynchronous with completion block
    

    before

    [[PFUser currentUser] objectForKey:@"is_pro"]
    

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

    Note: refresh and refreshInBackgroundWithBlock: are now deprecated and have been replaced with fetch and fetchInBackgroundWithBlock:

    Update:

    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."

提交回复
热议问题