Reputation: 1730
I'm trying to use the SendBird SDK to implement a simple instant messaging feature in my iOS app.
I've read the Quick Start, Authentication, and Messaging Channel - Basic guides, and I've attempted to set up a 1-1 messaging channel as they describe.
In application:didFinishLaunchingWithOptions
I included SendBird.initAppId("MyAppID")
.
In my initial view controller, I log in the user. I'm using the user's username from my app as his userId, and I'm concatenating his first and last name to use as his SendBird nickname:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if let emailAddress = KCSUser.activeUser().email,
firstName = KCSUser.activeUser().givenName,
lastName = KCSUser.activeUser().surname {
let nickname = firstName.lowercaseString + lastName.lowercaseString
SendBird.loginWithUserId(emailAddress, andUserName: nickname)
}
}
Finally, in the actual chat view controller, I attempt to start a messaging channel with another user:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
guard let targetId = session?.parent?.user?.email else {
return
}
// I logged in once with this id, so according to the SendBird docs, the
// user should exist.
SendBird.startMessagingWithUserId(targetId)
SendBird.setEventHandlerConnectBlock({ (channel) in
NSLog("%@", channel)
}, errorBlock: { (errorCode) in
NSLog("%D", errorCode)
}, channelLeftBlock: { (channel) in
}, messageReceivedBlock: { (message) in
}, systemMessageReceivedBlock: { (systemMessage) in
}, broadcastMessageReceivedBlock: { (broadcastMessage) in
}, fileReceivedBlock: { (fileLink) in
}, messagingStartedBlock: { (messagingChannel) in
SendBird.joinChannel(messagingChannel.getUrl())
// SendBirdChannelInfo is a custom struct for some use within the app
let channelInfo = SendBirdChannelInfo(
channelId: messagingChannel.getId(),
url: messagingChannel.getUrl()
)
// self.session is a custom data model for use with our database.
self.session?.sendBirdChannelInfo = channelInfo
SendBird.queryMessageListInChannel(messagingChannel.getUrl()).prevWithMessageTs(
Int64.max, andLimit: 30, resultBlock: { (queryResult) in
var maxMessageTs = Int64.min
for model in queryResult {
if maxMessageTs <= (model as! SendBirdMessageModel).getMessageTimestamp() {
maxMessageTs = (model as! SendBirdMessageModel).getMessageTimestamp()
}
}
SendBird.connectWithMessageTs(maxMessageTs)
}, endBlock: { (error) in
if let fetchMessagesError = error {
NSLog(fetchMessagesError.localizedDescription)
}
})
}, messagingUpdatedBlock: { (messagingChannel) in
}, messagingEndedBlock: { (messagingChannel) in
}, allMessagingEndedBlock: {
}, messagingHiddenBlock: { (messagingChannel) in
}, allMessagingHiddenBlock: {
}, readReceivedBlock: { (readStatus) in
}, typeStartReceivedBlock: { (typeStatus) in
}, typeEndReceivedBlock: { (typeStatus) in
}, allDataReceivedBlock: { (unsignedInt, thirtyTwoBitInt) in
}, messageDeliveryBlock: { (sent, message, data, messageId) in
}, mutedMessagesReceivedBlock: { (message) in
}) { (fileLink) in
}
}
With the exception of the lines I commented, this code comes directly from the SendBird manual. However, when it runs, I receive error code 14000, and the message, "Fail to start messaging," is logged.
What is the actual cause of the error? Am I missing a step during user login or SDK initialization, or is there another step in creating a channel? Or is it something else entirely?
Upvotes: 1
Views: 572
Reputation: 196
Please try our new SDK instead of the old SDK which will be deprecated soon!
Thanks!
Upvotes: 1