iOS: Swift Concurrency

How to use the iOS SDK with Swift Concurrency

If you would like to adopt Swift Concurrency in your app, this is possible through the use of our Swift Concurrency wrapper SDK:

The wrapper is available through Swift Package Manager and allows all the iOS SDK asynchronous functionality to be accessed using async/await. Any errors that occur while completing the operations will be thrown and can be caught and handled as appropriate by your app.



// Set Attributes
let attributes = STMAttributes()
try await SailthruMobile().set(attributes: attributes)

// Remove Attribute
try await SailthruMobile().removeAttribute(with: "my_attribute")

// Clear Device
try await SailthruMobile().clearDeviceData(for: .attributes)

// Device ID
let deviceId = try await SailthruMobile().deviceId()

// Set User ID
try await SailthruMobile().set(userId: "123456")

// Set User Email
try await SailthruMobile().set(userEmail: "[email protected]")

// Recommendations
let recommendations = try await SailthruMobile().recommendations(with: "section-id")

// Tracking
try await SailthruMobile().trackPageview(with: URL(string: "")!, tags: [ "interesting-thing1", "interesting-thing2" ])

try await SailthruMobile().trackImpression(with: "section-id", urls: [ URL(string: "")!, URL(string: "")!])

try await SailthruMobile().trackClick(with: "section-id", url: URL(string: "")!)

// Profile Vars
try await SailthruMobile().set(profileVars: [ "varKey": "varVal" ])

let profileVars = try await SailthruMobile().profileVars()

// Geo IP
try await SailthruMobile().set(geoIpTrackingEnabled: false)

// Purchases
let purchaseItems = [
  STMPurchaseItem(quantity: 1, title: "thing", price: 2, itemId: "item1", itemUrl: URL(string: "")!)!
let purchase = STMPurchase(purchaseItems: purchaseItems)!

try await SailthruMobile().log(purchase: purchase)

try await SailthruMobile().log(abandonedCart: purchase)

// Development
try await SailthruMobile().setDevelopmentDevice()


// Unread Count
let unreadCount = try await STMMessageStream().unreadCount()

// Mark as Read
let message = STMMessage()
try await STMMessageStream().mark(asRead: message)

try await STMMessageStream().mark(asRead: [message])

// Message List
let messages = try await STMMessageStream().messages()

// Remove Message
let message = STMMessage()
try await STMMessageStream().remove(message: message)