Webex Messaging
Webex Messaging
Quickstart
This article provides examples of common methods used in the meetings flow for the iOS Messaging SDK. For detailed method parameters, refer to the SDK API Reference.
The Webex
instance is the core access point for the SDK, providing access to all Webex SDK methods.
anchorCreate a New Webex Space
anchorTo create a new Webex space:
webex.spaces.create(title: "Hello World") { result in
switch result {
case .success(let space):
// ...
case .failure(let error):
// ...
}
}
anchorAdd a User to a Space
anchorTo add a user to a space:
webex.memberships.create(spaceId: spaceId, personEmail: email) { result in
switch result {
case .success(let membership):
// Handle success
print("Membership created: \(membership)")
case .failure(let error):
// Handle failure
print("Error creating membership: \(error)")
}
}
}
Post a Message in a Space
To post a message in the space:
webex.messages.post(roomId: "spaceId", text: Message.Text.plain(plain: "hello world")){ response in
switch result {
case .success(let message):
// ...
case .failure(let error):
// ...
}
}
}
anchorPost a Message with an Attachment
anchorTo post a message to a space with an attachment:
let text = Message.Text.html(html: html)
let thumbnail = LocalFile.Thumbnail(path: thumbnailFilePath, mime: fileType, width: Int(image.size.width), height: Int(image.size.height))
let localFile = LocalFile(path: filePath, name: fileName, mime: fileType, thumbnail: thumbnail, progressHandler: { progress in
// Implement progress bar
})
webex.messages.post(text, toSpace: spaceId, withFiles: localFiles, completionHandler: { response in
switch response.result {
case .success(let message):
// ...
case .failure(let error):
// ...
}
}
anchorIntercept Messaging Events
anchorTo intercept messaging events:
webex.messages.onEvent = { messageEvent in
switch messageEvent{
case .messageReceived(let message):
// ...
case .messageDeleted(let messageId):
// ...
}
}
anchorManage the Background Connection
anchorTo maintain a websocket connection in the background (allowing background syncing of messages):
webex.phone.enableBackgroundConnection = true
anchorEnable or Disable Console Logging
anchorTo enable/disable console login:
webex.enableConsoleLogger = true
anchorCheck Feature Entitlements for a Logged-In User
anchorTo determine what entitlements a particular logged-in user has:
let capability: ProductCapability = webex.people.getProductCapability()
let hasCalling = capability.isCallingSupported
let hasMeeting = capability.isMeetingSupported
let hasMessaging = capability.isMessagingSupported