How to delete Pubnub channel history when logout from app?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 03:19:10

问题


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

I get history in two status :

 .PNReconnectedCategory
 .PNConnectedCategory

I get history like this way:

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

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.

But the pubnub still getting the old history!!

anyone try to clear the pubnub channels history?

Any help pleasssse?

thanks,


回答1:


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.



来源:https://stackoverflow.com/questions/38695441/how-to-delete-pubnub-channel-history-when-logout-from-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!