【问题标题】:Parse to Heroku migration (MongoLab): PFRelation issue解析到 Heroku 迁移(MongoLab):PFRelation 问题
【发布时间】:2016-06-11 21:02:41
【问题描述】:

我成功地使用 mongolab 将 parse 迁移到 parse-server。现在一切都按预期工作,除了当我使用 MongoLab 使用 PFUser 登录时,我的 PFRelation 对象始终为空。

在我的 AppDelegate 中,当我运行这段代码时(官方 Parse):

[Parse setApplicationId:@"xxxxxx"
              clientKey:@"xxxxxx"];
[PFUser enableRevocableSessionInBackground];

HomeView.m:

self.currentUser = [PFUser currentUser];
self.friendsRelation = [[PFUser currentUser] objectForKey:@"friends"];
NSLog(@"%@", self.currentUser);
NSLog(@"%@", self.friendsRelation);

登录后,我的 HomeView 会记录:

2016-02-28 23:25:38.756 ChillN[4131:57119] <PFUser: 0x7fe0b3e4fc10, objectId: MZdPHaqByR, localId: (null)> {
    friends = "<PFRelation: 0x7fe0b3e4f900, 0x7fe0b3e4fc10.friends -> _User>";
    phone = "06 19 05 39 30";
    surname = a;
    username = a;
}
2016-02-28 23:25:38.756 ChillN[4131:57119] <PFRelation: 0x7fe0b3e4f900, 0x7fe0b3e4fc10.friends -> _User>

所以一切正常。

现在使用 mongolab 数据库:

AppDelegate:

[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) {
    configuration.applicationId = @"xxxxxxx";
    configuration.clientKey = @"xxxxxxx";
    configuration.server = @"http://xxxxxxx.herokuapp.com/parse/";
}]];

登录后,我的 HomeView 会记录以下内容:

2016-02-28 23:29:21.785 ChillN[4281:59046] <PFUser: 0x7fa43c09ed20, objectId: MZdPHaqByR, localId: (null)> {
    phone = "06 19 05 39 27";
    surname = a;
    username = a;
}
2016-02-28 23:29:21.786 ChillN[4281:59046] (null)

对于日志记录,我只是使用:

[PFUser logInWithUsernameInBackground:user
                                 password:password block:^(PFUser *user, NSError *error) {}];

这是我的数据库: 解析:

Heroku(MongoLab):

这是来自 MongoLab 的用户记录:

{
    "_id": "MZdPHaqByR",
    "_perishable_token": "SHuhtWl0EoxxmNLOkspmp1vBF",
    "username": "a",
    "phone": "06 19 05 39 27",
    "surname": "a",
    "_session_token": "zO2drjzrO0To1q0JiohaL8f4v",
    "_hashed_password": "$2a$10$a7j5yB7uFDtv.YnHESVJgO9Io.nci8hbx7vngOo.FyzA3qBLxw38G",
    "_created_at": {
        "$date": "2016-02-28T21:55:48.548Z"
    },
    "_updated_at": {
        "$date": "2016-02-28T22:03:45.704Z"
    }
}

【问题讨论】:

    标签: ios heroku parse-platform mlab pfrelation


    【解决方案1】:

    这只是我的代码中的一个错误,我不得不替换:

    self.friendsRelation = [[PFUser currentUser] objectForKey:@"friends"];
    

    self.friendsRelation = [[PFUser currentUser] relationForKey:@"friends"];
    

    希望这会帮助另一个人。干杯!

    【讨论】:

      猜你喜欢
      • 2017-06-25
      • 2016-09-06
      • 2016-05-11
      • 2012-06-05
      • 1970-01-01
      • 2017-07-10
      • 2021-07-13
      • 2016-05-26
      • 1970-01-01
      相关资源
      最近更新 更多