AppFriendsUI is an open source library which provides customizable UI components and example usage of AppFriends. It's a great starting point to build an app using AppFriends. It can save you a lot of development hours. Besides UI components, this library also provides convenient methods for you to handles dialogs, send/receive messages and query for users. It uses CoreData to store dialogs and
You can checkout how to use this SDK together with the AppFriendsCore SDK by running the AFChatUISample app included in this repo.
To integrate AppFriends iOS SDK to your Xcode iOS project, add this line in your Podfile
pod 'AppFriendsUI'
Also, add use_frameworks!
to the file. eg.
platform :ios, "8.0"
use_frameworks!
...
After installation, the first thing you need to do is initializing the SDK. Look for AppFriendsUI
, then invoke:
public func initialize(completion: ((success: Bool, error: NSError?) -> ())? = nil)
You need to do this after you initialize the AppFriendsCore
library
Then you need to login the user by using AppFriendsCore
. After login is successful, you can start using all the components of AppFriendsUI
AppFriendsUI
has a HCChatContainerViewController
which contains a dialog list view, a friends list view and chat view. This is the easiest way to use AppFriends. You can use it by calling:
let chatContainer = HCChatContainerViewController(tabs:HCTitles.dialogsTabTitle, HCTitles.contactsTabTitle])
let nav = UINavigationController(rootViewController: chatContainer)
nav.navigationBar.tintColor = UIColor.whiteColor()
self.presentVC(nav)
HCDialogsListViewController
is a class to help you display your dialogs list.
HCBaseChatViewController
or HCDialogChatViewController
is a class you can use to display a chat UI. It provides basic chat UI.
You can send typing events with startTyping and endTyping. If you use the chat view provided by this library, type indicator is provided for you automatically, so you don't have to write any additional code.
DialogsManager.sharedInstance.startTyping(_dialogID, dialogType: _dialogType)
DialogsManager.sharedInstance.endTyping(_dialogID, dialogType: _dialogType)
AppFriendsUI
offers a convenient UI for you to search for users. To use this UI, you can either directly use HCUserSearchViewController
or create its sub class.
Sometimes, you may not wish to leave the current screen to show the chat. With AppFriendsUI
, you can achieve this very easily by using a side panel.
// use this code in one of your view controller
AppFriendsUI.sharedInstance.presentVCInSidePanel(fromVC: self, showVC: channelChatVC, direction: .Left)
AppFriendsUI
customization can be done through HCUIConfiguration
. You can change the color, font, and text. Example:
HCColorPalette.chatBackgroundColor = UIColor(hexString: "0d0e28")
HCColorPalette.SegmentSelectorOnBgColor = UIColor(hexString: "3c3a60")
If more advanced customizations are needed, you can sub class components of AppFriendsUI.
When you want to switch user, don't forget to log out the user by
AppFriendsUI.sharedInstance.logout()