From bc910e8f7cbbd82711eb980dc03b788b5a374dd9 Mon Sep 17 00:00:00 2001 From: Johnny Date: Tue, 11 Apr 2017 14:16:44 -0700 Subject: [PATCH 1/2] project setup --- .gitignore | 67 +++++++++++++++++++ .../SendBird-iOS.xcodeproj/project.pbxproj | 4 +- sample-swift/SendBird-iOS/AppDelegate.swift | 2 +- 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9573f0c --- /dev/null +++ b/.gitignore @@ -0,0 +1,67 @@ +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +.DS_Store + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xcuserstate + +## Obj-C/Swift specific +*.hmap +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +.build/ + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# Pods/ + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output diff --git a/sample-swift/SendBird-iOS.xcodeproj/project.pbxproj b/sample-swift/SendBird-iOS.xcodeproj/project.pbxproj index 9049586..cf95aef 100644 --- a/sample-swift/SendBird-iOS.xcodeproj/project.pbxproj +++ b/sample-swift/SendBird-iOS.xcodeproj/project.pbxproj @@ -409,7 +409,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0800; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0830; ORGANIZATIONNAME = SendBird; TargetAttributes = { 5ABA0B7C1DA6010A000C82DC = { @@ -817,7 +817,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.sendbird.sample; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; }; name = Release; diff --git a/sample-swift/SendBird-iOS/AppDelegate.swift b/sample-swift/SendBird-iOS/AppDelegate.swift index 4715515..7bec3ae 100644 --- a/sample-swift/SendBird-iOS/AppDelegate.swift +++ b/sample-swift/SendBird-iOS/AppDelegate.swift @@ -35,7 +35,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { application.applicationIconBadgeNumber = 0 - SBDMain.initWithApplicationId("9DA1B1F4-0BE6-4DA8-82C5-2E81DAB56F23") + SBDMain.initWithApplicationId("1B0C2F67-9D82-49DD-8DA8-FF067E6C4259") SBDMain.setLogLevel(SBDLogLevel.debug) SBDOptions.setUseMemberAsMessageSender(true) From 36c4e46c00a29741bff29da442745527be35f1ff Mon Sep 17 00:00:00 2001 From: Johnny Date: Tue, 11 Apr 2017 15:07:32 -0700 Subject: [PATCH 2/2] subclass group chat view, some walkthrough comments --- .../SendBird-iOS.xcodeproj/project.pbxproj | 10 ++- .../GroupChannelChattingViewController.swift | 77 +---------------- .../GroupChannelChattingViewController.xib | 6 +- .../GroupChannelListViewController.swift | 4 +- .../GroupChannel/SnapChatViewController.swift | 86 +++++++++++++++++++ .../OpenChannelChattingViewController.swift | 4 +- 6 files changed, 103 insertions(+), 84 deletions(-) create mode 100644 sample-swift/SendBird-iOS/GroupChannel/SnapChatViewController.swift diff --git a/sample-swift/SendBird-iOS.xcodeproj/project.pbxproj b/sample-swift/SendBird-iOS.xcodeproj/project.pbxproj index cf95aef..61bbb9c 100644 --- a/sample-swift/SendBird-iOS.xcodeproj/project.pbxproj +++ b/sample-swift/SendBird-iOS.xcodeproj/project.pbxproj @@ -73,6 +73,7 @@ 5ADEF82A1DAA663C000AABF9 /* CreateGroupChannelUserListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ADEF8291DAA663C000AABF9 /* CreateGroupChannelUserListTableViewCell.swift */; }; 5ADEF82C1DAA67C5000AABF9 /* GroupChannelListEditableTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ADEF82B1DAA67C5000AABF9 /* GroupChannelListEditableTableViewCell.swift */; }; 8F4B9B4CF66474515B5345D2 /* Pods_SendBird_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8F3A2CB679067572774BDE5D /* Pods_SendBird_iOS.framework */; }; + AB7DC7761E9D867300614891 /* SnapChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB7DC7751E9D867300614891 /* SnapChatViewController.swift */; }; CE806EF61E79048200A8CB57 /* IncomingVideoFileMessageTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE806EF41E79048200A8CB57 /* IncomingVideoFileMessageTableViewCell.swift */; }; CE806EF71E79048200A8CB57 /* IncomingVideoFileMessageTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = CE806EF51E79048200A8CB57 /* IncomingVideoFileMessageTableViewCell.xib */; }; CE806EFA1E79049800A8CB57 /* OutgoingVideoFileMessageTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE806EF81E79049800A8CB57 /* OutgoingVideoFileMessageTableViewCell.swift */; }; @@ -163,6 +164,7 @@ 5ADEF82B1DAA67C5000AABF9 /* GroupChannelListEditableTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupChannelListEditableTableViewCell.swift; sourceTree = ""; }; 8F3A2CB679067572774BDE5D /* Pods_SendBird_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SendBird_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 96683C54D2DA7CFBF0C23471 /* Pods-SendBird-iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SendBird-iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-SendBird-iOS/Pods-SendBird-iOS.release.xcconfig"; sourceTree = ""; }; + AB7DC7751E9D867300614891 /* SnapChatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnapChatViewController.swift; sourceTree = ""; }; C879E57358A8287C34B477A5 /* Pods-SendBird-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SendBird-iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SendBird-iOS/Pods-SendBird-iOS.debug.xcconfig"; sourceTree = ""; }; CE806EF41E79048200A8CB57 /* IncomingVideoFileMessageTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = IncomingVideoFileMessageTableViewCell.swift; path = ../../GroupChannel/ViewCell/IncomingVideoFileMessageTableViewCell.swift; sourceTree = ""; }; CE806EF51E79048200A8CB57 /* IncomingVideoFileMessageTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = IncomingVideoFileMessageTableViewCell.xib; path = ../../GroupChannel/ViewCell/IncomingVideoFileMessageTableViewCell.xib; sourceTree = ""; }; @@ -284,6 +286,7 @@ 5ADEF8211DAA617D000AABF9 /* GroupChannelChattingViewController.xib */, 5AD94BA21DAF1A3A00A6CD66 /* MemberListViewController.swift */, 5AC2B6EC1DB61C1500BA4BC7 /* MemberListViewController.xib */, + AB7DC7751E9D867300614891 /* SnapChatViewController.swift */, ); path = GroupChannel; sourceTree = ""; @@ -414,7 +417,7 @@ TargetAttributes = { 5ABA0B7C1DA6010A000C82DC = { CreatedOnToolsVersion = 8.0; - DevelopmentTeam = 8K8M9F9X95; + DevelopmentTeam = 3W8D3S7TCY; ProvisioningStyle = Automatic; }; }; @@ -568,6 +571,7 @@ 5AD94C2C1DB5F74A00A6CD66 /* Bundle+SendBird.swift in Sources */, 5AD94BB91DAF24AD00A6CD66 /* OpenChannelListTableViewCell.swift in Sources */, 5AD94BA11DAB878600A6CD66 /* GroupChannelChattingViewController.swift in Sources */, + AB7DC7761E9D867300614891 /* SnapChatViewController.swift in Sources */, 5ABA0BCC1DA65240000C82DC /* IncomingUserMessageTableViewCell.swift in Sources */, 5AD94BBB1DAF262C00A6CD66 /* ParticipantListTableViewCell.swift in Sources */, 5AD94BC51DAF6FA500A6CD66 /* ParticipantListViewController.swift in Sources */, @@ -794,7 +798,7 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = 8K8M9F9X95; + DEVELOPMENT_TEAM = 3W8D3S7TCY; INFOPLIST_FILE = "SendBird-iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -810,7 +814,7 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = 8K8M9F9X95; + DEVELOPMENT_TEAM = 3W8D3S7TCY; GCC_OPTIMIZATION_LEVEL = s; INFOPLIST_FILE = "SendBird-iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.1; diff --git a/sample-swift/SendBird-iOS/GroupChannel/GroupChannelChattingViewController.swift b/sample-swift/SendBird-iOS/GroupChannel/GroupChannelChattingViewController.swift index 15fcc16..e6df99d 100644 --- a/sample-swift/SendBird-iOS/GroupChannel/GroupChannelChattingViewController.swift +++ b/sample-swift/SendBird-iOS/GroupChannel/GroupChannelChattingViewController.swift @@ -14,7 +14,7 @@ import MobileCoreServices import Photos import NYTPhotoViewer -class GroupChannelChattingViewController: UIViewController, SBDConnectionDelegate, SBDChannelDelegate, ChattingViewDelegate, MessageDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate { +class GroupChannelChattingViewController: UIViewController, SBDConnectionDelegate, ChattingViewDelegate, MessageDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate { var groupChannel: SBDGroupChannel! @IBOutlet weak var chattingView: ChattingView! @@ -25,7 +25,7 @@ class GroupChannelChattingViewController: UIViewController, SBDConnectionDelegat @IBOutlet weak var imageViewerLoadingViewNavItem: UINavigationItem! private var messageQuery: SBDPreviousMessageListQuery! - private var delegateIdentifier: String! + var delegateIdentifier: String! private var hasNext: Bool = true private var refreshInViewDidAppear: Bool = true private var isLoading: Bool = false @@ -72,7 +72,6 @@ class GroupChannelChattingViewController: UIViewController, SBDConnectionDelegat NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow(notification:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil) self.delegateIdentifier = self.description - SBDMain.add(self as SBDChannelDelegate, identifier: self.delegateIdentifier) SBDMain.add(self as SBDConnectionDelegate, identifier: self.delegateIdentifier) self.chattingView.fileAttachButton.addTarget(self, action: #selector(sendFileMessage), for: UIControlEvents.touchUpInside) @@ -119,7 +118,7 @@ class GroupChannelChattingViewController: UIViewController, SBDConnectionDelegat } } - @objc private func close() { + @objc func close() { self.dismiss(animated: false) { } @@ -341,76 +340,6 @@ class GroupChannelChattingViewController: UIViewController, SBDConnectionDelegat } } - // MARK: SBDChannelDelegate - func channel(_ sender: SBDBaseChannel, didReceive message: SBDBaseMessage) { - if sender == self.groupChannel { - self.groupChannel.markAsRead() - - self.chattingView.messages.append(message) - self.chattingView.chattingTableView.reloadData() - DispatchQueue.main.async { - self.chattingView.scrollToBottom(animated: true, force: false) - } - } - } - - func channelDidUpdateReadReceipt(_ sender: SBDGroupChannel) { - if sender == self.groupChannel { - DispatchQueue.main.async { - self.chattingView.chattingTableView.reloadData() - } - } - } - - func channelDidUpdateTypingStatus(_ sender: SBDGroupChannel) { - if sender == self.groupChannel { - if sender.getTypingMembers()?.count == 0 { - self.chattingView.endTypingIndicator() - } - else { - if sender.getTypingMembers()?.count == 1 { - self.chattingView.startTypingIndicator(text: String(format: Bundle.sbLocalizedStringForKey(key: "TypingMessageSingular"), (sender.getTypingMembers()?[0].nickname)!)) - } - else { - self.chattingView.startTypingIndicator(text: Bundle.sbLocalizedStringForKey(key: "TypingMessagePlural")) - } - } - } - } - - func channelWasChanged(_ sender: SBDBaseChannel) { - if sender == self.groupChannel { - DispatchQueue.main.async { - self.navItem.title = String(format: Bundle.sbLocalizedStringForKey(key: "GroupChannelTitle"), self.groupChannel.memberCount) - } - } - } - - func channelWasDeleted(_ channelUrl: String, channelType: SBDChannelType) { - let vc = UIAlertController(title: Bundle.sbLocalizedStringForKey(key: "ChannelDeletedTitle"), message: Bundle.sbLocalizedStringForKey(key: "ChannelDeletedMessage"), preferredStyle: UIAlertControllerStyle.alert) - let closeAction = UIAlertAction(title: Bundle.sbLocalizedStringForKey(key: "CloseButton"), style: UIAlertActionStyle.cancel) { (action) in - self.close() - } - vc.addAction(closeAction) - DispatchQueue.main.async { - self.present(vc, animated: true, completion: nil) - } - } - - func channel(_ sender: SBDBaseChannel, messageWasDeleted messageId: Int64) { - if sender == self.groupChannel { - for message in self.chattingView.messages { - if message.messageId == messageId { - self.chattingView.messages.remove(at: self.chattingView.messages.index(of: message)!) - DispatchQueue.main.async { - self.chattingView.chattingTableView.reloadData() - } - break - } - } - } - } - // MARK: ChattingViewDelegate func loadMoreMessage(view: UIView) { self.loadPreviousMessage(initial: false) diff --git a/sample-swift/SendBird-iOS/GroupChannel/GroupChannelChattingViewController.xib b/sample-swift/SendBird-iOS/GroupChannel/GroupChannelChattingViewController.xib index 35b7857..3d8cf99 100644 --- a/sample-swift/SendBird-iOS/GroupChannel/GroupChannelChattingViewController.xib +++ b/sample-swift/SendBird-iOS/GroupChannel/GroupChannelChattingViewController.xib @@ -1,15 +1,15 @@ - + - + - + diff --git a/sample-swift/SendBird-iOS/GroupChannel/GroupChannelListViewController.swift b/sample-swift/SendBird-iOS/GroupChannel/GroupChannelListViewController.swift index 141edb9..f686eeb 100644 --- a/sample-swift/SendBird-iOS/GroupChannel/GroupChannelListViewController.swift +++ b/sample-swift/SendBird-iOS/GroupChannel/GroupChannelListViewController.swift @@ -193,7 +193,7 @@ class GroupChannelListViewController: UIViewController, UITableViewDelegate, UIT func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: false) if self.editableChannel == false { - let vc = GroupChannelChattingViewController(nibName: "GroupChannelChattingViewController", bundle: Bundle.main) + let vc = SnapChatViewController(nibName: "GroupChannelChattingViewController", bundle: Bundle.main) vc.groupChannel = self.channels[indexPath.row] self.present(vc, animated: false, completion: nil) } @@ -302,7 +302,7 @@ class GroupChannelListViewController: UIViewController, UITableViewDelegate, UIT // MARK: CreateGroupChannelUserListViewControllerDelegate func openGroupChannel(channel: SBDGroupChannel, vc: UIViewController) { DispatchQueue.main.async { - let vc = GroupChannelChattingViewController(nibName: "GroupChannelChattingViewController", bundle: Bundle.main) + let vc = SnapChatViewController(nibName: "GroupChannelChattingViewController", bundle: Bundle.main) vc.groupChannel = channel self.present(vc, animated: false, completion: nil) } diff --git a/sample-swift/SendBird-iOS/GroupChannel/SnapChatViewController.swift b/sample-swift/SendBird-iOS/GroupChannel/SnapChatViewController.swift new file mode 100644 index 0000000..2cf6497 --- /dev/null +++ b/sample-swift/SendBird-iOS/GroupChannel/SnapChatViewController.swift @@ -0,0 +1,86 @@ +import UIKit +import SendBirdSDK + +class SnapChatViewController: GroupChannelChattingViewController, SBDChannelDelegate { + // JC TODO: Create timer to message deletion after a message is read by the recipient + + override func viewDidLoad() { + super.viewDidLoad() + + SBDMain.add(self as SBDChannelDelegate, identifier: self.delegateIdentifier) + } + + // MARK: SBDChannelDelegate + func channel(_ sender: SBDBaseChannel, didReceive message: SBDBaseMessage) { + if sender == self.groupChannel { + self.groupChannel.markAsRead() + + self.chattingView.messages.append(message) + self.chattingView.chattingTableView.reloadData() + DispatchQueue.main.async { + self.chattingView.scrollToBottom(animated: true, force: false) + } + } + } + + func channelDidUpdateReadReceipt(_ sender: SBDGroupChannel) { + if sender == self.groupChannel { + DispatchQueue.main.async { + self.chattingView.chattingTableView.reloadData() + } + } + + // JC TODO: Message read by recipient, start timer to delete message + // To get the last message, use sender.lastMessage + } + + func channelDidUpdateTypingStatus(_ sender: SBDGroupChannel) { + if sender == self.groupChannel { + if sender.getTypingMembers()?.count == 0 { + self.chattingView.endTypingIndicator() + } + else { + if sender.getTypingMembers()?.count == 1 { + self.chattingView.startTypingIndicator(text: String(format: Bundle.sbLocalizedStringForKey(key: "TypingMessageSingular"), (sender.getTypingMembers()?[0].nickname)!)) + } + else { + self.chattingView.startTypingIndicator(text: Bundle.sbLocalizedStringForKey(key: "TypingMessagePlural")) + } + } + } + } + + func channelWasChanged(_ sender: SBDBaseChannel) { + if sender == self.groupChannel { + DispatchQueue.main.async { + self.navItem.title = String(format: Bundle.sbLocalizedStringForKey(key: "GroupChannelTitle"), self.groupChannel.memberCount) + } + } + } + + func channelWasDeleted(_ channelUrl: String, channelType: SBDChannelType) { + let vc = UIAlertController(title: Bundle.sbLocalizedStringForKey(key: "ChannelDeletedTitle"), message: Bundle.sbLocalizedStringForKey(key: "ChannelDeletedMessage"), preferredStyle: UIAlertControllerStyle.alert) + let closeAction = UIAlertAction(title: Bundle.sbLocalizedStringForKey(key: "CloseButton"), style: UIAlertActionStyle.cancel) { (action) in + self.close() + } + vc.addAction(closeAction) + DispatchQueue.main.async { + self.present(vc, animated: true, completion: nil) + } + } + + func channel(_ sender: SBDBaseChannel, messageWasDeleted messageId: Int64) { + if sender == self.groupChannel { + for message in self.chattingView.messages { + if message.messageId == messageId { + self.chattingView.messages.remove(at: self.chattingView.messages.index(of: message)!) + DispatchQueue.main.async { + self.chattingView.chattingTableView.reloadData() + } + break + } + } + } + } + +} diff --git a/sample-swift/SendBird-iOS/OpenChannel/OpenChannelChattingViewController.swift b/sample-swift/SendBird-iOS/OpenChannel/OpenChannelChattingViewController.swift index a2dfb92..82b5bfd 100644 --- a/sample-swift/SendBird-iOS/OpenChannel/OpenChannelChattingViewController.swift +++ b/sample-swift/SendBird-iOS/OpenChannel/OpenChannelChattingViewController.swift @@ -387,7 +387,7 @@ class OpenChannelChattingViewController: UIViewController, SBDConnectionDelegate } DispatchQueue.main.async { - let vc = GroupChannelChattingViewController(nibName: "GroupChannelChattingViewController", bundle: Bundle.main) + let vc = SnapChatViewController(nibName: "GroupChannelChattingViewController", bundle: Bundle.main) vc.groupChannel = channel self.present(vc, animated: false, completion: nil) } @@ -409,7 +409,7 @@ class OpenChannelChattingViewController: UIViewController, SBDConnectionDelegate } DispatchQueue.main.async { - let vc = GroupChannelChattingViewController(nibName: "GroupChannelChattingViewController", bundle: Bundle.main) + let vc = SnapChatViewController(nibName: "GroupChannelChattingViewController", bundle: Bundle.main) vc.groupChannel = channel self.present(vc, animated: false, completion: nil) }