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: https://github.com/sailthru/sailthru-mobile-ios-sdk-swift 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.

Examples

Note: All examples are in Swift.

SailthruMobile

// 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: "123456@some-site.com")


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


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

try await SailthruMobile().trackImpression(with: "section-id", urls: [ URL(string: "some-site.com/page1")!, URL(string: "some-site.com/page2")!])

try await SailthruMobile().trackClick(with: "section-id", url: URL(string: "some-site.com/page2")!)


// 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: "some-site.com/item1")!)!
]
let purchase = STMPurchase(purchaseItems: purchaseItems)!

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

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

// Development
#if DEBUG
try await SailthruMobile().setDevelopmentDevice()
#endif

STMMessageStream

// 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)

Contact us

Top