Last active
June 10, 2021 01:16
-
-
Save supertopoz/859e70365463a91d38af3d75915082e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// sendbird_channel_change | |
// | |
// Created by Jason.Allshorn on 08/06/2021. | |
// | |
import UIKit | |
import SendBirdSDK | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
//Init | |
let APP_ID = "APP_ID" | |
SBDMain.initWithApplicationId(APP_ID) | |
let USER_ID = "UserA" | |
//Connect | |
SBDMain.connect(withUserId: USER_ID, completionHandler: { (user, error) in | |
guard error == nil else { return } | |
}) | |
} | |
@IBAction func getChangedChannels(_ sender: Any) { | |
// Button Clicked | |
self.processChangedChannels() | |
} | |
func writeLog (_ updatedChannels: [SBDGroupChannel]?, _ deletedChannels: [String]?, _ nextToken: String?) { | |
print("updated channels \(updatedChannels!)") | |
print("deletedChannels \(deletedChannels!)") | |
//Update change log token | |
} | |
func processChangedChannels () { | |
//Set change log params | |
let params = SBDGroupChannelChangeLogsParams() | |
params.includeEmptyChannel = true | |
//If change log token doesn't exist locally | |
if (UserDefaults.standard.string(forKey: "nextToken") == nil) { | |
let ts = SBDMain.getLastConnectedAt() | |
SBDMain.getMyGroupChannelChangeLogs(byTimestamp: ts, params: params) { updatedChannels, deletedChannels, hasMore, nextToken, error in | |
guard error == nil else { | |
return | |
} | |
self.writeLog(updatedChannels, deletedChannels, nextToken) | |
} | |
} else { | |
let token = UserDefaults.standard.string(forKey: "nextToken") | |
SBDMain.getMyGroupChannelChangeLogs(byToken: token, params: params) { updatedChannels, deletedChannels, hasMore, nextToken, error in | |
guard error == nil else { return } | |
self.writeLog(updatedChannels, deletedChannels, nextToken) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment