AppsFlyerLib

Overview

AppsFlyerLib is the main class of the AppsFlyer iOS SDK, and encapsulates most of the methods.

To import AppsFlyerLib:

// AppDelegate.h
#import <AppsFlyerLib/AppsFlyerLib.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, AppsFlyerLibDelegate>

@end
import AppsFlyerLib

Go back to the SDK reference index.

Properties

advertisingIdentifier (read-only)

Property declaration

@property(nonatomic, strong, readonly) NSString *advertisingIdentifier

Description
AppsFlyer SDK collect Apple's advertisingIdentifier if the AdSupport.framework included in the SDK.
You can disable this behavior by setting the disableAdvertisingIdentifier to true.

TypeName
NSStringadvertisingIdentifier

anonymizeUser

Property declaration

@property(atomic) BOOL anonymizeUser;

Description
Opt-out logging for specific user

TypeName
boolanonymizeUser

appInviteOneLinkID

Property declaration

@property(nonatomic, strong, nullable, setter = setAppInviteOneLink:) NSString * appInviteOneLinkID

Description
Set your OneLink ID from OneLink configuration. Used in User Invites to generate a OneLink.

TypeName
NSStringappInviteOneLinkID

appleAppID

Property declaration

@property(nonatomic, strong) NSString * appleAppID

Description
Use this property to set your app’s Apple ID(taken from the app’s page on iTunes Connect)

TypeName
NSStringappleAppID

appsFlyerDevKey

Property declaration

@property(nonatomic, strong) NSString * appsFlyerDevKey

Description
Use this property to set your AppsFlyer dev key.

TypeNameDescription
NSStringappsFlyerDevKeyYour AppsFlyer dev key.

currencyCode

Property declaration

@property(nonatomic, strong, nullable) NSString *currencyCode

Description
In case of in app purchase events, you can set the currency code your user has purchased with.
The currency code is a 3 letter code according to ISO standards.

Usage example

[[AppsFlyerLib shared] setCurrencyCode:@"USD"];
AppsFlyerLib.shared().currencyCode = "USD"

customData

📘

Setting customData before first launch will have the additional data included in installs, sessions, as well as in-app events.

Property declaration

@property(nonatomic, strong, nullable, setter = setAdditionalData:) NSDictionary * customData

Description
Use to add custom data to events' payload. You will receive it in the raw-data reports.

TypeName
NSDictionarycustomData

customerUserID

Property declaration

@property(nonatomic, strong, nullable) NSString * customerUserID

Description
In case you use your own user ID in your app, you can set this property to that ID.
Enables you to cross-reference your own unique ID with AppsFlyer’s unique ID and the other devices’ IDs

TypeName
NSStringcustomerUserID

deepLinkDelegate

Property declaration

@property(weak, nonatomic) id<AppsFlyerDeepLinkDelegate> deepLinkDelegate

Description
Delegate property of an object, that conforms to DeepLinkDelegate protocol and implements its methods.

TypeName
DeepLinkDelegatedeepLinkDelegate

Usage example

AppsFlyerLib.shared().deepLinkDelegate = self

deepLinkTimeout

Description
Request timeout for Deferred Deeplinking.

Units in milliseconds.

Property declaration

@property(nonatomic) NSUInteger deepLinkTimeout
TypeName
NSUIntegerdeepLinkTimeout

delegate

Description
AppsFlyer delegate. See AppsFlyerLibDelegate.
Property declaration

@property (nonatomic, weak) id<AppsFlyerLibDelegate> delegate;
TypeName
AppsFlyerLibDelegatedelegate

disableAdvertisingIdentifier

Property declaration

@property (nonatomic) int disableAdvertisingIdentifier;

Description
If AdSupport.framework isn't disabled, the SDK collects the Apple advertisingIdentifier.
You can disable this behavior by setting the following property to YES.

TypeName
NSStringadvertisingIdentifier

disableAppleAdsAttribution

Property declaration

@property(nonatomic) BOOL disableAppleAdsAttribution

Description

TypeName
booldisableAppleAdsAttribution

disableCollectASA

Property declaration

@property(atomic) BOOL disableCollectASA;

Description
Opt-out of Apple Search Ads attributions.

TypeName
booldisableCollectASA

disableIDFVCollection

Property declaration

@property(nonatomic) BOOL disableIDFVCollection;

Description
To disable app vendor identifier (IDFV) collection, set disableIDFVCollection to YES.

TypeName
booldisableIDFVCollection

disableSKAdNetwork

Property declaration

@property(nonatomic) BOOL disableSKAdNetwork

Description

TypeName
booldisableSKAdNetwork

facebookDeferredAppLink

Property declaration

@property (nonatomic, nullable) int *facebookDeferredAppLink;

Description
Manually set Facebook deferred app link.

TypeName
NSStringadvertisingIdentifier

host (read-only)

Property declaration

@property(nonatomic, strong, readonly) NSString *host

Description
This property accepts a string value representing the host name for all endpoints. To set the host, use setHost.

To use default SDK endpoint – set value to nil.

TypeName
NSStringhost

hostPrefix (read-only)

Property declaration

@property(nonatomic, strong, readonly) NSString *hostPrefix

Description
This property accepts a string value representing the prefix hostname for all endpoints. To set the host, use setHost.

TypeName
NSStringhostPrefix

isDebug

Property declaration

@property(nonatomic) BOOL isDebug;

Description
Prints SDK messages to the console log. Should be disabled for production builds.

TypeName
boolisDebug

isStopped

Property declaration

@property(atomic) BOOL isStopped;

📘

SDK Restart

Set isStopped = true and then set isStopped = false

No need to call start()

Description
API to shut down all SDK activities. This will disable all requests from the SDK except for those related to fetching SKAd Network data from the server.

TypeName
boolisStopped

minTimeBetweenSessions

Property declaration

@property(atomic) NSUInteger minTimeBetweenSessions;

Description
Set a custom value for the minimum required time between sessions.

Input arguments

TypeNameDescription
NSUIntegerminTimeBetweenSessionsSets the minimum time that must pass between two app launches to count as two separate sessions. If not set, the default minimum time between sessions is 5 seconds

oneLinkCustomDomains

Property declaration

@property(nonatomic, nullable) NSArray<NSString *> *oneLinkCustomDomains;

Description
For advertisers who use vanity OneLinks.

TypeName
NSArray<NSString *>oneLinkCustomDomains

phoneNumber

Property declaration

@property(nonatomic, nullable) NSString *phoneNumber

Description

TypeName
NSStringphoneNumber

resolveDeepLinkURLs

Property declaration

@property(nonatomic, nullable) NSArray<NSString *> *resolveDeepLinkURLs;

Description

TypeName
NSArray<NSString *>resolveDeepLinkURLs

Usage example
Some third-party services such as email service providers (ESPs) wrap links in emails with their own click recording domains. Some even allow you to set your own click recording domains. If OneLink is wrapped in such domains, it might limit its functionality.

To overcome this issue, use setResolveDeepLinkURLs to get the OneLink from click domains that launch the app. Make sure to call this API before SDK initialization.

For example, you have three click domains that redirect to your OneLink which is https://mysubdomain.onelink.me/abCD. Use this API to get the OneLink that your click domains redirect to. This API method receives a list of domains that the SDK resolves.

[AppsFlyerLib shared].resolveDeepLinkURLs = @[@"example.com",@"click.example.com"];
AppsFlyerLib.shared().resolveDeepLinkURLs = ["example.com", "click.example.com"]

This allows you to use your click domain while preserving OneLink functionality. The click domains are responsible for launching the app. The API, in turn, gets the OneLink from these click domains, and then you can use the data from this OneLink to deep-link and customize user content.

sharingFilter

Property declaration

@property(nonatomic, nullable) NSArray<NSString *> *sharingFilter;

Description

TypeName
NSArray<NSString *>sharingFilter

shouldCollectDeviceName

Property declaration

@property(nonatomic) BOOL shouldCollectDeviceName;

Description
Set this flag to YES, to collect the current device name(e.g. “My iPhone”).

TypeName
boolshouldCollectDeviceName

useReceiptValidationSandbox

Property declaration

@property (nonatomic) BOOL useReceiptValidationSandbox;

Description
In-app purchase receipt validation Apple environment(production or sandbox).

TypeName
booluseReceiptValidationSandbox

useUninstallSandbox

Property declaration

@property (nonatomic) BOOL useUninstallSandbox;

Description
Set this flag to test uninstall on Apple environment(production or sandbox).

TypeName
booluseUninstallSandbox

Methods

addPushNotificationDeepLinkPath

Method signature

- (void)addPushNotificationDeepLinkPath:(NSArray<NSString *> *)deepLinkPath;
addPushNotificationDeepLinkPath(deepLinkPath: [String])

Description
Adds array of keys, which are used to compose key path to resolve deeplink from push notification payload.

Input arguments

TypeName
NSArray<NSString *>deepLinkPath

Returns
void.

Usage example
Basic configuration:

[AppsFlyerLib shared] addPushNotificationDeepLinkPath:@[@"af_push_link"]]
AppsFlyerLib.shared().addPushNotificationDeepLinkPath(["af_push_link"])

Advanced configuration:

[AppsFlyerLib shared] addPushNotificationDeepLinkPath:@[@"deeply", @"nested", @"deep_link"]]
AppsFlyerLib.shared().addPushNotificationDeepLinkPath(["deeply", "nested", "deep_link"])

This call matches the following payload structure:

{
  "deeply": {
      "nested": {
          “deep_link”: “https://yourdeeplink2.onelink.me”
      }
  }
}

appendParametersToDeepLinkingURL

Method signature

(void)appendParametersToDeepLinkingURLWithString:(NSString *)containsString parameters:(NSDictionary<NSString *, NSString*> *)parameters;
appendParametersToDeeplinkURL(contains: String, parameters: [String : String])

Description
Matches URLs that contain contains as a substring and appends query parameters to them. In case the URL does not match, parameters are not appended to it.

🚧

Call this method before calling start

Input arguments

TypeNameDescription
NSStringcontainsThe string to check in URL.
NSDictionaryparametersParameters to append to the deeplink url after it passed validation.

Returns
void.

continue

Method signature

- (id)continueUserActivity:(id)userActivity
restorationHandler:
(void (^_Nullable)(int *_Nullable))restorationHandler;
AppsFlyerLib.shared().continue(userActivity: NSUserActivity?, restorationHandler: (([Any]?) -> Void)?)

Description
Allow AppsFlyer to handle restoration from an `NSUserActivity. Use this method to handle Universal links.

Input arguments

TypeNameDescription
NSUserActivityuserActivityThe NSUserActivity that was passed to your app delegate
void (^_Nullable)(int *_Nullable)restorationHandlerpass nil

Returns
void.

enableFacebookDeferderedApplinks

Method signature

- (void)enableFacebookDeferredApplinksWithClass:(Class _Nullable)facebookAppLinkUtilityClass;
enableFacebookDeferredApplinks(with:AnyClass?)

Description
Enable the collection of Facebook Deferred AppLinks.

  • Requires Facebook SDK and Facebook app on target/client device.
  • This API must be invoked prior to initializing the AppsFlyer SDK in order to function properly

Input arguments

TypeNameDescription
FBSDKAppLinkUtilityfacebookAppLinkUtilityClass

Returns
void.

getAppsFlyerUID

Method signature

- (NSString *)getAppsFlyerUID;
getAppsFlyerUID()

Description
Get AppsFlyer's unique device ID. The SDK generates an AppsFlyer unique device ID upon app installation. When the SDK is started, this ID is recorded as the ID of the first app install.

Input arguments
This method takes no input arguments.

Returns

TypeDescription
NSStringAppsFlyer internal ID.

getSDKVersion

Method signature

- (NSString *)getSDKVersion;
getSDKVersion()

Description
Get SDK version.

Input arguments
This method takes no input arguments.

Returns

TypeDescription
NSStringThe AppsFlyer SDK version.

handleOpen

Method signature

- (void)handleOpenUrl:(id)url options:(id)options;
AppsFlyerLib.shared().handleOpen(url: URL?, options: [AnyHashable : Any]?)

Description
Call this method from inside of your AppDelegate openURL method.
This method handles URI-scheme for iOS 9 and above.

Input arguments

TypeNameDescription
NSURLurlThe URL that was passed to your app delegate.
AnyHashableoptionsThe options dictionary that was passed to your AppDelegate.

Returns
void.

handlePushNotification

Method signature

- (void)handlePushNotification:(NSDictionary * _Nullable)pushPayload;
AppsFlyerLib.shared().handlePushNotification(pushPayload: [AnyHashable : Any]?)

Description
Enable AppsFlyer to handle a push notification.

Input arguments

TypeNameDescription
AnyHashablepushPayloadThe userInfo from received remote notification. Unless addPushNotificationDeepLinkPath is used, the data must be under the @“af” key.

Returns
void.

logEvent

Method signature

- (void)logEvent:(NSString *)eventName withValues:(NSDictionary * _Nullable)values;
logEvent(eventName: String, withValues: [AnyHashable : Any]?)

Description
Use this method to log an event with event parameters.

Input arguments

TypeNameDescription
NSStringeventNameContains name of event that could be provided from predefined constants
AnyHashablewithValuesdictionary of values for handling by backend

Returns
void.

logEvent

Method signature

- (void)logEventWithEventName:(NSString *)eventName
  eventValues:(NSDictionary<NSString * , id> * _Nullable)eventValues
  completionHandler:(void (^ _Nullable)(NSDictionary<NSString *, id> * _Nullable dictionary, NSError * _Nullable error))completionHandler;
logEvent(eventName: String, withValues: [AnyHashable : Any]?, completionHandler:(([String : Any]?, Error?) -> Void)?)

Description
Use this method to log an event with event parameters, and pass a completion handler to handle event submissions success and failure.

Input arguments

TypeNameDescription
NSStringeventNameContains name of event that could be provided from predefined constants
AnyHashablewithValuesdictionary of values for handling by backend
(^ _Nullable)(NSDictionary<NSString _, id> _ _Nullable dictionary, NSError * _Nullable error))completionHandler

Returns
void.

logLocation

Method signature

- (void)logLocation:(double)longitude latitude:(double)latitude;
logLocation(longitude: Double, latitude: Double)

Description
To log location for geo-fencing. Does the same as code below.

Input arguments

TypeNameDescription
DoublelongitudeThe location longitude
DoublelatitudeThe location latitude

Returns
void.

performOnAppAttribution

Method signature

- (void)performOnAppAttributionWithURL:(NSURL * _Nullable)URL;
performOnAppAttribution(with:URL?)

Description
Used to manually trigger onAppOpenAttribution delegate.

Input arguments

TypeNameDescription
NSURLURLThe parameter to resolve into -[AppsFlyerLibDelegate onAppOpenAttribution:]

Returns
void.

registerUninstall

Method signature

- (void)registerUninstall:(NSData * _Nullable)deviceToken;
registerUninstall(deviceToken: Data?)

Description
Register uninstall - you should register for remote notification and provide AppsFlyer the push device token.

Input arguments

TypeNameDescription
NSDatadeviceTokenThe deviceToken is from didRegisterForRemoteNotificationsWithDeviceToken.

Returns
void.

setConsentData

Method signature

.setConsentData(afConsent: AppsFlyerConsent)
- (void)setConsentData:(AppsFlyerConsent) afConsent

Description

Transfers consent data to the SDK.

Input arguments

TypeNameDescription
AppsFlyerConsentafConsentAn object containing user consent data

setCurrentDeviceLanguage

Method signature

- (void)setCurrentDeviceLanguage:(NSString *)currentDeviceLanguage

Description
Use this method to set the device language in the SDK and pass it to AppsFlyer.

Input arguments

TypeNameDescription
NSStringcurrentDeviceLanguageCurrent device language.

Usage example

NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0]
    [[AppsFlyerLib shared] setCurrentDeviceLanguage: @language];
let language = NSLocale.current.languageCode
AppsFlyerLib.shared().currentDeviceLanguage = language

setHost

Method signature

(void)setHost:(NSString *)host withHostPrefix:(NSString *)hostPrefix;
setHost(host: String, withHostPrefix: String)

Description
This function sets the hostname and prefix hostname for all the endpoints.

Note: Starting with SDK V6.11, if the host value is empty or null, the API call will be ignored.

Input arguments

TypeNameDescription
NSStringhosthostname.
NSStringwithHostPrefixRequired. host prefix.

Returns
void.

Usage example

[[AppsFlyerLib shared] setHost:@"example.com" withHostPrefix:@"my_host_prefix"];
AppsFlyerLib.shared().setHost("example.com", withHostPrefix: "my_host_prefix")

setPartnerData

Method signature

- (void)setPartnerDataWithPartnerId:(NSString * _Nullable)partnerId partnerInfo:(NSDictionary<NSString *, id> * _Nullable)partnerInfo;
setPartnerData(partnerId: String?, partnerInfo: [String : Any]?)

Description
Allows sending custom data for partner integration purposes.

Input arguments

TypeNameDescription
NSStringpartnerIdID of the partner (usually has _int suffix)
NSDictionary<NSString _, id> _ _NullablepartnerInfocustomer data, depends on the integration nature with specific partner

Returns
void.

Usage example

NSDictionary *partnerInfo = @{
 @"puid": @"123456789",
};

[[AppsFlyerLib shared] setPartnerDataWithPartnerId: @"test_int" partnerInfo:partnerInfo];
let partnerInfo = [
  "puid":"123456789",
]

AppsFlyerLib.shared().setPartnerData(partnerId:"test_int", partnerInfo:partnerInfo)

setSharingFilterForPartners

Added in V6.4
Method signature

- (void)setSharingFilterForPartners:(NSArray<NSString *> * _Nullable)sharingFilter;

This function replaces the deprecated setSharingFilterForAllPartners

Description
Lets you configure which partners should the SDK exclude from data-sharing.

Input arguments

TypeNameDescription
NSArray<NSString _> _ _NullablesharingFilterOne or more partner identifiers you wish to exclude. Must include letters/digits and underscores only.

Maximum partner ID length: 45

Note:
To find out the required partner IDs:

  1. Run the Get active integrations API for a list of all active integrations
  2. Use the media_source_name values from the API response as input values to the method partners array.

Exceptions:

  • For Apple Search Ads use Apple Search Ads (and not iossearchads_int).
  • For Twitter, use twitter (and not twitter_int)

Usage example

[[AppsFlyerLib shared] setSharingFilterForPartners:@[@"examplePartner1_int"]]; // 1 partner
[[AppsFlyerLib shared] setSharingFilterForPartners:@[@"examplePartner1_int", @"examplePartner2_int"]]; // multiple partners
[[AppsFlyerLib shared] setSharingFilterForPartners:@[@"all"]]; // All partners
[[AppsFlyerLib shared] setSharingFilterForPartners:nil]; // Reset list (default)
AppsFlyerLib.shared().setSharingFilterForPartners(["examplePartner1_int"]) // 1 partner
AppsFlyerLib.shared().setSharingFilterForPartners(["examplePartner2_int", "examplePartner1_int"]) // multiple partners
AppsFlyerLib.shared().setSharingFilterForPartners(["all"]) // All partners
AppsFlyerLib.shared().setSharingFilterForPartners(nil) // Reset list (default)

setSharingFilterForAllPartners

Deprecated in V6.4
Method signature

- (void)setSharingFilterForAllPartners;
setSharingFilterForAllPartners()

This function is deprecated and has been replaced by setSharingFilterForPartners

Description
Block an event from being shared with integrated partners.

Input arguments
This method takes no input arguments.

Returns
void

setUserEmails

Method signature

- (void)setUserEmails:(NSArray<NSString *> * _Nullable)userEmails withCryptType:(EmailCryptType)type;
setUserEmails(userEmails: [String]?, with: EmailCryptType)

Description
Use this to set the user email(s).
Note: MD-5 and SHA-1 encryption types are deprecated starting with SDK V6.9.0. Currently, only SHA-256 and NONE are supported.

Input arguments

TypeNameDescription
NSArray<NSString *>userEmailsEmail array.
EmailCryptTypetypeEncryption type.

Returns
void.

shared

Method signature

(AppsFlyerLib *)shared;

Description
Gets the singleton instance of the AppsFlyerLib class, creating it if necessary.

Usage example

AppsFlyerLib.shared()

start

Method signature

- (void)start;
(void) start()

Description
Starts the SDK.

Input arguments
This method takes no input arguments.

Returns
void.

start

Method signature

- (void)startWithCompletionHandler:(void (^ _Nullable)(NSDictionary<NSString *, id> * _Nullable dictionary, NSError * _Nullable error))completionHandler;
start(completionHandler: (([String : Any]?, Error?) -> Void)?)

Description
Start the SDK with a completion handler.

Input arguments

TypeNameDescription
void (^ _Nullable)(NSDictionary<NSString _, id> _ _Nullable dictionary, NSError * _Nullable error)completionHandler

Returns
void.

validateAndLogLogInAppPurchase

Method signature

- (void)validateAndLogInAppPurchase:(id)productIdentifier
price:(id)price
 currency:(id)currency
transactionId:(id)transactionId
additionalParameters:(id)params
success:(void (^_Nullable)(int *))successBlock
failure:
(void (^_Nullable)(int *_Nullable,
 id _Nullable))failedBlock;
validateAndLog(inAppPurchase: String?, price: String?, currency: String?, transactionId: String?, additionalParameters: [AnyHashable : Any]?, success: ([AnyHashable : Any]) -> Void)?, failure: ((Error?, Any?) -> Void)?)

Description
To log and validate in-app purchases you can call this method from the [completeTransaction] method in your SKPaymentTransactionObserver.

Input arguments

TypeNameDescription
NSStringproductIdentifierinAppPurchase in Swift.
NSStringprice
NSStringcurrency
NSStringtransactionId
NSDictionaryadditionalParameters
void (^_Nullable)(int *))successBlocksuccessBlockCompletion handler for successful logging and validation.
void (^_Nullable)(int *_Nullable, id _Nullable))failedBlockCompletion handler for failure in logging and validation.

Returns
void.

waitForATTUserAuthorization

Method signature

- (void)waitForATTUserAuthorizationWithTimeoutInterval:(id)timeoutInterval;
waitForATTUserAuthorization(timeoutInterval:)

Description
Waits for request user authorization to access app-related data

Input arguments

TypeNameDescription
NSIntegertimeoutInterval

Usage example

if (@available(iOS 14, *)) {
        [[AppsFlyerLib shared] waitForATTUserAuthorizationWithTimeoutInterval:60];
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status){
        }];
    }
if #available(iOS 14, *) {
            AppsFlyerLib.shared().waitForATTUserAuthorization(withTimeoutInterval: 60)
            ATTrackingManager.requestTrackingAuthorization { (status) in
            }
        }

Returns
void.