iOS, watchOS, tvOS & macOS


This document includes necessary information for integrating Countly iOS / watchOS / tvOS / macOS SDK in your application.

Supported System Versions

Countly iOS SDK supports minimum Deployment Target iOS 8.0 (watchOS 2.0, tvOS 9.0, macOS 10.10) , and requires Xcode 9.0+ with Base SDK iOS 10.0+


To integrate Countly iOS SDK into your application, please follow these steps:

1. Download Countly iOS SDK (or clone it in your project as a Git submodule, or use CocoaPods or Carthage).

2. Add all files in countly-ios-sdk to your project on Xcode.

You can delete and from your project or remove them from Target > Build Phases > Compile Sources to avoid compiler warnings.

3. In your application delegate, import Countly.h , and inside application:didFinishLaunchingWithOptions: add following lines at the beginning:

objectivec swift
#import "Countly.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    CountlyConfig* config =;
    config.appKey = @"YOUR_APP_KEY"; = @"https://YOUR_COUNTLY_SERVER";
    [Countly.sharedInstance startWithConfig:config];

    // your code
    return YES;

4. Set your app key and host on CountlyConfig object. Make sure you use App Key (under Management > Applications), not API Key or App ID.

If you are using Countly Enterprise Edition trial servers host should be, or Basically the domain you are accessing your trial dashboard from.

5. You can run your project and see first session data immediately on your Countly Server dashboard.

Advanced Configuration

Countly Code Generator

Countly Code Generator can be used to generate Countly iOS SDK code snippets easily and fast. You can provide values for your custom events, user profiles, or just start with basic integration. It will generate necessary code for you.

Debug Mode

If you want to enable Countly iOS SDK debug mode which logs internal infos, errors and warnings into console, you can set enableDebug flag on CountlyConfig object before starting Countly.

objectivec swift
config.enableDebug = YES;

Additional Features

If you want to use additional features like PushNotifications, CrashReporting and AutoViewTracking you can specify them in features array on CountlyConfig object before you start:

objectivec swift
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    CountlyConfig* config =;
    config.appKey = @"YOUR_APP_KEY"; = @"https://YOUR_COUNTLY_SERVER";
    //You can specify additional features you want here
    config.features = @[CLYPushNotifications, CLYCrashReporting, CLYAutoViewTracking];
    [Countly.sharedInstance startWithConfig:config];

    // your code
    return YES;

Device ID

You can configure device ID using CountlyConfig object and helper methods:

Using a Custom Device ID

If you want to use a custom device ID, you can set deviceID property on CountlyConfig object. If deviceID property is not set explicitly, default device ID will be used depending on platform.

objectivec swift
config.deviceID = @"customDeviceID";  //Optional custom device ID

Note: Once set, device ID will be persistently stored on device after the first app launch, and deviceID property will be ignored on the following app launches, until the app is deleted and re-installed or resetStoredDeviceID flag is set. For details please see Resetting Stored Device ID section.

Changing Device ID

You can use setNewDeviceID:onServer: method to change device ID on runtime after you start Countly. You can either let the device counted as a new device or merge existing data on server.

If onServer bool is set, old device ID on server will be replaced with the new one, and data associated with old device ID will be merged automatically.

objectivec swift
[Countly.sharedInstance setNewDeviceID:@"new_device_id" onServer:YES];
//replace and merge on server

Otherwise, if onServer bool is not set, device will be counted as a new device on server.

objectivec swift
[Countly.sharedInstance setNewDeviceID:@"new_device_id" onServer:NO];
//no replace and merge on server, device will be counted as new

Note: To switch back to default device ID, you can pass CLYDefaultDeviceID.

Handling User Login and Logout

If your app allows users to login, logged in users can be tracked with custom user ID (like accountID, username, memberID, email etc.) instead of device ID. For these cases, you can use userLoggedIn: and userLoggedOut convenience methods for changing device ID.

userLoggedIn: method handles switching from device ID to custom user ID for logged in users. It is just a convenience method that sets passed user ID as new device ID and merging existing data on server.

objectivec swift
[Countly.sharedInstance userLoggedIn:@"UserID"];

userLoggedOut method handles switching from custom user ID to default device ID for logged out users. It is just a convenience method that handles setting device ID to default one and starting a new session. Logged out user's data can will be tracked using default device ID henceforth.

objectivec swift
[Countly.sharedInstance userLoggedOut];

Resetting Stored Device ID

In order to handle device ID changes for logged in and logged out users, on the first app launch, device ID specified in CountlyConfig object deviceID property (or default device ID, if not specified) will be persistently stored. As well as device ID passed to setNewDeviceID:onServer: method anytime. After this point, until you delete and re-install the app, Countly iOS SDK will continue to use stored device ID and ignore deviceID property. So, while development if you set deviceID property to something else on following app launches, it will have no effect. In this case, you can set resetStoredDeviceID flag on CountlyConfig object, to reset stored device ID. This will reset the initially stored device ID and Countly iOS SDK will work as if it is the first app launch.

objectivec swift
config.resetStoredDeviceID = YES;

After you start Countly with resetStoredDeviceID flag only once while developing, you can remove that line. resetStoredDeviceID flag is not meant for production. It is only for debugging purposes while doing development and not being able to delete and re-install the app.


On CountlyConfig object you can specify extra security features:

Pinned Certificates

You can use optional pinnedCertificates on CountlyConfig object for specifying bundled certificates to be used for public key pinning. Certificates from your Countly Server have to be DER encoded and should have .der, .cer or .crt extension. They also have to be added to your project and included in Copy Bundles Resources.

objectivec swift
config.pinnedCertificates = @[@"mycertificate.cer"];

Custom Header Field

You can set optional customHeaderFieldName to be sent with every request. It is useful if your server requires special headers to be sent for security reasons. Every request sent to Countly Server will have this custom HTTP header and its value will be what you specify for customHeaderFieldValue property.

objectivec swift
config.customHeaderFieldName = @"X-My-Custom-Field";
config.customHeaderFieldValue = @"my_custom_value";

If you do not set customHeaderFieldValue value while you set customHeaderFieldName on initial Countly configuration (incase value is not available on app launch and will be retrieved later), requests will not start until you set it using setCustomHeaderFieldValue: method later.

objectivec swift
[Countly.sharedInstance setCustomHeaderFieldValue:@"my_custom_value"];

Parameter Tampering Protection

You can set optional secretSalt to be used for calculating checksum of request data, which will be sent with each request using &checksum256 field. You need to set exactly the same secretSalt on Countly Server. If secretSalt on Countly Server is set, all requests would be checked for validity of &checksum256 field before being processed.

objectivec swift
config.secretSalt = @"mysecretsalt";

Other Settings

On CountlyConfig object you can specify further optional settings:

Update Session Period

You can specify updateSessionPeriod on CountlyConfig object before starting Countly. It is used for session updating and sending queued events to server periodically. If updateSessionPeriod is not set explicitly, it will be 60 seconds for iOS, tvOS & macOS, and 20 seconds for watchOS by default.

objectivec swift
config.updateSessionPeriod = 300;

Event Send Threshold

You can specify eventSendThreshold on CountlyConfig object before starting Countly. It is used to send events requests to server when number of recorded custom events reach it without waiting for next update session request. If eventSendThreshold is not set explicitly it will be 10 for iOS, tvOS & macOS, and 3 for watchOS by default.

objectivec swift
config.eventSendThreshold = 5;

Stored Requests Limit

You can specify storedRequestsLimit on CountlyConfig object before starting Countly. It is used to limit number of request to be stored when there is a Countly Server connection problem. In case your Countly Server is down, queued request may reach excessive numbers, and it may cause problems with being delivered to server and stored on the device. To prevent this, Countly iOS SDK will only store requests up to storedRequestsLimit. If number of stored requests reach storedRequestsLimit, Countly iOS SDK will start to drop oldest request while storing the newest one instead. If storedRequestsLimit is not set explicitly it will be 1000 by default.

objectivec swift
config.storedRequestsLimit = 5000;

Always use POST method

You can set alwaysUsePOST flag on CountlyConfig object before starting Countly. It is used for sending all requests using HTTP POST method regardless of the data size. If set, all requests will be sent using HTTP POST method. Otherwise; only the requests with a file upload or data size more than 2048 bytes will be sent using HTTP POST method.

objectivec swift
config.alwaysUsePOST = YES;

Manual Session Handling

You can set manualSessionHandling flag on CountlyConfig object before starting Countly to handle sessions manually.

objectivec swift
config.manualSessionHandling = YES;

By default, Countly iOS SDK tracks sessions automatically and sends begin_session request on initialization, end_session request when the app goes to background, and begin_session request again when the app comes back to foreground. In addition to them, Countly iOS SDK automatically sends a periodical (60 sec by default) update session request while the app is in foreground.

If manualSessionHandling flag is set, Countly iOS SDK does not send these requests automatically. So, you need to call beginSession, updateSession and endSession methods manually after you start Countly, depending on your own definition of a session.

objectivec swift
[Countly.sharedInstance beginSession];
[Countly.sharedInstance updateSession];
[Countly.sharedInstance endSession];


You can set enableAttribution flag on CountlyConfig object to enable campaign attribution. If set, IDFA (Identifier For Advertising) will be sent with every begin_session request, unless user has limited ad tracking in iOS Settings.

objectivec swift
config.enableAttribution = YES;


Default Device ID

On iOS, iPadOS and tvOS default device ID is Identifier For Vendor (IDFV). On watchOS and macOS, it is a persistently stored random NSUUID string.

Automatic Reference Counting (ARC)

Countly iOS SDK uses Automatic Reference Counting (ARC). If you are integrating Countly iOS SDK into a non-ARC project, you should add -fobjc-arc compiler flag to all Countly iOS SDK implementation (*.m) files, under Target > Build Phases > Compile Sources.

App Transport Security (ATS)

With App Transport Security introduced in iOS 9, connections do not follow some security requirements will fail. You can see these requirements here. If your Countly Server instance does not meet these requirements, you may need to add NSAppTransportSecurity key into your targets' Info.plist files, with NSAllowsArbitraryLoads or NSExceptionDomains as value, to communicate with your Countly Server.

Swift Projects

For using Countly on Swift based projects, please make sure your Bridging Header File is configured properly for each target. And then import Countly.h file in Bridging Header file. After that you can use Countly methods in your Swift projects seamlessly.

And for Notification Service Extension targets, just import CountlyNotificationService.h in Bridging Header file.

You can see details on how to create Bridging Header file here.

Updating Countly iOS SDK

Before upgrading to a new version of Countly iOS SDK, do not forget to remove the existing old files from your project first. And while adding new Countly iOS SDK files again, please make sure you choose targets correctly and select "Copy items if needed" checkbox.


CocoaPods Support

While Countly iOS SDK supports integration via CocoaPods, we may not be able to help you with issues stemming from CocoaPods itself, especially for some advanced use-cases.

You can integrate Countly iOS SDK using CocoaPods. For more information, please see Countly CocoaPods page. Please make sure you have the latest version of CocoaPods and your local spec repo is updated. For Notification Service Extension targets, please make sure your Podfile uses subspecs like this:

target 'MyMainApp' do
  platform :ios,'8.0'
  pod 'Countly'

target 'CountlyNSE' do
  platform :ios,'10.0'
  pod 'Countly/NotificationService'

For Swift projects with Notification Service Extension, please see:

For Crash Reporting automatic dSYM uploading, please add dSYM uploader script to your project manually.


You can integrate Countly iOS SDK using Carthage. Just add following to your project's Cartfile:

github "Countly/countly-sdk-ios"

App Store Connect IDFA Warning

As Countly iOS SDK source has references to IDFA for attribution feature, and App Store Connect checks for API usage, you may need to answer Yes for "Does this app use the Advertising Identifier (IDFA)?" question on App Store Connect app submit form. Please make sure you follow the instructions specified in App Store Connect support page - Provide advertising identifier details section. Otherwise your app may get rejected due to "Improper use of IDFA" or fail to proceed on app submitting. In screenshot below, you can see which checkboxes to select while sending your app to the App Store :

If you are using an advertisement system, you might need to check "Serve advertisements within the app" checkbox too.

If you do not want any IDFA references to be part of you app, you can add COUNTLY_EXCLUDE_IDFA=1 flag to Build Settings > Preprocessor Macros section in Xcode. Once this flag is added, IDFA references won't be a part of the final product. So, you can directly say No to IDFA usage question on App Store Connect.

If you are adding Countly iOS SDK source files directly to your project, make sure the flag is added to your app target. If you are adding it as a framework, make sure the flag is added to framework target.


If you want to rebrand Countly iOS SDK or make it whitelabel, you can use this rebranding script:

Frequently Asked Questions (FAQ) Page

For frequently asked questions about Countly iOS SDK you can see the FAQ page:

Recording Events

Here is a quick summary on how to use custom events recording methods:

Regular Events

In examples below, we will be recording a event named purchase with different scenarios:

  • purchase event occurred 1 time
objectivec swift
[Countly.sharedInstance recordEvent:@"purchase"];
  • purchase event occurred 3 times
objectivec swift
[Countly.sharedInstance recordEvent:@"purchase" count:3];
  • purchase event occurred 1 times with the total amount 3.33
objectivec swift
[Countly.sharedInstance recordEvent:@"purchase" sum:3.33];

* purchase event occurred 3 times with the total amount 9.99

objectivec swift
[Countly.sharedInstance recordEvent:@"purchase" count:3 sum:9.99];
  • purchase event occurred 1 time from country : Germany, on app_version : 1.0
objectivec swift
NSDictionary* dict = @{@"country":@"Germany", @"app_version":@"1.0"};

[Countly.sharedInstance recordEvent:@"purchase" segmentation:dict];
  • purchase event occurred 2 times from country : Germany, on app_version : 1.0
objectivec swift
NSDictionary* dict = @{@"country":@"Germany", @"app_version":@"1.0"};

[Countly.sharedInstance recordEvent:@"purchase" segmentation:dict count:2];
  • purchase event occurred 2 times with the total amount 6.66, from country : Germany, on app_version : 1.0
objectivec swift
NSDictionary* dict = @{@"country":@"Germany", @"app_version":@"1.0"};

[Countly.sharedInstance recordEvent:@"purchase" segmentation:dict count:2 sum:6.66];

Timed Events

In examples below, we will be recording a timed event called level24 to track how long it takes to complete:

  • level24 started
objectivec swift
[Countly.sharedInstance startEvent:@"level24"];
  • level24 ended
objectivec swift
[Countly.sharedInstance endEvent:@"level24"];

Additionally, you can provide more information like segmentation, count and sum while ending an event.

  • level24 ended 1 time with the total point of 34578, from country : Germany, on app_version : 1.0
objectivec swift
NSDictionary* dict = @{@"country":@"Germany", @"app_version":@"1.0"};

[Countly.sharedInstance endEvent:@"level24" segmentation:dict count:1 sum:34578];

Duration of the event will be calculated automatically when endEvent method is called.

Or, you if you measure duration of an event yourself, you can directly record it like this:

  • level24 took 344 seconds to complete:
objectivec swift
[Countly.sharedInstance recordEvent:@"level24" duration:344];

Additionally, you can provide more information like segmentation, count and sum as well.

  • level24 took 344 seconds to complete 2 times with the total point of 34578, from country : Germany, on app_version : 1.0
objectivec swift
NSDictionary* dict = @{@"country":@"Germany", @"app_version":@"1.0"};

[Countly.sharedInstance recordEvent:@"level24" segmentation:dict count:2 sum:34578 duration:344];

Event Names and Segmentation

Event names must be non-zero length valid NSString and segmentation must be an NSDictionary which does not contain any custom objects, as it will be converted to JSON.

Push Notifications

Setting up APNs Authentication

First you need to acquire Push Notification credentials from Apple, using one of the following methods: A) APNs Auth Key (preferred)
B) Universal (Sandbox + Production) Certificate

A) Getting APNs Auth Key

APNs Auth Key is the preferred way of authentication on APNs for a number of reasons including less issues during configuration and being able to reuse the same connection with multiple apps.

To get APNs Auth key, first go to Create a New Key section on Apple Developer website.

Check APNs option and create your key.
Then download it and store in a safe place, you won't be able to download it again.
To upload a key file to Countly you'll also need some identifiers:

  • Key ID (filled automatically if you kept original Auth Key filename, otherwise visible on key details panel)

  • Team ID (see Membership section)

  • Bundle ID (see App IDs section)

B) Getting APNs Universal (Sandbox + Production) Certificate

Please go to Certificates section of Certificates, Identifiers & Profiles page on Apple Developer website. Click plus sign and select Apple Push Notification service SSL (Sandbox & Production) type. Follow the instructions. Once you are done, download it and double click to add it to your Keychain.

Next, you'll need to export your push certificate in p12 format. Please open Keychain Access app, select login keychain and My Certificates category. Search for your app id and find the certificate starting with Apple Push Services. Select both the certificate and its private key as in screenshot below. Right click and choose Export 2 items... and save it. You're free to name the p12 file as you wish and set up a passphrase or leave it empty.

Once you download your auth key or export your certificate, you need to upload it to your Countly Server. Please go to Management > Applications > Your App Click on Edit and upload your auth key or exported certificate under APN Credentials section.

After filling all the required fields, click Validate button. Countly will check validity of credentials by initiating a test connection to APNs. If validation succeeds, click Save changes.

Configuring iOS app

Using Countly Push Notifications in iOS apps is pretty straightforward. First, integrate Countly iOS SDK as usual if you still haven't.

Then, under Capabilities section of Xcode, please enable Push Notifications and Remote notifications Background Mode for your target, as in screen shot below:

Now start Countly in application:didFinishLaunchingWithOptions: method of your app with the following configuration. Do not forget to specify CLYPushNotifications in features array of CountlyConfig object. After that, you'll need to ask for user's permission for push notifications using askForNotificationPermission method of Countly, at any point in the app. Countly iOS SDK will handle the rest automatically. No need to call any other method for registering or when device token is generated or a push notification is received.

objectivec swift
#import "Countly.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    //Start Countly with CLYPushNotifications feature as follows
    CountlyConfig* config =;
    config.appKey = @"YOUR_APP_KEY"; = @"https://YOUR_COUNTLY_SERVER";
    config.features = @[CLYPushNotifications];
//  config.isTestDevice = YES;     //if it is a test device, mark it here
    [Countly.sharedInstance startWithConfig:config];

    //Ask for user's permission for Push Notifications (not necessarily here)
    //You can do this later at anypoint in the app after starting Countly
    [Countly.sharedInstance askForNotificationPermission];

    // your code

    return YES;

Note: Make sure you codesign your application using an explicit Provisioning Profile specific to your app's bundleID with aps-environment key in it. You can get it from iOS Provisioning Profiles section of Apple Developer website. Be advised, wildcard (*) profiles or profiles without aps-environment key does not work with APNs, and your device can not get a push token.

Note: To see how to send push notifications using Countly Server please check our Push Notifications documentation.

Rich Push Notifications (iOS10+ only)

Rich push notifications let's you send image, video or audio attachments, as well as customized action buttons on iOS10+. You need to set up Notification Service Extension to use it.

While main project file is selected, please click Editor > Add Target... menu in Xcode, and add a Notification Service Extension target.

Using Product Name field name the Notification Service Extension target as you wish (for example: CountlyNSE). And make sure Team is selected also.

Note: If Xcode asks a question about activating the scheme for newly added Notification Service Extension target, you can choose Cancel.

Under Build Phases > Compile Sources section of newly added extension target, click on + sign.

Select CountlyNotificationService.m in the list.

Note: If you can not see CountlyNotificationService.m file due to using CocoaPods or Carthage for integration, please locate it yourself (probably under Pods folder) and add to your project manually.

Then find NotificationService.m file (NotificationService.swift in Swift projects) in extension target. It is a default template file added by Xcode automatically. Inside this file import CountlyNotificationService.h

objectivec swift
#import "CountlyNotificationService.h"

And add the following line at the end of didReceiveNotificationRequest:withContentHandler: method as shown below:

objectivec swift
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];
  	//delete existing template code, and add this line
    [CountlyNotificationService didReceiveNotificationRequest:request withContentHandler:contentHandler];

Note: Please make sure you configure App Transport Security setting in extension's Info.plist file also, just like the main application. Otherwise media attachments from non-https sources can not be loaded.

Note: Please make sure you check Deployment Target version of extension target is 10, not 10.3 (or whatever minor version Xcode set automatically). Otherwise users running iOS versions lower than Deployment Target value can not get rich push notifications.

Provisional Permission for Push Notifications (iOS12+ only)

iOS12 has a new feature called Provisional Permission for push notifications, and it is granted by default for all users. Without showing the notification permission dialog, without requiring users to accept anything, it let's you send notifications to the users.

But these notifications are little bit different, they do not actually notify the users. There are no alerts, no banners, no sounds, or no badges. Nothing informing the users at the moment of notification delivery. Instead, these notifications directly go to Notification Center and they pile up in the list silently. Only when the user goes to Notification Center and checks the list he/she sees them.

To utilize Provisional Permission for push notifications; while requesting for notification permission types, you pass a new type, called UNAuthorizationOptionProvisional.

objectivec swift
UNAuthorizationOptions authorizationOptions = UNAuthorizationOptionProvisional;

[Countly.sharedInstance askForNotificationPermissionWithOptions:authorizationOptions completionHandler:^(BOOL granted, NSError *error)
    NSLog(@"granted: %d", granted);
    NSLog(@"error: %@", error);

And if this is the only notification permission type you ask for, there will be no permission dialog and it will be granted by default. And then later on Notification Center, users can swipe on these provisional notifications and cancel the provisional permission anytime they want. And notification permission level changes to UNAuthorizationStatusDenied from UNAuthorizationStatusProvisional state. So, it works as a kind of opt-out.

How do Push Notifications Work in Countly

When a push notification is received, Countly iOS SDK handles everything automatically.

First, it checks if notification payload has Countly specific dictionary (c key) and notification ID inside it (i key). If Countly specific dictionary is present, it processes the notification. Otherwise it does nothing. In both cases, Countly iOS SDK forwards the notification to default application delegate implementation for manual handling.

Processing of notification payload depends on iOS version, applications status (background or foreground) at the time of notification receiving, and notification payload's content.

If there is a media attachment or custom action buttons, Notification Service Extension handles all automatically. Users can see them by using 3D Touch or swiping on older devices.

When the app is not in foreground, it waits for the user's interaction (like tapping notification itself or one of the custom action buttons). After user's interaction, it automatically records a specific event indicating that user has opened the push notification. And if user tapped one of the custom action buttons, it also records another specific event with button index segmentation and redirects to specified URL for that action.

When the app is in foreground, it uses UNNotificationPresentationOptionAlert mode on iOS10+ to present a default notification banner. And it uses a system UIAlertController on older iOS version and records push opened event directly.

You can see the detailed flow in this chart (download the chart for a bigger view):

Deep Linking

When you send a push notification with custom actions buttons, you can redirect users to any custom page or view in your app, by specifying deep links as custom actions button URLs. For this, you need to create URL scheme (e.g: myapp://) in your project first.

To do this, select your app target in Xcode and open Info tab. Then, open URL Types section by clicking horizontal arrow, and click plus + sign there.

Enter an identifier (preferably in reverse domain format) into Identifier field. And enter your app's URL scheme (without ://part) into URL Schemes field. Optionally you can set Icon. And you can leave Role field whatever it is by default. When you are done, you can confirm that new URL scheme is added to your app's Info.plist file. It should look like this:

After setting up URL scheme, you should add application:openURL:options: method to your app delegate:

objectivec swift
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
    //handle URL here to navigate to custom views

    return YES;

If your app's deployment target is lower than iOS9, you should add application:openURL:sourceApplication:annotation: method instead:

objectivec swift
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation
    //handle URL here to navigate to custom views

    return YES;

Then in this method you can check the passed url for custom view navigation, using scheme and host properties. For example, if you set custom action button URLs as countly://productA and countly://productB, you can use something similar to this snippet:

objectivec swift
if ([url.scheme isEqualToString: @"countly"])
    if ([ isEqualToString: @"productA"])
        // present view controller for Product A;
    else if ([ isEqualToString: @"productB"])
        // present view controller for Product B;
   // or you can use host property directly

When users tap on custom action buttons, Countly iOS SDK will open the specified URLs with your app's scheme. Following this, related method you added to your app's delegate will be called.

Advanced Setup

Test Mode

For Development builds (where the project's build settings includes DEBUG preprocessor macro by default), your device will be marked as test device automatically. So, you can send push notifications to test devices by choosing Test Users radio button on Create Message screen of Countly Dashboard. If you want to manually mark your device as a test device for Distribution builds like TestFlight or AdHoc, you can use isTestDevice flag on CountlyConfig object.

objectivec swift
config.isTestDevice = YES;

Disabling Alerts Shown by Notification

To disable automatically showing of messages by CLYPushNotifications feature while the app is in foreground, you can set doNotShowAlertForNotifications flag on CountlyConfig object. If set, no message will be displayed by using default system UI in the app, but push open event will be recorded automatically.

objectivec swift
config.doNotShowAlertForNotifications = YES;

Handling Notifications Manually

If you want to do additional custom work when a push notification is received, all you need to do is implement default push related methods in your application delegate (e.g. AppDelegate.m). After finishing its internal work, Countly iOS SDK will forward push related method calls to default implementations on application delegate.

Please make sure you do not set UNUserNotificationCenter.currentNotificationCenter's delegate manually, as Countly iOS SDK will be acting as the delegate. Just directly add UNUserNotificationCenterDelegate methods to your application delegate class.

Inside push notification userInfo dictionary, you can find all necessary information under Countly Payload dictionary specified by c (kCountlyPNKeyCountlyPayload) key. Custom action buttons array is specified by b (kCountlyPNKeyButtons) key here. And each custom action button's title and action URL is specified by t (kCountlyPNKeyActionButtonTitle) and l (kCountlyPNKeyActionButtonURL) keys respectively. Here is an example Countly Push Notification Payload:

    "alert": "this is notification text",
    //or     {"title": "title string", "body": "message string"}, //if title is set separately
		"sound": "sound_name", //if sound is set 
		"badge": 123, //if badge is set 
		"content-available": 1, //if data only flag is set
		"mutable-content": 1, //if buttons or media attachment is set      

    "i": "100001", //notification ID
    "l": "", //if default link is set
		"a": "", //if media attachment is  set
    "b": //if buttons is set
        "t": "Custom Action Button Title 1", //button title
        "l": "", //button link
        "t": "Custom Action Button Title 2",
        "l": "",
  //any other custom data if set

You can create your own custom UI to show notification message and custom action buttons as you wish, along with URLs to redirect users when action is taken. Once users take action by clicking your custom buttons, you need to report this event manually using this method:

objectivec swift
NSDictionary* userInfo;     // notification dictionary
NSInteger buttonIndex = 1;  // clicked button index
                            // 1 for first action button
                            // 2 for second action button
                            // 0 for default action
[Countly.sharedInstance recordActionForNotification:userInfo clickedButtonIndex:buttonIndex];

Sending Push Token Always

Thanks to Remote Notification Background Mode of iOS, it is possible to send silent push notifications to users who have not given notification permission. But Countly iOS SDK does not send push tokens to server by default, from users who have not given permission for notifications. You can change this by setting sendPushTokenAlways flag of CountlyConfig object. If set, push tokens from all users regardless of their notification permission status will be sent to Countly server and these users will be listed as possible recipients on Create Message screen of Countly Dashboard. As these users are not able to be notified by alert, sound or badge, be advised this is useful only for sending data via silent notifications.

objectivec swift
config.sendPushTokenAlways = YES;

Notification Permission with Preferred Types and Callback

As asking for user's permission for push notifications differ by iOS versions, Countly iOS SDK has a one-liner convenience method askForNotificationPermission to do this for both iOS10 and older versions. It simply asks for user's permission for all available notification types. But if you need to specify which notification types your app will use (alert, badge, sound) or if you need a callback to see user's response to permission dialog you can use askForNotificationPermissionWithOptions:completionHandler: method.

objectivec swift
UNAuthorizationOptions authorizationOptions = UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert;

[Countly.sharedInstance askForNotificationPermissionWithOptions:authorizationOptions completionHandler:^(BOOL granted, NSError *error)
    NSLog(@"granted: %d", granted);
    NSLog(@"error: %@", error);


Enterprise Edition Feature

This feature is only available with Enterprise Edition subscription.

Countly lets you send GeoLocation based push notifications to your users. By default, Countly Server uses geoip database to deduce user's location. But, if your app has better means of detecting location, you can send this information to Countly Server by using initial configuration properties or relevant methods.

Initial configuration properties can be set on CountlyConfig object, to be sent on SDK initialization. These are:

location a CLLocationCoordinate2D struct specifying latitude and longitude. ISOCountryCode an NSString in ISO 3166-1 alpha-2 format country code. city an NSString specifying city name. IP an NSString specifying IP address in IPv4 or IPv6 format.

objectivec swift
config.location = (CLLocationCoordinate2D){35.6895,139.6917}; = @"Tokyo";

config.ISOCountryCode = @"JP";

config.IP = @""

GeoLocation info recording methods also can be called anytime after Countly iOS SDK started. Values recorded using these methods will override the values specified on initial configuration.

objectivec swift
[Countly.sharedInstance recordLocation:(CLLocationCoordinate2D){35.6895,139.6917}];

[Countly.sharedInstance recordCity:@"Tokyo" andISOCountryCode:@"JP"];

[Countly.sharedInstance recordIP:@""];

GeoLocation info can also be disabled:

objectivec swift
[Countly.sharedInstance disableLocationInfo];

Once disabled, you can re-enable GeoLocation info by calling recordLocation: or recordCity:andISOCountryCode: or recordIP: method.

Crash Reporting

Automatic Crash Reporting

For Countly Crash Reporting, you'll need to specify CLYCrashReporting in features array on CountlyConfig object before starting Countly.

objectivec swift
config.features = @[CLYCrashReporting];

With this feature, Countly iOS SDK will generate a crash report if your application crashes due to an exception, and send it to Countly Server for further inspection. If a crash report can not be delivered to server (e.g. no internet connection, unavailable server) at the time of crash, then Countly iOS SDK stores the crash report locally in order to try again later.

Manually Handled Exceptions

You can records handled exception manually, besides automatically reported unhandled exceptions and crashes:

objectivec swift
NSException* myException = [NSException exceptionWithName:@"MyException" reason:@"MyReason" userInfo:@{@"key":@"value"}];

[Countly.sharedInstance recordHandledException:myException];

You can also manually pass stack trace at the time of handled exception:

objectivec swift
NSException* myException = [NSException exceptionWithName:@"MyException" reason:@"MyReason" userInfo:@{@"key":@"value"}];

[Countly.sharedInstance recordHandledException:myException withStackTrace:[NSThread callStackSymbols]];

Crash Report Contents

A crash report includes following information:

Default Crash Report Information

- Exception Info:
  * Exception Name
  * Exception Description
  * Stack Trace
  * Binary Images

- Device Static Info:
  * Device Type
  * Device Architecture
  * Resolution
  * Total RAM
  * Total Disk

- Device Dynamic Info:
  * Used RAM
  * Used Disk
  * Battery Level 
  * Connection Type
  * Device Orientation

- OS Info:
  * OS Name
  * OS Version
  * OpenGL ES Version
  * Jailbrake State

- App Info:
  * App Version
  * App Build Number
  * Executable Name
  * Time Since App Launch
  * Background State

- Custom Info:
  * Crash logs recorded using `recordCrashLog:` method
  * Crash segmentation specified in `crashSegmentation` property

Custom Crash Logs

You can use recordCrashLog: method to get custom logs with the crash reports. Logs generated by recordCrashLog: method are stored in a non-persistent structure, and delivered to Countly Server only in case of a crash.

objectivec swift
[Countly.sharedInstance recordCrashLog:@"This is a custom crash log."];

Custom Crash Segmentation

If you want to use custom crash segmentation, you can set optional crashSegmentation dictionary on CountlyConfig object.

objectivec swift
config.crashSegmentation = @{@"key":@"value"};


Enterprise Edition Feature

This feature is only available with Enterprise Edition subscription.

Symbolication is the process of converting stack trace memory addresses in crash reports, into human readable useful information like class/method names, file names and line numbers.

In order to symbolicate memory addresses, dSYM files for each build needs to be uploaded to Countly Server.

Automatic dSYM Uploading

For Automatic dSYM Uploading, you can use countly_dsym_uploader script in Countly iOS SDK.

For this, go to Build Phases section of your app target, and click on plus ( + ) icon on the top left, then choose New Run Script Phase in the list.

Then, add the following snippet:

COUNTLY_DSYM_UPLOADER=$(/usr/bin/find $SRCROOT -name "" | head -n 1)

And select checkbox Run script only when installing

Note: Do not forget to replace your server and app key.

By default Xcode will generate dSYM files for Release build configuration, and countly_dsym_uploader script will handle the uploading automatically. You can check for the result at Report Navigator in Xcode. If dSYM upload is completed successfully, you will see [Countly] dSYM upload succesfully completed. message.

If there are any errors while uploading dSYM file, you can also see these error messages in Report Navigator. Some of the possible error reasons are: dSYM file not being created due to build configurations, dSYM file being created at a non-default location, wrong App ID and/or Countly Server address, network unavailability.

Manual dSYM Uploading

In case of an error with Automatic dSYM Uploading, or just if you want to upload your dSYM files manually, you can use our guide for Manual dSYM Uploading here. You also need to use Manual dSYM Uploading if Bitcode is enabled while uploading your app to the App Store Connect.

Bitcode Enabled Apps

If Bitcode is enabled in your project while uploading your app to the App Store Connect, Apple re-compiles your app to optimize it for specific devices. When Apple re-compiles your app, a new dSYM file is generated for the new build, and the dSYM file on your machine will not work for symbolication. So, you need to get this new dSYM file manually, and then upload it to Countly Server. In order to get the new dSYM file, you can use App Store Connect or Xcode Organizer.

Using App Store Connect: 1. Login to App Store Connect. 2. Go to Activity tab. 3. Select your app's Version and Build 4. Under General Information click on Download dSYM. 5. If downloaded file does not have any extension add .zip and unarchive to see contents.

Using Xcode: 1. Open Organizer in Xcode 2. Go to Archives tab. 3. Select your app on the left list and select the archive 4. Click on Download dSYMs... 5. Xcode inserts the downloaded .dSYM files in the selected archive

For more information about downloading dSYM files from Apple, please see Apple's documentation here.

After you get your dSYM file from Apple, you can use our Manual dSYM Uploading guide.

How to Use Symbolication

Once your dSYM file is uploaded to Countly Server, you can symbolicate your crash reports coming from that build, on Crashes panel of your Count Server.

A symbolicated stack trace of a crash report looks like this:

Before symbolication:

YourAppName                               0x000000010006e174 YourAppName + 156020
YourAppName                               0x000000010006d060 YourAppName + 151648
YourAppName                               0x000000010006ad34 YourAppName + 142644

After symbolication:

-[MHViewController countlyProductionTest] (in YourAppName) (MHViewController.m:620)
-[MHViewController transitionToMahya] (in YourAppName) (MHViewController.m:443)
-[MHViewController textFieldShouldReturn:] (in YourAppName) (MHViewController.m:210)

For more information about how to use Symbolication feature on Countly Server, please see our Symbolication documentation here.

User Profiles

Enterprise Edition Feature

This feature is only available with Enterprise Edition subscription.

You can see detailed user information under User Profiles section of Countly Dashboard by recording user properties.

User Properties

You can record default and custom properties of user details like this:

objectivec swift
//default properties = @"John Doe";
Countly.user.username = @"johndoe"; = @"";
Countly.user.birthYear = @1970;
Countly.user.organization = @"United Nations";
Countly.user.gender = @"M"; = @"+0123456789";

//profile photo
Countly.user.pictureURL = @"";
//or local image on the device
Countly.user.pictureLocalPath = localImagePath;

//custom properties
Countly.user.custom = @{@"testkey1":@"testvalue1",@"testkey2":@"testvalue2"};

[Countly.user save];

Note: Local image specified on pictureLocalPath property will not be persisted exclusively. If request fails and is retried later, local image is expected to be still present on the exactly same path. Otherwise upload will be aborted.

Custom User Property Modifiers

Also, you can use custom user property modifiers like this:

objectivec swift
[Countly.user set:@"key101" value:@"value101"];
[Countly.user setOnce:@"key101" value:@"value101"];
[Countly.user unSet:@"key101"];

[Countly.user increment:@"key102"];
[Countly.user incrementBy:@"key102" value:5];
[Countly.user multiply:@"key102" value:2];

[Countly.user max:@"key102" value:30];
[Countly.user min:@"key102" value:20];

[Countly.user push:@"key103" value:@"singlevalue"];
[Countly.user push:@"key103" values:@[@"a",@"b",@"c",@"d"]];
[Countly.user pull:@"key103" value:@"b"];
[Countly.user pull:@"key103" values:@[@"a",@"d"]];

[Countly.user pushUnique:@"key104" value:@"uniqueValue"];
[Countly.user pushUnique:@"key104" values:@[@"uniqueValue2",@"uniqueValue3"]];

[Countly.user save];

View Tracking

Auto View Tracking

For Countly Auto View Tracking, you'll need to specify CLYAutoViewTracking in features array on CountlyConfig object before starting Countly.

objectivec swift
config.features = @[CLYAutoViewTracking];

After this point Countly iOS SDK will automatically track appeared and disappeared views. It simply intercepts viewDidAppear: method of UIViewController class and reports which view is displayed with view's name and duration. If view controller's title property is set, reported view's name will be the value of title property, otherwise view controller's class name.

You can temporarily enable or disable Auto View Tracking using 'isAutoViewTrackingActive' property.

objectivec swift
Countly.sharedInstance.isAutoViewTrackingActive = NO;

If Auto View Tracking feature is not enabled on initial configuration, enabling or disabling this property later has no effect. It will always be disabled.

Exception View Controllers

By default, following system view controllers will be excluded from auto tracking, as they are not visible views but structural controllers:


In addition to these default exceptions, you can manually add your own exception view controllers using addExceptionForAutoViewTracking: method by passing view controller class name or title:

objectivec swift
[Countly.sharedInstance addExceptionForAutoViewTracking:NSStringFromClass(MyViewController.class)];
[Countly.sharedInstance addExceptionForAutoViewTracking:@"MyViewControllerTitle"];

Added view controller class name or titles will be ignored by Auto View Tracking and their appearances and disappearances will not be reported. Adding an already added view controller class name or title again will have no effect.

As well, you can remove manually added exception view controllers using removeExceptionForAutoViewTracking method by passing view controller class name or title:

objectivec swift
[Countly.sharedInstance removeExceptionForAutoViewTracking:NSStringFromClass(MyViewController.class)];
[Countly.sharedInstance removeExceptionForAutoViewTracking:@"MyViewControllerTitle"];

Removing an already removed (or not yet added) view controller class name or title again will have no effect.

Manual View Tracking

In addition to Auto View Tracking, you can manually record appearance of a view using recordView: method with view's name:

objectivec swift
[Countly.sharedInstance recordView:@"MyView"];

When you record another view later, duration of previous view will be calculated and view tracking event will be recorded automatically.

You can also specify custom segmentation key-value pairs while recording views:


Star Rating

You can optionally set Countly iOS SDK to automatically ask users for a 1-to-5 star-rating, depending on app launch count for each version. For this, you need to set starRatingSessionCount property on CountlyConfig object. When total number of sessions reaches starRatingSessionCount, an alert view asking for 1-to-5 star-rating will be displayed automatically, once for each new version of the app.

objectivec swift
config.starRatingSessionCount = 10;

If you want star-rating dialog to be displayed only once for app lifetime, instead of for each new version, you can set starRatingDisableAskingForEachAppVersion flag on CountlyConfig object.

objectivec swift
config.starRatingDisableAskingForEachAppVersion = YES;

Additionally, you can customize star-rating dialog message using starRatingMessage property on CountlyConfig object. If you do not specify this property explicitly, message will be "How would you rate the app?" or corresponding localized version depending on device language. Currently supported localizations are: English, Turkish, Japanese, Chinese, Russian, Czech, Latvian and Bengali.

objectivec swift
config.starRatingMessage = @"Please rate our app?";

Additionally, you can set starRatingCompletion block property on CountlyConfig object to be executed after star-rating dialog is shown automatically. Completion block has a single NSInteger parameter that indicates 1 to 5 star-rating given by user. If user dismissed dialog without giving a rating, this value will be 0 and it will not be reported to server.

objectivec swift
config.starRatingCompletion = ^(NSInteger rating)
    NSLog(@"rating %d",(int)rating);

Additionally, you can use askForStarRating: method to ask for a star-rating anytime you want. It displays the 1-to-5 star-rating dialog manually and executes completion block after user's action. Completion block takes a single NSInteger parameter that indicates 1 to 5 star-rating given by user. If user dismissed dialog without giving a rating, this value will be 0 and it will not be reported to server. Manually asking for star-rating does not effect automatically asking of star-rating.

objectivec swift
[Countly.sharedInstance askForStarRating:^(NSInteger rating)
    NSLog(@"rating %li",(long)rating);

Feedback Widgets

You can use Countly iOS SDK to display feedback widgets configured on Countly Server. For more information on feedback widgets please visit Ratings & Feedbacks documentation.

Here is how you can utilize feedback widgets in your iOS apps:

Once you call presentFeedbackWidgetWithID:completionHandler: method, feedback widget with given ID will be displayed in a WKWebView placed in a UIViewController.

First, the availability of the feedback widget will be checked asynchronously. If the feedback widget is available, it will be modally presented. Otherwise, completionHandler will be called with an NSError. completionHandler will also be called with nil when feedback widget is dismissed by user.

objectivec swift
[Countly.sharedInstance presentFeedbackWidgetWithID:@"FEEDBACK_WIDGET_ID" completionHandler:^(NSError* error)
    if (error)
        NSLog(@"Feedback widget presentation failed: \n%@\n%@", error.localizedDescription, error.userInfo);
        NSLog(@"Feedback widget presented successfully");

Remote Config

Remote Config feature lets you change the behavior and appearance of your applications anytime without sending an update to the App Store, by creating or updating custom key-value pairs on your Countly Server. You can also create conditions to get different values depending on user criteria. For more details please see Remote Config documentation.

Here is how you can utilize Remote Config feature in your iOS apps:

First you need to enable Remote Config feature on initial configuration:

objectivec swift
config.enableRemoteConfig = YES;

With this, Countly iOS SDK will automatically fetch Remote Config keys and values from Countly Server, when you start it.

You can also set a completion block on initial configuration object, to be informed about the result of remote config fetching process, either with success or failure:

objectivec swift
config.remoteConfigCompletionHandler = ^(NSError * error)
    if (!error)
        NSLog(@"Remote Config is ready to use!");
        NSLog(@"There was an error while fetching Remote Config:\n%@", error);

Once fetched, you can access Remote Config values using remoteConfigValueForKey method:

objectivec swift
id value = [Countly.sharedInstance remoteConfigValueForKey:@"foo"];

if (value) // if value exists, you can use it as you see fit
		NSLog(@"Value %@", [value description]);
else //if value does not exist, you can set your default fallback value
	value = @"Default Value"; 	

Remote Config values are stored on device locally. So, you can access the latest fetched values even while Countly Server is not reachable. If Remote Config is never retrieved from Countly Server before or given key is not defined, this method will return nil. So, you can fallback to your desired default value.

You can also trigger fetching and updating of Remote Config values anytime you want:

objectivec swift
[Countly.sharedInstance updateRemoteConfigWithCompletionHandler:^(NSError * error)
    if (!error)
        NSLog(@"Remote Config is updated and ready to use!");
        NSLog(@"There is an error while updating Remote Config:\n%@", error);

You can also trigger partial updating of Remote Config values you want anytime you want. For updating the values only for the keys you specify:

objectivec swift
[Countly.sharedInstance updateRemoteConfigOnlyForKeys:@[@"key1", @"key2"] completionHandler:^(NSError * error)
    if (!error)
        NSLog(@"Remote Config is updated only for given keys and ready to use!");
        NSLog(@"There is an error while updating Remote Config:\n%@", error);

For updating the values except for the keys you specify:

objectivec swift
[Countly.sharedInstance updateRemoteConfigExceptForKeys:@[@"key3", @"key4"] completionHandler:^(NSError * error)
    if (!error)
        NSLog(@"Remote Config is updated except for given keys and ready to use !");
        NSLog(@"There is an error while updating Remote Config:\n%@", error);

watchOS Integration

Just like iPhones and iPads, collecting and analyzing usage statistics and analytics data from Apple Watch is the key for offering a better experience. Fortunately, Countly iOS SDK has watchOS support. Here you can see how to use Countly iOS SDK in your watchOS apps:

1. First open a new or your existing Xcode project and add a new target by clicking + icon at the bottom of Projects and Targets List . (You can skip to step 4 if your project already has a Watch App, or you can visit for more information)

2. Select target template WatchKit App under watchOS > Application section. Do not choose WatchKit App for watchOS 1. In order to keep things simple, do not include Notification scene, Glance scene or Complication.

3. If Xcode asks if you want to activate WatchKit App scheme, click Activate.

4. Now it is time to add Countly iOS SDK to your project. After cloning the Countly iOS SDK anywhere you want Drag&Drop countly-sdk-ios folder into your Xcode project and in the following dialog please make sure iPhone app target and WatchKit Extension target (not WatchKit App) are selected, as well as Copy items if needed checkbox.

5. Import Countly.h in ExtensionDelegate.m

objectivec swift
#import "Countly.h"

6. Add Countly starting code into applicationDidFinishLaunching method ExtensionDelegate.m

objectivec swift
CountlyConfig* config =;
config.appKey = @"YOUR_APP_KEY"; = @"https://YOUR_COUNTLY_SERVER";
config.enableAppleWatch = YES;
[Countly.sharedInstance startWithConfig:config];

7. Add suspend code into applicationWillResignActive method of ExtensionDelegate.m

objectivec swift
[Countly.sharedInstance suspend];

8. Add resume code into applicationDidBecomeActive method of ExtensionDelegate.m

objectivec swift
[Countly.sharedInstance resume];

9. After adding these three lines of code into related extension delegate methods, try building the project. Everything should be OK now. If you run the watchOS app, you can see the session on your Countly dashboard.

Now you are ready to track your watchOS app with Countly.

By the way, session concept on watchOS is a little bit different than the one on the iOS, as watchOS apps are intended for brief user interaction. So, there are two values you might need to adjust depending on your watch apps use cases.

  • First one is updateSessionPeriod. Its default value is 20 seconds for watchOS while 60 seconds for iOS. This value determines how often session updating requests will be sent to server while the app is in use.
  • Second one is eventSendThreshold which is 3 for watchOS and 10 for iOS by default. Countly iOS SDK waits for the number of recorded unique events to reach this threshold, to deliver them to server until next session updating kicks in. Considering that Apple Watch is designed to be used for short sessions, these values seems proper in general. But you can change them depending on your watchOS app’s scenario.
objectivec swift
config.updateSessionPeriod = 15;
config.eventSendThreshold = 1;

And do not forget to set enableAppleWatch flag of CountlyConfig object on your watch apps iOS counterpart:

objectivec swift
config.enableAppleWatch = YES;

With this setting, iOS counterpart of your watchOS app will be reporting paired Apple Watch's information to server as well.

Note: Please make sure you do not set WCSession.defaultSession's delegate manually, as Countly iOS SDK will be acting as the delegate.


For compatibility with data protection regulations such as GDPR, Countly iOS SDK allows developers to enable/disable any feature at any time, depending on user consent. Currently available features with consent control are:

CLYConsentSessions : sessions CLYConsentEvents : events CLYConsentUserDetails : users CLYConsentCrashReporting : crashes CLYConsentPushNotifications : push CLYConsentLocation : location CLYConsentViewTracking : views CLYConsentAttribution : attribution CLYConsentStarRating : star-rating CLYConsentAppleWatch : accessory-devices

To utilize consents, you should set requiresConsent flag is set on initial configuration.

objectivec swift
config.requiresConsent = YES;

With this flag set, Countly iOS SDK will not collect or send any data automatically, as well as ignoring all manual calls. Until explicit consent is given for a feature, it will be inactive. After giving consent for a feature, it will be started immediately and kept active henceforth.

To give consent for a feature you can use giveConsentForFeature: method, passing the feature name:

objectivec swift
[Countly.sharedInstance giveConsentForFeature:CLYConsentSessions];
[Countly.sharedInstance giveConsentForFeature:CLYConsentEvents];

Or, you can give consent for more than one feature at a time using giveConsentForFeatures: method, passing feature names as an NSArray:

objectivec swift
[Countly.sharedInstance giveConsentForFeatures:@[CLYConsentSessions, CLYConsentEvents];

Or, if you want to give consent for all the features, you can use giveConsentForAllFeatures convenience method:

objectivec swift
[Countly.sharedInstance giveConsentForAllFeatures];

Countly iOS SDK does not persistently store status of given consents. You are expected to handle getting consent from end-users using proper UIs depending on your app's context, and storing them either locally or remotely. Following this, you need to call giving consent methods on each app launch, just after starting Countly iOS SDK, depending on the permissions you managed to get from the end-users.

If the end-user changes his/her mind about consents later, you need to reflect this to Countly iOS SDK, using cancelConsentForFeature: method:

objectivec swift
[Countly.sharedInstance cancelConsentForFeature:CLYConsentSessions];
[Countly.sharedInstance cancelConsentForFeature:CLYConsentEvents];

Or, you can cancel consent for more than one feature at a time using cancelConsentForFeatures: method, passing feature names as an NSArray:

objectivec swift
[Countly.sharedInstance cancelConsentForFeatures:@[CLYConsentSessions, CLYConsentEvents];

Or, if you want to cancel consent for all the features, you can use cancelConsentForAllFeatures convenience method:

objectivec swift
[Countly.sharedInstance cancelConsentForAllFeatures];

Once consent for a feature is cancelled, that feature is stopped immediately and kept inactive henceforth.

Countly iOS SDK reports consent changes to Countly Server, so Countly Server can do preparations or clean-up on server side as well.

Was this article helpful?
0 out of 0 found this helpful

Looking for help?