【问题标题】:Retrieving the latest 10 messages from PubNub server从 PubNub 服务器检索最新的 10 条消息
【发布时间】:2014-06-12 21:08:04
【问题描述】:

根据最新的 PubNub 3.6.2 documentation,我正在使用以下方法来检索频道中发送的最新 10 条消息:

PNDate *now = [PNDate dateWithDate:[NSDate date]];
[PubNub requestHistoryForChannel:self.currentChannel from:nil to:now limit:10 reverseHistory:YES includingTimeToken:YES withCompletionBlock:^(NSArray *retrivedMessages, PNChannel *channel, PNDate *beginDate, PNDate *endDate, PNError *error) {
...}];

我的问题是,在这个频道发送了 10 条消息后,这个方法只会检索前 10 条消息,而不是最近的 10 条消息。我以为使用from:nil to:now 总是会收到最新消息,我想知道我是否错过了什么?

谢谢

【问题讨论】:

    标签: ios pubnub


    【解决方案1】:

    钢琴家,

    您收到前 10 条消息的原因是您指定了reverseHistory:YES。这具有从最旧的消息开始遍历消息历史记录的效果。

    例如,如果我的消息队列是:1,2,3,4,5,6,8,9,10(其中1 是最旧的消息,10 是最新的消息)。

    [PubNub requestHistoryForChannel:self.currentChannel from:nil to:now limit:3 reverseHistory:YES includingTimeToken:YES withCompletionBlock:^(NSArray *retrivedMessages, PNChannel *channel, PNDate *beginDate, PNDate *endDate, PNError *error) { ...}];

    应该返回: [1,2,3]

    通过设置reverseHistory:NO,调用应该是队列中最新的消息。

    所以基于前面的例子:

    [PubNub requestHistoryForChannel:self.currentChannel from:nil to:now limit:3 reverseHistory:NO includingTimeToken:YES withCompletionBlock:^(NSArray *retrivedMessages, PNChannel *channel, PNDate *beginDate, PNDate *endDate, PNError *error) { ...}];

    应该返回: [8,9,10]

    【讨论】:

    • 这很棒 - 是的,设置 reverseHistory 是纠正它的最佳方法。
    猜你喜欢
    • 2015-09-21
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 2023-03-31
    • 2012-12-26
    • 1970-01-01
    相关资源
    最近更新 更多