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: 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
Marigold class
// Clear Device
try await Marigold().clearDeviceData(for: .events)
// Device ID
let deviceId = try await Marigold().deviceId()
// Geo IP
try await Marigold().set(geoIpTrackingEnabled: false)
// Development
#if DEBUG
try await Marigold().setDevelopmentDevice()
#endif
EngageBySailthru class
// Set Attributes
let attributes = MARAttributes()
try await EngageBySailthru().set(attributes: attributes)
// Remove Attribute
try await EngageBySailthru().removeAttribute(with: "my_attribute")
// Device ID
let deviceId = try await Marigold().deviceId()
// Set User ID
try await EngageBySailthru().set(userId: "123456")
// Set User Email
try await EngageBySailthru().set(userEmail: "[email protected]")
// Tracking
try await EngageBySailthru().trackPageview(with: URL(string: "some-site.com/page")!, tags: [ "interesting-thing1", "interesting-thing2" ])
try await EngageBySailthru().trackImpression(with: "section-id", urls: [ URL(string: "some-site.com/page1")!, URL(string: "some-site.com/page2")!])
try await EngageBySailthru().trackClick(with: "section-id", url: URL(string: "some-site.com/page2")!)
// Profile Vars
try await EngageBySailthru().set(profileVars: [ "varKey": "varVal" ])
let profileVars = try await EngageBySailthru().profileVars()
// Purchases
let purchaseItems = [
MARPurchaseItem(quantity: 1, title: "thing", price: 2, itemId: "item1", itemUrl: URL(string: "some-site.com/item1")!)!
]
let purchase = MARPurchase(purchaseItems: purchaseItems)!
try await EngageBySailthru().log(purchase: purchase)
try await EngageBySailthru().log(abandonedCart: purchase)
MARMessageStream
// Unread Count
let unreadCount = try await MARMessageStream().unreadCount()
// Mark as Read
let message = MARMessage()
try await MARMessageStream().mark(asRead: message)
try await MARMessageStream().mark(asRead: [message])
// Message List
let messages = try await MARMessageStream().messages()
// Remove Message
let message = MARMessage()
try await MARMessageStream().remove(message: message)
Updated 11 months ago