iOS SDK Getting Started
Initializing the SDK
We recommend initializing the SDK once in didFinishLaunchingWithOptions
of your AppDelegate
for iOS / tvOS,
or applicationDidFinishLaunching
for macOS, to receive features for as soon as possible
and to pass around the client instance around in your app.
Swift
Using the builder pattern we can initialize the DevCycle SDK by providing the DevCycleUser and DevCycle mobile SDK key:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
let user = try DevCycleUser.builder()
.userId("my-user1")
.build()
guard let devcycleClient = try DevCycleClient.builder()
.sdkKey("<DEVCYCLE_MOBILE_SDK_KEY>")
.user(user)
.build(onInitialized: nil)
self.devcycleClient = devcycleClient
...
return true
}
The user object needs either a user_id
, or isAnonymous
set to true
for an anonymous user.
Objective-C
For Objective-C we use a standard callback pattern to initialize the DevCycle SDK by providing the DevCycleUser and DevCycle mobile SDK key:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
DevCycleUser *user = [DevCycleUser initializeWithUserId:@"my-user1"];
self.devcycleClient = [DevCycleClient initialize:@"<DEVCYCLE_MOBILE_SDK_KEY>"
user:user
options:nil
onInitialized:^(NSError * _Nullable error) {
if (error) {
NSLog(@"DevCycle failed to initialize: %@", error);
}
}];
...
return YES;
}
DevCycleClientBuilder
The DevCycleClient can be built using the following methods:
Method | Parameter | Description |
---|---|---|
sdkKey | String | DevCycle SDK key |
user | DevCycleUser | DevCycle user object |
options | DevCycleOptions | DevCycle options object |
DevCycleUser Builder
The DevCycleUser can be built using the following methods:
Method | Parameter | Description |
---|---|---|
userId | String | Unique user ID |
isAnonymous | Bool | Boolean to indicate if the user is anonymous |
String | User's email | |
name | String | User's name |
language | String | User's language |
country | String | User's country |
customData | [String: Any] | Key/value map of properties to be used for targeting |
privateCustomData | [String: Any] | Key/value map of properties to be used for targeting. Private properties will not be included in event logging. |
DevCycleOptions Builder
The SDK exposes various initialization options which can be used by passing a DevCycleOptions
object to the withOptions
method of DevCycleClient.builder()
:
Method | Parameter | Default | Description |
---|---|---|---|
flushEventsIntervalMs | Int | 10000 | Controls the interval between flushing events to the DevCycle servers in milliseconds, defaults to 10 seconds. |
disableCustomEventLogging | Boolean | false | Disables logging of custom events generated by calling .track() method to DevCycle. |
disableAutomaticEventLogging | Boolean | false | Disables logging of SDK generated events (e.g. variableEvaluated, variableDefaulted) to DevCycle. |
logLevel | LogLevel | error | Set log level of the default logger. Defaults to error |
enableEdgeDB | Boolean | false | Enables the usage of EdgeDB for DevCycle that syncs User Data to DevCycle. |
configCacheTTL | Int | 604800000 | The maximum allowed age of a cached config in milliseconds, defaults to 7 days |
disableConfigCache | Bool | false | Disable the use of cached configs |
disableRealtimeUpdates | Bool | false | Disable Realtime Updates |
apiProxyURL | String | nil | Allows the SDK to communicate with a proxy of DevCycle Client SDK API. |
eventsApiProxyURL | String | nil | Allows the SDK to communicate with a proxy of DevCycle Events API. |
Notifying when DevCycle features are available
In the initialize call there is an optional onInitialized
parameter you can use to determine when your features have been loaded:
Swift
self.devcycleClient = try? DevCycleClient.builder()
.sdkKey("<DEVCYCLE_MOBILE_SDK_KEY>")
.user(user)
.options(options)
.build(onInitialized: { error in
if (error != nil) {
// there was an error with building the client
} else {
// initialized successfully
}
})
Objective-C
self.devcycleClient = [DevCycleClient initialize:@"<DEVCYCLE_MOBILE_SDK_KEY>"
user:user
options:nil
onInitialized:^(NSError * _Nullable error) {
if (error) {
NSLog(@"DevCycle failed to initialize: %@", error);
} else {
// initialized successfully
}
}];