copyright 2015-16, Stand Alone, Inc. & Ben Gottlieb
Instructions for Use:
- Download the project and build the "Combined Framework" target
- This will generate a ConversationKit.framework
- Add ConversationKit.framework to your project, and make sure it's copied to your bundle at build time (this may require adding a Run Script step to your Build Phases in your target. See the Test Harness target in the project for an example)
- On the Apple Developer Portal, ensure that you've got iCloud support with CloudKit (check the "Include CloudKit support (requires Xcode 6)" checkbox)
- In your app's Capabilities pane in Xcode…
- Turn on "iCloud" and check the "CloudKit" checkbox (use default container is already selected)
- Turn on "Background Modes" and check the "Remote Notifications" checkbox
- In your app delegate add
ConversationKit.configureNotifications(_:)
to yourapplicationDidFinishLaunching(…)
method - Add an
application(application,didReceiveRemoteNotification,fetchCompletionHandler)
method, and call the same method onConversationKit
- If you want the user to be able to reply to message notifications from outside the application, add an
application(application,handleActionWithIdentifier,forLocalNotification,withResponseInfo,completionHandler)
method, and call the same method onConversationKit
- Finally, call
ConversationKit.setupLocalSpeaker()
with an identifier for the local user.
You're now set up. You can easily add a ConversationView
to a view controller, set its conversation
property, and you'll receive messages as they come in.
ConversationKit caches all data in a local CoreData database (stored in ~/Library/Caches/Conversations.db by default). It also caches all images (from avatars) in ~/Library/Caches/Images.
There is a ConversationKit object at the center of most of your interactions with ConversationKit. It's accessed via ConversationKit.instance
.
Properties:
feedbackLevel
an enum controlling how much feedback you get when calling ConversationKit methods. Set to either.Development
,.Testing
, or.Production
showNetworkActivityIndicatorBlock
a closure that takes a single Bool, whether to show the Activity Indicator in the status bar. By default, it merely toggles it on and off, but youcan set a custom block to integrate with other Activity Indicator controlscloudAvailable
is CloudKit available (the user may be signed in or not)
Methods:
configureNotifications(…)
is called fromdidFinishLaunching(…)
to request permission to show notificationsapplication(application,didReceiveRemoteNotification,fetchCompletionHandler)
called from the identically named Application Delegate method to process incoming notificationsfetchAccountIdentifier(…)
takes a completion block which will be passed the user's CloudKit account identifier.setup(containerName,completion)
called before accessing most other ConversationKit methods. The containerName is optional, and the completion block will be called with a Bool indicating successsetupLocalSpeaker(identifier, completion)
changes the identity of the local speaker. Called whenever the identity of the local speaker changes (new iCloud login, new GameCenter ID, etc). Calling with the existing identitfier does nothing. If necessary, will callclearAllCachedDataWithCompletion()
clearAllCachedDataWithCompletion(…)
clears out the CoreData cache and all in-memory caches.
This object represents a user of the app, either the local user (Speaker.localSpeaker
) or whomever they're speaking to.
Speakers have the following properties:
name
The user visible name that is shown to other speakersidentifier
a unique string. Frequently their CloudKit account identifier (can be found usingConversationKit.fetchAccountIdentifier()
) or their GameCenter identifiertags
an array of strings that can be used to search for users using theSpeakerQuery
objectisLocalSpeaker
a boolean indicating whether this is the local device user's speakeravatarImage
a UIImage representing the speaker and shown to other usersavatarImageLocalURL
a file URL pointing to the user's avatar imagespeakerRef
a string representation of the user which can be stored and passed back to theSpeaker.speakerFromSpeakerRef
method
A few useful methods:
sendMessage(content, completion)
send the user a message
There are also a few class methods and vars on the Speaker object:
allKnownSpeakers
an array of Speakers representing all speakers the local speaker has either had a conversation with or found via aSpeakerQuery
searchmaxImageSize
a CGSize that all avatarImages will be capped to. Defaults to 100x100
Speakers are cached in the CoreData database as Speaker objects, and stored in CloudKit as ConversationKitSpeaker records.
A message represents a single message from one Speaker to another.
Properties:
content
a string containing the message textspeaker
aSpeaker
, who said itlistender
aSpeaker
, who it was said tospokenAt
an NSDate, when it was spokenconversation
aConversation
object (see below) representing allMessage
s between these twoSpeaker
s
Messages are cached in the CoreData database as Message objects, and stored in CloudKit as ConversationKitMessage records.
A Conversation
contains all Message
s between two Speaker
s.
startedBy
theSpeaker
that initiated the conversationjoinedBy
aSpeaker
, the other side of the conversation-
sortedMessages
a chronologically ordered list ofMessage
s -
nonLocalSpeaker
whichever member of the conversation is NOT the localSpeaker
Class methods:
existing(with: Speaker)
looks up and returns an existing conversation between the local speaker and the passed in oneconversationWith(Soeaker)
looks up existing and creates a new one if needed