Developed in Swift, the Web3MQ SDK for iOS Swift provides a modern way of implementing Web3MQ APIs. The features included in this SDK will help you develop an iOS app with engaging and personalized user experience.
For more information, refer to the Web3MQ SDK Docs.
- Uses
UIKitpatterns and paradigms: The API follows the design of native system SDKs. It makes integration with your existing code easy and familiar. - First-class support for
CombineandConcurrency - Swift native API: Uses Swift's powerful language features to make the SDK usage easy and type-safe.
before you run your project, make sure that your development environment is provided with:
- Xcode 11
- iOS 13.0 or later
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
Once you have your Swift package set up, adding Web3MQSDK as a dependency is as easy as adding it to the dependencies value of your Package.swift.
dependencies: [
.package(url: "git@github.com:Generative-Labs/Web3MQ-SDK-Swift.git", .upToNextMajor(from: "0.1.0"))
]Let's get started by initializing the client:
import Web3MQ
// the SDK will find the endpoint with lowest latency for you
ChatClient.default.setup(with: Configuration(appKey: "{AppKey}"))
// or you prefer to set a specific endpoint
ChatClient.default.setup(with: Configuration(appKey: "{AppKey}", endpoint: Endpoint.Dev.jp1))For any first-time user of Web3MQ's network, you'll need to register on Web3MQ's network. SDK takes care of the key generation process and subsequent wallet signing process. ChatClient.default.connectWithMateMask is a utility method that does this automatically.
// Keep your private key in a safe place!
let (keyPair, userId) = await ChatClient.default.connectWithMateMask()SDK will save the KeyPair in Keychain by default, you could disable it by setting keychainStore false
let (keyPair, userId) = await ChatClient.default.connectWithMateMask(keychainStore: false)If there is a key-pair in keychain, it will automatically connect to that user.
ChatClient.default.autoConnect()You could also connect manually.
ChatClient.default.connect(with: KeyPair(privateKey: "{PrivateKey}", publicKey: "{PublicKey}"), userId: "{UserId}")If you want to react instantly with the connecting status updating, just subscribe this publisher: ChatClient.default.connectingStatusPublisher
let status: Web3MQConnectingStatus = ChatClient.default.connectingStatus
public enum Web3MQConnectingStatus {
case idle
// the SDK will always try to reconnect the Web3MQ network, so you don't need
// to care about that part.
case connecting
case connected(nodeId: String)
// only when you disconnect manually
case disconnected
case error(_ error: Error?)
}Let’s continue by initializing your first channel. A channel contains messages, a list of members that are watching the channel. The example below shows how to set up a channel to support chat for a group conversation:
let channelId: String = await ChatClient.default.channelManager.createChannel(name: "{channel_name}") Now that we have the channel set up, let's send our first chat message:
send a message to a user or a channel
// sessionId: userId or channelId
ChatClient.default.messageManager.sendMessage("{Text}", topicId: "{TopicId}") async throwssubscribe the messagePublisher to receive messages.
ChatClient.default.messageManager.messagePublisherThe notification is also a specific message. Just subscribe the notificationPublisher to receive notifications.
ChatClient.default.notificationManager.notificationPublisher