iOS SDK best practice
Mobile application performance is critical to your business. Our technology is focused on improving your customer's experience with your app. As such, screen performance is a core component of our solutions. To boost engagement and conversion rates, we employ several approaches to minimize screen load times.
SwiftUI Component
Starting from major version 4 of the Rokt iOS SDK, you can add a Rokt layout by utilizing the RoktLayout
component targeting iOS 15+. This removes the need to call Rokt.execute
and supports a more modern declarative integration using SwiftUI.
Adding the component
import SwiftUI
import Rokt_Widget
struct OrderConfirmationSwiftUI: View {
let attributes: [String: String]
let pageIdentifier: String
let location: String
// if application supports only Light Mode.
let roktConfig = RoktConfig.Builder()
.colorMode(.light)
.build()
var body: some View {
VStack(alignment: .leading) {
RoktLayout(sdkTriggered: true,
viewName: pageIdentifier,
locationName: location, // If using an embedded layout
attributes: attributes,
config: roktConfig,
onLoad: {
// Optional callback for when the Rokt placement loads
}, onUnLoad: {
// Optional callback for when the Rokt placement unloads
},onShouldShowLoadingIndicator: {
// Optional callback to show a loading indicator
}, onShouldHideLoadingIndicator: {
// Optional callback to hide a loading indicator
})
}.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
}
}
You can use the RoktLayout
component for both embedded and overlay layouts.
Using App Configurations
Applications can now send configuration settings from their own application environment. This allows Rokt SDK to use application custom configurations instead of relying solely on system defaults.
ColorMode object
Value | Description |
---|---|
light | Application is in Light Mode |
dark | Application is in Dark Mode |
system | Application defaults to System Color Mode |
// if application supports only Light Mode.
let roktConfig = RoktConfig.Builder()
.colorMode(.light)
.build()
Rokt.execute(
// other params,
config: roktConfig,
)
CacheConfig object
Parameter | Description |
---|---|
cacheDuration | Optional TimeInterval for which the Rokt SDK should cache the experience. Maximum allowed value is 90 minutes and the default (if value is not provided or invalid) is 90 minutes. |
cacheAttributes | Optional attributes to be used as cache key. If null, all the attributes sent in Rokt.execute will be used as the cache key. |
// to cache the experience for 1200 seconds, using email and orderNumber attributes as the cache key.
let roktConfig = RoktConfig.Builder()
.cacheConfig(RoktConfig.CacheConfig(
cacheDuration: TimeInterval(1200),
cacheAttributes: ["email": "j.smith@example.com", "orderNumber": "123"]
))
.build()
Rokt.execute(
// other params,
config: roktConfig,
)
For more information see how-to section.