iOS Swift SDK
Overview
The Kevel iOS SDK makes the ad serving and UserDB features of Kevel easily available for iOS apps. It is an open source project hosted on Github.
Github Open Source iOS SDK
https://github.com/adzerk/adzerk-ios-sdk
iOS Version
iOS SDK is designed for iOS v8.0 and later.
Getting the SDK
The SDK can be installed via Carthage or CocoaPods. It can also be installed manually.
Detailed Documentation
We have detailed developer-level documentation on the project's website at https://adzerk.github.io/adzerk-ios-sdk/
Examples
Fetching an Ad Decision
import AdzerkSDK
// Demo network, site, & ad type IDs; find your own via the Adzerk UI!
DecisionSDK.defaultNetworkId = 23
DecisionSDK.defaultSiteId = 667480
let client = DecisionSDK()
var p = Placements.custom(divName: "div0", adTypes: [5])
var reqOpts = PlacementRequest<StandardPlacement>.Options()
reqOpts.userKey = "abc"
reqOpts.keywords = ["keyword1", "keyword2"]
client.request(placements: [p], options: reqOpts) {response in
dump(response)
}
Recording Impressions
Use with the fetch ad example above.
client.request(placements: [p], options: reqOpts) {
switch $0 {
case .success(let response):
for decision in response.decisions {
print(decision.key)
for selection in decision.value {
dump(selection, maxDepth: 3)
print("\nFiring impression pixel...")
client.recordImpression(pixelURL: selection.impressionUrl!)
}
}
case .failure(let error):
print(error)
}
}
UserDB: Reading User Record
import AdzerkSDK
// Demo network ID; find your own via the Adzerk UI!
DecisionSDK.defaultNetworkId = 23
let keyStore = UserKeyStoreKeychain()
keyStore.save(userKey: "abc")
let client = DecisionSDK(keyStore: keyStore)
client.userDB().readUser() {response in
dump(response)
}
UserDB: Setting Custom Properties
import AdzerkSDK
// Demo network ID; find your own via the Adzerk UI!
DecisionSDK.defaultNetworkId = 23
let keyStore = UserKeyStoreKeychain()
keyStore.save(userKey: "abc")
let client = DecisionSDK(keyStore: keyStore)
let props:[String: AnyCodable] = [
"favoriteColor": .string("blue"),
"favoriteNumber": .int(42),
"favoriteFoods": .array([
.string("strawberries"),
.string("chocolate"),
])
]
client.userDB().postProperties(props) {response in
dump(response)
}
Building an iOS Project with the SDK
Once you have installed the SDK, you can import AdzerkSDK
in the AppDelegate
and define your networkID and siteID.
The readme on Github has full documentation for usage.
By default, warnings and errors will be printed to the console. If you want logs, be sure to set your logging level to production before deploying your app. The readme has more details and instructions.
Updated 6 months ago