diff --git a/.gitignore b/.gitignore index 3ed0476..eab39d1 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,5 @@ Chat-Unity/chat_unity_quickstart/ProjectSettings/ Chat-Unity/chat_unity_quickstart/UserSettings/EditorUserSettings.asset Chat-Unity/chat_unity_quickstart/UserSettings/ Chat-Unity/chat_unity_quickstart/Packages/ +/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Pods +/Chat-iOS/AgoraChatAPIExample/Pods diff --git a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift.xcodeproj/project.pbxproj b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift.xcodeproj/project.pbxproj index bd822d5..c213f73 100644 --- a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift.xcodeproj/project.pbxproj +++ b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 05F4366A28F1200600AC9A46 /* AgoraChatSendVideoController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05F4366928F1200600AC9A46 /* AgoraChatSendVideoController.swift */; }; 662FBDBA28615AEC0089A3CF /* AgoraChatImageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 662FBDB928615AEC0089A3CF /* AgoraChatImageCell.swift */; }; 66DEBE42286040AF00AB9465 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66DEBE41286040AF00AB9465 /* AppDelegate.swift */; }; 66DEBE46286040AF00AB9465 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66DEBE45286040AF00AB9465 /* ViewController.swift */; }; @@ -17,11 +18,12 @@ 66DEBE5A2860577600AB9465 /* AgoraChatSendTextViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66DEBE592860577600AB9465 /* AgoraChatSendTextViewController.swift */; }; 66DEBE5F28605AAA00AB9465 /* AgoraChatTextCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66DEBE5E28605AAA00AB9465 /* AgoraChatTextCell.swift */; }; 66DEBE6128605CF900AB9465 /* AgoraChatConversationsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66DEBE6028605CF900AB9465 /* AgoraChatConversationsViewController.swift */; }; - 66DEBE63286070F800AB9465 /* AgoraChatSendImageVideoController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66DEBE62286070F800AB9465 /* AgoraChatSendImageVideoController.swift */; }; + 66DEBE63286070F800AB9465 /* AgoraChatSendImageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66DEBE62286070F800AB9465 /* AgoraChatSendImageController.swift */; }; F9F9666FA1F0D5957A12DB6B /* Pods_AgoraChatAPIExample_Swift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C4B62263AADB6A28ED3EC79 /* Pods_AgoraChatAPIExample_Swift.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 05F4366928F1200600AC9A46 /* AgoraChatSendVideoController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgoraChatSendVideoController.swift; sourceTree = ""; }; 13D4326DAA8D17023CED02A4 /* Pods-AgoraChatAPIExample-Swift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AgoraChatAPIExample-Swift.release.xcconfig"; path = "Target Support Files/Pods-AgoraChatAPIExample-Swift/Pods-AgoraChatAPIExample-Swift.release.xcconfig"; sourceTree = ""; }; 662FBDB928615AEC0089A3CF /* AgoraChatImageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgoraChatImageCell.swift; sourceTree = ""; }; 66DEBE3E286040AF00AB9465 /* AgoraChatAPIExample-Swift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "AgoraChatAPIExample-Swift.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -35,7 +37,7 @@ 66DEBE592860577600AB9465 /* AgoraChatSendTextViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgoraChatSendTextViewController.swift; sourceTree = ""; }; 66DEBE5E28605AAA00AB9465 /* AgoraChatTextCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgoraChatTextCell.swift; sourceTree = ""; }; 66DEBE6028605CF900AB9465 /* AgoraChatConversationsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgoraChatConversationsViewController.swift; sourceTree = ""; }; - 66DEBE62286070F800AB9465 /* AgoraChatSendImageVideoController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgoraChatSendImageVideoController.swift; sourceTree = ""; }; + 66DEBE62286070F800AB9465 /* AgoraChatSendImageController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgoraChatSendImageController.swift; sourceTree = ""; }; 9C4B62263AADB6A28ED3EC79 /* Pods_AgoraChatAPIExample_Swift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AgoraChatAPIExample_Swift.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C73A60BA5101D95C00C51B3F /* Pods-AgoraChatAPIExample-Swift.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AgoraChatAPIExample-Swift.debug.xcconfig"; path = "Target Support Files/Pods-AgoraChatAPIExample-Swift/Pods-AgoraChatAPIExample-Swift.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -90,7 +92,8 @@ 66DEBE45286040AF00AB9465 /* ViewController.swift */, 66DEBE572860489600AB9465 /* AgoraChatLoginViewController.swift */, 66DEBE592860577600AB9465 /* AgoraChatSendTextViewController.swift */, - 66DEBE62286070F800AB9465 /* AgoraChatSendImageVideoController.swift */, + 66DEBE62286070F800AB9465 /* AgoraChatSendImageController.swift */, + 05F4366928F1200600AC9A46 /* AgoraChatSendVideoController.swift */, 66DEBE6028605CF900AB9465 /* AgoraChatConversationsViewController.swift */, ); path = Controllers; @@ -228,10 +231,14 @@ inputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-AgoraChatAPIExample-Swift/Pods-AgoraChatAPIExample-Swift-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); + inputPaths = ( + ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-AgoraChatAPIExample-Swift/Pods-AgoraChatAPIExample-Swift-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); + outputPaths = ( + ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-AgoraChatAPIExample-Swift/Pods-AgoraChatAPIExample-Swift-frameworks.sh\"\n"; @@ -248,8 +255,9 @@ 66DEBE5F28605AAA00AB9465 /* AgoraChatTextCell.swift in Sources */, 66DEBE5A2860577600AB9465 /* AgoraChatSendTextViewController.swift in Sources */, 66DEBE42286040AF00AB9465 /* AppDelegate.swift in Sources */, - 66DEBE63286070F800AB9465 /* AgoraChatSendImageVideoController.swift in Sources */, + 66DEBE63286070F800AB9465 /* AgoraChatSendImageController.swift in Sources */, 662FBDBA28615AEC0089A3CF /* AgoraChatImageCell.swift in Sources */, + 05F4366A28F1200600AC9A46 /* AgoraChatSendVideoController.swift in Sources */, 66DEBE562860436B00AB9465 /* AgoraChatRequest.swift in Sources */, 66DEBE582860489600AB9465 /* AgoraChatLoginViewController.swift in Sources */, 66DEBE6128605CF900AB9465 /* AgoraChatConversationsViewController.swift in Sources */, @@ -392,9 +400,10 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = 499WYUV8Q2; + DEVELOPMENT_TEAM = JC854K845H; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "AgoraChatAPIExample-Swift/Info.plist"; + INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "using send image"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait; @@ -406,7 +415,7 @@ "@executable_path/Frameworks", ); MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = "luomobancheng-gmail.com.AgoraChatAPIExample-Swift"; + PRODUCT_BUNDLE_IDENTIFIER = "com.AgoraChatAPIExample-Swift"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; @@ -422,9 +431,10 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = 499WYUV8Q2; + DEVELOPMENT_TEAM = JC854K845H; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "AgoraChatAPIExample-Swift/Info.plist"; + INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "using send image"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait; @@ -436,7 +446,7 @@ "@executable_path/Frameworks", ); MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = "luomobancheng-gmail.com.AgoraChatAPIExample-Swift"; + PRODUCT_BUNDLE_IDENTIFIER = "com.AgoraChatAPIExample-Swift"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; diff --git a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AppDelegate.swift b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AppDelegate.swift index bf02c9b..f635b0a 100644 --- a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AppDelegate.swift +++ b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AppDelegate.swift @@ -41,11 +41,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } private func agoraChatInitlize() { - let options = AgoraChatOptions(appkey: AgoraChatRequest.appKey) + let options = AgoraChatOptions(appId: AgoraChatRequest.appID) options.enableConsoleLog = true options.isAutoLogin = true - options.pushKitCertName = "com.easemob.enterprise.demo.ui.voip" - options.apnsCertName = "ChatDemoDevPush" + AgoraChatClient.shared().initializeSDK(with: options) } } diff --git a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Cells/AgoraChatImageCell.swift b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Cells/AgoraChatImageCell.swift index 47116ec..7310de0 100644 --- a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Cells/AgoraChatImageCell.swift +++ b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Cells/AgoraChatImageCell.swift @@ -45,7 +45,7 @@ extension AgoraChatImageCell { guard let body = message.body as? AgoraChatImageMessageBody else { return } if body.localPath.isEmpty,body.thumbnailLocalPath.isEmpty { ProgressHUD.show("downloading image...") - AgoraChatClient.shared().chatManager.downloadMessageAttachment(message, progress: nil) { msg, error in + AgoraChatClient.shared().chatManager?.downloadMessageAttachment(message, progress: nil) { msg, error in ProgressHUD.dismiss() if error == nil { self.picture.image = UIImage(contentsOfFile: body.thumbnailLocalPath.isEmpty ? body.localPath:body.thumbnailLocalPath) diff --git a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatConversationsViewController.swift b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatConversationsViewController.swift index f56ccad..c9f3e78 100644 --- a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatConversationsViewController.swift +++ b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatConversationsViewController.swift @@ -23,7 +23,7 @@ final class AgoraChatConversationsViewController: UIViewController,UITableViewDe override func viewDidLoad() { super.viewDidLoad() - guard let datas = AgoraChatClient.shared().chatManager.getAllConversations() else { return } + guard let datas = AgoraChatClient.shared().chatManager?.getAllConversations() else { return } if self.title == "Join a group" { self.conversations = datas.filter({ $0.type == .groupChat }) } else { @@ -32,12 +32,12 @@ final class AgoraChatConversationsViewController: UIViewController,UITableViewDe // Do any additional setup after loading the view. self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChat)) self.view.addSubview(self.conversationList) - AgoraChatClient.shared().chatManager.add(self, delegateQueue: .main) + AgoraChatClient.shared().chatManager?.add(self, delegateQueue: .main) } deinit { AgoraChatClient.shared().removeDelegate(self) - AgoraChatClient.shared().chatManager.remove(self) + AgoraChatClient.shared().chatManager?.remove(self) } } @@ -71,7 +71,7 @@ extension AgoraChatConversationsViewController { case "Send text message": VC = AgoraChatSendTextViewController.init(to) case "Send image message": - VC = AgoraChatSendImageVideoController.init(to) + VC = AgoraChatSendImageController.init(to) default: VC = AgoraChatSendTextViewController.init(to) } @@ -102,7 +102,7 @@ extension AgoraChatConversationsViewController { return } if self.title == "Join a group" { - AgoraChatClient.shared().groupManager.joinPublicGroup(self.toChatId) { group, error in + AgoraChatClient.shared().groupManager?.joinPublicGroup(self.toChatId) { group, error in if error == nil { self.createConversation(.groupChat) } else { @@ -116,16 +116,17 @@ extension AgoraChatConversationsViewController { } private func createConversation(_ type: AgoraChatConversationType) { - let item: AgoraChatConversation = AgoraChatClient.shared().chatManager.getConversation(self.toChatId, type: type, createIfNotExist: true)! - let temp = self.conversations.filter { $0.conversationId == item.conversationId - } - if temp.count <= 0 { - self.conversations.append(item) - self.conversationList.reloadData() + if let item: AgoraChatConversation = AgoraChatClient.shared().chatManager?.getConversation(self.toChatId, type: type, createIfNotExist: true) { + let temp = self.conversations.filter { $0.conversationId == item.conversationId + } + if temp.count <= 0 { + self.conversations.append(item) + self.conversationList.reloadData() + } + let to = self.toChatId + let message = AgoraChatMessage(conversationID: to, from: AgoraChatClient.shared().currentUsername!, to: to, body: AgoraChatTextMessageBody(text: "Hello!"), ext: [:]) + AgoraChatClient.shared().chatManager?.send(message, progress: nil) } - let to = self.toChatId - let message = AgoraChatMessage(conversationID: to, from: AgoraChatClient.shared().currentUsername!, to: to, body: AgoraChatTextMessageBody(text: "Hello!"), ext: [:]) - AgoraChatClient.shared().chatManager.send(message, progress: nil) } //MARK: - UITextFieldDelegate @@ -136,11 +137,12 @@ extension AgoraChatConversationsViewController { //MARK: - AgoraChatManagerDelegate func messagesDidReceive(_ aMessages: [AgoraChatMessage]) { for message in aMessages { - let item: AgoraChatConversation = AgoraChatClient.shared().chatManager.getConversation(message.conversationId, type: AgoraChatConversationType.init(rawValue: 0)!, createIfNotExist: true)! - let temp = self.conversations.filter { $0.conversationId == item.conversationId - } - if temp.count <= 0 { - self.conversations.append(item) + if let item: AgoraChatConversation = AgoraChatClient.shared().chatManager?.getConversation(message.conversationId, type: AgoraChatConversationType(rawValue: 0) ?? .chat, createIfNotExist: true) { + let temp = self.conversations.filter { $0.conversationId == item.conversationId + } + if temp.count <= 0 { + self.conversations.append(item) + } } } DispatchQueue.main.async { diff --git a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendImageVideoController.swift b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendImageController.swift similarity index 89% rename from Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendImageVideoController.swift rename to Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendImageController.swift index b56af53..f886806 100644 --- a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendImageVideoController.swift +++ b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendImageController.swift @@ -9,7 +9,7 @@ import UIKit import Photos import ZSwiftBaseLib -final class AgoraChatSendImageVideoController: UIViewController,UITableViewDelegate,UITableViewDataSource,AgoraChatClientDelegate, AgoraChatManagerDelegate,UIImagePickerControllerDelegate, UINavigationControllerDelegate { +final class AgoraChatSendImageController: UIViewController,UITableViewDelegate,UITableViewDataSource,AgoraChatClientDelegate, AgoraChatManagerDelegate,UIImagePickerControllerDelegate, UINavigationControllerDelegate { private var filePath = "" @@ -34,7 +34,7 @@ final class AgoraChatSendImageVideoController: UIViewController,UITableViewDeleg convenience init(_ conversationId: String) { self.init() - self.conversation = AgoraChatClient.shared().chatManager.getConversationWithConvId(conversationId) + self.conversation = AgoraChatClient.shared().chatManager?.getConversationWithConvId(conversationId) let messages = self.conversation?.loadMessagesStart(fromId: "", count: 50, searchDirection: AgoraChatMessageSearchDirection.init(rawValue: 0)!) ?? [] for message in messages { if message.body.type == .image { @@ -47,20 +47,20 @@ final class AgoraChatSendImageVideoController: UIViewController,UITableViewDeleg super.viewDidLoad() self.view.addSubViews([self.messagesList,self.sendImage]) AgoraChatClient.shared().add(self, delegateQueue: .main) - AgoraChatClient.shared().chatManager.add(self, delegateQueue: .main) + AgoraChatClient.shared().chatManager?.add(self, delegateQueue: .main) // Do any additional setup after loading the view. } deinit { AgoraChatClient.shared().removeDelegate(self) - AgoraChatClient.shared().chatManager.remove(self) + AgoraChatClient.shared().chatManager?.remove(self) NotificationCenter.default.removeObserver(self) } } //MARK: - Private method -extension AgoraChatSendImageVideoController { +extension AgoraChatSendImageController { @objc private func sendImageAction() { PHPhotoLibrary.requestAuthorization { status in @@ -105,10 +105,10 @@ extension AgoraChatSendImageVideoController { let to = self.conversation?.conversationId ?? "" let message = AgoraChatMessage(conversationID: to, from: AgoraChatClient.shared().currentUsername!, to: to, body: body, ext: nil) ProgressHUD.show("sending image...") - AgoraChatClient.shared().chatManager.send(message, progress: nil) { msg, error in + AgoraChatClient.shared().chatManager?.send(message, progress: nil) { msg, error in ProgressHUD.dismiss() - if error == nil { - self.messages.append(msg!) + if error == nil,let message = msg { + self.messages.append(message) self.messagesList.reloadData() } else { ProgressHUD.showError("\(error?.errorDescription ?? "")") diff --git a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendTextViewController.swift b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendTextViewController.swift index 1f03214..5d2ba06 100644 --- a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendTextViewController.swift +++ b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendTextViewController.swift @@ -28,7 +28,7 @@ final class AgoraChatSendTextViewController: UIViewController,UITableViewDelegat convenience init(_ conversationId: String) { self.init() - self.conversation = AgoraChatClient.shared().chatManager.getConversationWithConvId(conversationId) + self.conversation = AgoraChatClient.shared().chatManager?.getConversationWithConvId(conversationId) let messages = self.conversation?.loadMessagesStart(fromId: "", count: 50, searchDirection: .up) ?? [] for message in messages { if message.body.type == .text { @@ -45,14 +45,14 @@ final class AgoraChatSendTextViewController: UIViewController,UITableViewDelegat self.view.addSubViews([self.messagesList,self.messageField]) self.messageField.returnKeyType = .send AgoraChatClient.shared().add(self, delegateQueue: .main) - AgoraChatClient.shared().chatManager.add(self, delegateQueue: .main) + AgoraChatClient.shared().chatManager?.add(self, delegateQueue: .main) NotificationCenter.default.addObserver(self, selector: #selector(showKeyboard(notify:)), name: UIResponder.keyboardWillShowNotification, object: nil) // Do any additional setup after loading the view. } deinit { AgoraChatClient.shared().removeDelegate(self) - AgoraChatClient.shared().chatManager.remove(self) + AgoraChatClient.shared().chatManager?.remove(self) NotificationCenter.default.removeObserver(self) } } @@ -95,7 +95,7 @@ extension AgoraChatSendTextViewController { private func sendTextMessage(_ text: String) { let to = self.conversation?.conversationId ?? "" let message = AgoraChatMessage(conversationID: to, from: AgoraChatClient.shared().currentUsername!, to: to, body: AgoraChatTextMessageBody(text: text), ext: [:]) - AgoraChatClient.shared().chatManager.send(message, progress: nil) { sendMessage, error in + AgoraChatClient.shared().chatManager?.send(message, progress: nil) { sendMessage, error in if error == nil { if self.heightMap[message.messageId] ?? 0 <= 0 { self.heightMap[message.messageId] = AgoraChatTextCell.contentHeight(message)+52 diff --git a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendVideoController.swift b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendVideoController.swift new file mode 100644 index 0000000..2234522 --- /dev/null +++ b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Controllers/AgoraChatSendVideoController.swift @@ -0,0 +1,211 @@ +// +// AgoraChatSendVideoController.swift +// AgoraChatAPIExample-Swift +// +// Created by 朱继超 on 2022/10/8. +// + +import UIKit +import AgoraChat +import ZSwiftBaseLib +import Photos + +final class AgoraChatSendVideoController: UIViewController,UITableViewDelegate,UITableViewDataSource,AgoraChatClientDelegate, AgoraChatManagerDelegate,UIImagePickerControllerDelegate, UINavigationControllerDelegate { + + private var filePath = "" + + private var messages: [AgoraChatMessage] = [AgoraChatMessage]() + + private var conversation: AgoraChatConversation? + + private lazy var imagePicker: UIImagePickerController = { + let picker = UIImagePickerController.init() + picker.modalPresentationStyle = .fullScreen + picker.delegate = self + return picker + }() + + private lazy var messagesList: UITableView = { + UITableView(frame: CGRect(x: 0, y: ZNavgationHeight, width: ScreenWidth, height: ScreenHeight-ZNavgationHeight-40-CGFloat(ZBottombarHeight)), style: .plain).delegate(self).dataSource(self).tableFooterView(UIView()).separatorStyle(.none) + }() + + private lazy var sendImage: UIButton = { + UIButton(type: .custom).frame(CGRect(x: 10, y: ScreenHeight-40-CGFloat(ZBottombarHeight), width: ScreenWidth - 20, height: 45)).backgroundColor(UIColor(0x0066ff)).cornerRadius(10).title("Send Image", .normal).font(UIFont.systemFont(ofSize: 18, weight: .semibold)).addTargetFor(self, action: #selector(sendImageAction), for: .touchUpInside) + }() + + convenience init(_ conversationId: String) { + self.init() + self.conversation = AgoraChatClient.shared().chatManager?.getConversationWithConvId(conversationId) + let messages = self.conversation?.loadMessagesStart(fromId: "", count: 50, searchDirection: AgoraChatMessageSearchDirection.init(rawValue: 0)!) ?? [] + for message in messages { + if message.body.type == .image { + self.messages.append(message) + } + } + } + + override func viewDidLoad() { + super.viewDidLoad() + self.view.addSubViews([self.messagesList,self.sendImage]) + AgoraChatClient.shared().add(self, delegateQueue: .main) + AgoraChatClient.shared().chatManager?.add(self, delegateQueue: .main) + // Do any additional setup after loading the view. + } + + deinit { + AgoraChatClient.shared().removeDelegate(self) + AgoraChatClient.shared().chatManager?.remove(self) + NotificationCenter.default.removeObserver(self) + } + + + +} + + +//MARK: - Private method +extension AgoraChatSendVideoController { + + @objc private func sendImageAction() { + PHPhotoLibrary.requestAuthorization { status in + switch status { + case .notDetermined,.restricted,.denied: + ProgressHUD.showError("Access to the album is not authorized") + case .limited,.authorized: self.openAlbum() + @unknown default: + fatalError() + } + } + + } + + private func openAlbum() { + DispatchQueue.main.async { + self.imagePicker.sourceType = .photoLibrary + self.imagePicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)! + self.present(self.imagePicker, animated: true, completion: nil) + } + } + + //MARK: - UIImagePickerControllerDelegate + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { + guard let type = info[.mediaType] as? String else { + picker.dismiss(animated: true) + return + } +// let assert = AVURLAsset.init(url: url) +// +// let tracks = assert.tracks(withMediaType: .video) + + if !type.hasSuffix("image") || type.hasSuffix("movie") { +// NSURL *videoURL = info[UIImagePickerControllerMediaURL]; +// // we will convert it to mp4 format +// NSURL *mp4 = [self _videoConvert2Mp4:videoURL]; +// NSFileManager *fileman = [NSFileManager defaultManager]; +// if ([fileman fileExistsAtPath:videoURL.path]) { +// NSError *error = nil; +// [fileman removeItemAtURL:videoURL error:&error]; +// if (error) { +// NSLog(@"failed to remove file, error:%@.", error); +// } +// } + guard let url = info[.mediaURL] as? URL else { + return + } + } else { + + } + picker.dismiss(animated: true) + } + + //MARK: - UITableViewDelegate&UITableViewDataSource + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + 110 + } + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + self.messages.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let message: AgoraChatMessage = self.messages[safe: indexPath.row]! + var cell = tableView.dequeueReusableCell(withIdentifier: "AgoraChatImageCell") as? AgoraChatImageCell + if cell == nil { + cell = AgoraChatImageCell(style: .subtitle, reuseIdentifier: "AgoraChatImageCell") + } + cell?.updateLayout(message: message) + return cell! + } + + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + tableView.deselectRow(at: indexPath, animated: true) + } + + //MARK: - AgoraChatManagerDelegate + func messagesDidReceive(_ aMessages: [AgoraChatMessage]) { + self.messages.append(contentsOf: aMessages) + DispatchQueue.main.async { + self.messagesList.reloadData() + self.messagesList.scrollToRow(at: IndexPath(row: self.messages.count - 1, section: 0), at: .bottom, animated: true) + } + } +// - (NSURL *)_videoConvert2Mp4:(NSURL *)movUrl +// { +// NSURL *mp4Url = nil; +// AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:movUrl options:nil]; +// NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset]; +// +// if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality]) { +// AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetHighestQuality]; +// NSString *mp4Path = [NSString stringWithFormat:@"%@/%d%d.mp4", [self getAudioOrVideoPath], (int)[[NSDate date] timeIntervalSince1970], arc4random() % 100000]; +// mp4Url = [NSURL fileURLWithPath:mp4Path]; +// exportSession.outputURL = mp4Url; +// exportSession.shouldOptimizeForNetworkUse = YES; +// exportSession.outputFileType = AVFileTypeMPEG4; +// dispatch_semaphore_t wait = dispatch_semaphore_create(0l); +// [exportSession exportAsynchronouslyWithCompletionHandler:^{ +// switch ([exportSession status]) { +// case AVAssetExportSessionStatusFailed: { +// NSLog(@"failed, error:%@.", exportSession.error); +// } break; +// case AVAssetExportSessionStatusCancelled: { +// NSLog(@"cancelled."); +// } break; +// case AVAssetExportSessionStatusCompleted: { +// NSLog(@"completed."); +// } break; +// default: { +// NSLog(@"others."); +// } break; +// } +// dispatch_semaphore_signal(wait); +// }]; +// long timeout = dispatch_semaphore_wait(wait, DISPATCH_TIME_FOREVER); +// if (timeout) { +// NSLog(@"timeout."); +// } +// +// if (wait) { +// //dispatch_release(wait); +// wait = nil; +// } +// } +// +// return mp4Url; +// } + func convertVideoType() -> String { + "" + } + + func videoPath() -> String { + let path = String.cachesPath + "AgoraChatApiExampleVideo" + if !FileManager.default.fileExists(atPath: path) { + do { + try FileManager.default.createDirectory(at: URL(string: path)!, withIntermediateDirectories: true) + } catch { + assert(false,"\(error.localizedDescription)") + } + } + return path + } +} diff --git a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Info.plist b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Info.plist index 46eb0f2..e8f91c6 100644 --- a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Info.plist +++ b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Info.plist @@ -2,8 +2,6 @@ - NSPhotoLibraryUsageDescription - using send image NSAppTransportSecurity NSAllowsArbitraryLoads diff --git a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Utils/AgoraChatRequest.swift b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Utils/AgoraChatRequest.swift index 0580e58..af4981f 100644 --- a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Utils/AgoraChatRequest.swift +++ b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Utils/AgoraChatRequest.swift @@ -41,9 +41,9 @@ final class AgoraChatRequest: NSObject,URLSessionDelegate { static var shared = AgoraChatRequest.init() - static let baseUrl = "https://a41.chat.agora.io" - - static let appKey = "41117440#383391" + static let baseUrl: String = "https://a41-appserver.chat.agora.io" + + static let appID: String = <#App Id#> private lazy var config: URLSessionConfiguration = { //MARK: - session config diff --git a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Podfile b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Podfile index 9a857af..a7622d2 100644 --- a/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Podfile +++ b/Chat-iOS/AgoraChatAPIExample-Swift/AgoraChatAPIExample-Swift/Podfile @@ -1,12 +1,12 @@ # Uncomment the next line to define a global platform for your project -# platform :ios, '11.0' +platform :ios, '11.0' source 'https://github.com/CocoaPods/Specs.git' target 'AgoraChatAPIExample-Swift' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! - pod 'Agora_Chat_iOS','1.0.6' + pod 'Agora_Chat_iOS','1.4.0' pod 'ZSwiftBaseLib','0.1.4' pod 'ProgressHUD' end diff --git a/Chat-iOS/AgoraChatAPIExample/AgoraChatAPIExample.xcodeproj/project.pbxproj b/Chat-iOS/AgoraChatAPIExample/AgoraChatAPIExample.xcodeproj/project.pbxproj index d6028af..9972857 100644 --- a/Chat-iOS/AgoraChatAPIExample/AgoraChatAPIExample.xcodeproj/project.pbxproj +++ b/Chat-iOS/AgoraChatAPIExample/AgoraChatAPIExample.xcodeproj/project.pbxproj @@ -70,8 +70,8 @@ 9ECC4D692812AE00001CEDCB /* AudioMessageViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioMessageViewController.m; sourceTree = ""; }; 9ECC4D6A2812AE00001CEDCB /* AgoraAudioRecordUtil.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AgoraAudioRecordUtil.mm; sourceTree = ""; }; 9ECC4D6B2812AE00001CEDCB /* AgoraAudioRecordUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AgoraAudioRecordUtil.h; sourceTree = ""; }; - A34036BDBC86A15EF71C06B7 /* Pods-AgoraChatAPIExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AgoraChatAPIExample.debug.xcconfig"; path = "Target Support Files/Pods-AgoraChatAPIExample/Pods-AgoraChatAPIExample.debug.xcconfig"; sourceTree = ""; }; - AC7BDDB8214D58990E78D8A3 /* Pods-AgoraChatAPIExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AgoraChatAPIExample.release.xcconfig"; path = "Target Support Files/Pods-AgoraChatAPIExample/Pods-AgoraChatAPIExample.release.xcconfig"; sourceTree = ""; }; + A34036BDBC86A15EF71C06B7 /* Pods-AgoraChatAPIExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AgoraChatAPIExample.debug.xcconfig"; path = "../AgoraChatAPIExample/Pods/Target Support Files/Pods-AgoraChatAPIExample/Pods-AgoraChatAPIExample.debug.xcconfig"; sourceTree = ""; }; + AC7BDDB8214D58990E78D8A3 /* Pods-AgoraChatAPIExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AgoraChatAPIExample.release.xcconfig"; path = "../AgoraChatAPIExample/Pods/Target Support Files/Pods-AgoraChatAPIExample/Pods-AgoraChatAPIExample.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ diff --git a/Chat-iOS/ChatQuickStart/ChatQuickStart.xcodeproj/project.pbxproj b/Chat-iOS/ChatQuickStart/ChatQuickStart.xcodeproj/project.pbxproj index 329d60b..9e9fa81 100644 --- a/Chat-iOS/ChatQuickStart/ChatQuickStart.xcodeproj/project.pbxproj +++ b/Chat-iOS/ChatQuickStart/ChatQuickStart.xcodeproj/project.pbxproj @@ -295,7 +295,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = 499WYUV8Q2; + DEVELOPMENT_TEAM = JC854K845H; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = ChatQuickStart/Info.plist; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; @@ -324,7 +324,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = 499WYUV8Q2; + DEVELOPMENT_TEAM = JC854K845H; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = ChatQuickStart/Info.plist; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; @@ -375,7 +375,7 @@ repositoryURL = "https://github.com/AgoraIO/AgoraChat_iOS"; requirement = { kind = exactVersion; - version = 1.3.1; + version = 1.4.0; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/Chat-iOS/ChatQuickStart/ChatQuickStart.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Chat-iOS/ChatQuickStart/ChatQuickStart.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index eae8c16..79dac8c 100644 --- a/Chat-iOS/ChatQuickStart/ChatQuickStart.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Chat-iOS/ChatQuickStart/ChatQuickStart.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,17 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/AgoraIO/AgoraChat_iOS", "state" : { - "revision" : "0060fe02b24b6b99cb115c8520f9858f00f56c0e", - "version" : "1.3.1" + "revision" : "fafa4833ed87f676d92b2c00ff486376ec679246", + "version" : "1.4.0" + } + }, + { + "identity" : "agorainfra_ios", + "kind" : "remoteSourceControl", + "location" : "https://github.com/AgoraIO/AgoraInfra_iOS.git", + "state" : { + "revision" : "1efd68dbd67bd464e35e799dd3779fa1c6a114c6", + "version" : "1.3.9" } } ], diff --git a/Chat-iOS/ChatQuickStart/ChatQuickStart/ViewController.swift b/Chat-iOS/ChatQuickStart/ChatQuickStart/ViewController.swift index 46d3a3a..813ea29 100644 --- a/Chat-iOS/ChatQuickStart/ChatQuickStart/ViewController.swift +++ b/Chat-iOS/ChatQuickStart/ChatQuickStart/ViewController.swift @@ -53,8 +53,6 @@ class ViewController: UIViewController { logView = createLogView() self.view.addSubview(logView) // Input userId and token which generated on console - self.userIdField.text = <#Input Your UserId#> - self.tokenField.text = <#Input Your Token#> } override func viewDidLayoutSubviews() { @@ -73,7 +71,7 @@ class ViewController: UIViewController { func initChatSDK() { // Initializes the Agora Chat SDK - let options = AgoraChatOptions(appkey: <#Agora App Key#>) + let options = AgoraChatOptions(appId: <#app id#>) options.isAutoLogin = false // disable auto login options.enableConsoleLog = true AgoraChatClient.shared.initializeSDK(with: options)