-->

How to delete Pubnub channel history when logout f

2019-09-13 19:15发布

问题:

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.



标签: ios swift pubnub