从应用程序注销时如何删除Pubnub频道历史记录? [英] How to delete Pubnub channel history when logout from app?

查看:51
本文介绍了从应用程序注销时如何删除Pubnub频道历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用 PubNub 频道来阅读消息.

In my App I'm using PubNub channels to read messages.

我以两种状态获取历史记录:

I get history in two status :

 .PNReconnectedCategory
 .PNConnectedCategory

我是这样获取历史的:

if let lastOpenedDate = NSUserDefaults.standardUserDefaults().objectForKey(PubNubModel.lastHistoryFetchKey) as? NSDate {

        let endDate = NSNumber(double:lastOpenedDate.timeIntervalSince1970)

        if UserHistoryChannel != nil {

            self.client?.historyForChannel(UserHistoryChannel!, start: nil, end: endDate, withCompletion: getHistoryCompletionBlock)
        } 
}

lastOpenedDate 是最后收到消息的日期,而

lastOpenedDate is a last received message date, and

在获取历史记录时,我总是检查它,并从该日期和之后获取历史记录.

in getting history I always check on it, and getting the history from this date and after it.

注销时我将此日期设置为nil,因此当用户登录应用程序并连接Pubnub时,获取历史时此日期将是当前日期,并且不会有任何历史记录.

on logout I set this date to nil, so when the user login to the App, and Pubnub connect, when getting history this date will be the current date, and there will be no history.

但是pubnub 仍然得到旧的历史!!

But the pubnub still getting the old history!!

有人尝试清除 pubnub 频道历史记录吗?

anyone try to clear the pubnub channels history?

有什么帮助吗?

谢谢,

推荐答案

History API 允许指定您想要从中获取消息的时间范围.如果您将存储并且永不重置为 nil(因为它将被视为最后收到的消息)时间令牌(message.data.timet‌ oken)并将其用作 endDate 与历史 API(如@CraigConover 所建议)- 使用此设置历史记录将获取自提及日期 (endDate) 以来的最后一条消息(包括已获取日期的消息.使用这种方法允许不提取自上次应用程序运行以来您的应用程序和用户知道的数据.已登录的新用户不会收到来自前一个会话的消息(期望一个).

History API allow to specify time frame from which you want to get messages. If you will store and never reset to nil (because it will be treated as last received messages) time token (message.data.timet‌​oken) and use it as endDate with history API (as suggested by @CraigConover) - using this setup history will fetch last messages since mentioned date (endDate) inclusively (including message from which date has been taken. Using this approach allow not to pull data about which your application and user been aware since last application run. Logged new user's won't get messages (expect one) from previous session.

这篇关于从应用程序注销时如何删除Pubnub频道历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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