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

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.

Type

Name

Description

NSString

advertisingIdentifier

anonymizeUser

Property declaration

@property(atomic) BOOL anonymizeUser;

Description
Opt-out logging for specific user

Type

Name

Description

bool

anonymizeUser

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.

Type

Name

Description

NSString

appInviteOneLinkID

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)

Type

Name

Description

NSString

appleAppID

appsFlyerDevKey

Property declaration

@property(nonatomic, strong) NSString * appsFlyerDevKey

Description
Use this property to set your AppsFlyer dev key.

Type

Name

Description

NSString

appsFlyerDevKey

Your 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

Property declaration

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

Description
In case you use custom data and you want to receive it in the raw reports.
See Setting additional custom data for more information.

Type

Name

Description

NSDictionary

customData

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

Type

Name

Description

NSString

customerUserID

deepLinkDelegate

Property declaration

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

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

Type

Name

Description

DeepLinkDelegate

deepLinkDelegate

Usage example

AppsFlyerLib.shared().deepLinkDelegate = self

deepLinkTimeout

Property declaration

@property(nonatomic) NSUInteger deepLinkTimeout

Description

Type

Name

Description

NSUInteger

deepLinkTimeout

delegate

Description
AppsFlyer delegate. See AppsFlyerLibDelegate.
Property declaration

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

Type

Name

Description

AppsFlyerLibDelegate

delegate

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.

Type

Name

Description

NSString

advertisingIdentifier

disableAppleAdsAttribution

Property declaration

@property(nonatomic) BOOL disableAppleAdsAttribution

Description

Type

Name

Description

bool

disableAppleAdsAttribution

disableCollectASA

Property declaration

@property(atomic) BOOL disableCollectASA;

Description
Opt-out of Apple Search Ads attributions.

Type

Name

Description

bool

disableCollectASA

disableIDFVCollection

Property declaration

@property(nonatomic) BOOL disableIDFVCollection;

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

Type

Name

Description

bool

disableIDFVCollection

disableSKAdNetwork

Property declaration

@property(nonatomic) BOOL disableSKAdNetwork

Description

Type

Name

Description

bool

disableSKAdNetwork

facebookDeferredAppLink

Property declaration

@property (nonatomic, nullable) int *facebookDeferredAppLink;

Description
Manually set Facebook deferred app link.

Type

Name

Description

NSString

advertisingIdentifier

host

Property declaration

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

Description
This property accepts a string value representing the host name for all endpoints.
Can be used to Zero rate your application’s data usage. Contact your CSM for more information.

To use default SDK endpoint – set value to nil.

Type

Name

Description

NSString

host

Usage example

[[AppsFlyerLib shared] setHost:@"example.com"];
AppsFlyerLib.shared().host = "example.com"

hostPrefix

Property declaration

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

Description
This property accepts a string value representing the prefix hostname for all endpoints.

Type

Name

Description

NSString

hostPrefix

If hostPrefix is “test” and the default hostname is used, the resulting address is “test.appsflyer.com”.

isDebug

Property declaration

@property(nonatomic) BOOL isDebug;

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

Type

Name

Description

bool

isDebug

Defaults to NO.

isStopped

Property declaration

@property(atomic) BOOL isStopped;

Description
API to shut down all SDK activities. This will disable all requests from the SDK.

Type

Name

Description

bool

isStopped

minTimeBetweenSessions

Property declaration

@property(atomic) NSUInteger minTimeBetweenSessions;

Description
This property is responsible for timeout between sessions in seconds.

Type

Name

Description

NSUInteger

minTimeBetweenSessions

Default value is 5 seconds.

oneLinkCustomDomains

Property declaration

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

Description
For advertisers who use vanity OneLinks.

Type

Name

Description

NSArray<NSString *>

oneLinkCustomDomains

phoneNumber

Property declaration

@property(nonatomic, nullable) NSString *phoneNumber

Description

Type

Name

Description

NSString

phoneNumber

resolveDeepLinkURLs

Property declaration

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

Description

Type

Name

Description

NSArray<NSString *>

resolveDeepLinkURLs

sharingFilter

Property declaration

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

Description

Type

Name

Description

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”).

Type

Name

Description

bool

shouldCollectDeviceName

Defaults to NO.

useReceiptValidationSandbox

Property declaration

@property (nonatomic) BOOL useReceiptValidationSandbox;

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

Type

Name

Description

bool

useReceiptValidationSandbox

Defaults to NO.

useUninstallSandbox

Property declaration

@property (nonatomic) BOOL useUninstallSandbox;

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

Type

Name

Description

bool

useUninstallSandbox

Defaults to NO.

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

Type

Name

Description

NSArray<NSString *>

deepLinkPath

Keys to search for deeplink in payload

Returns
void.

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.

Input arguments

Type

Name

Description

NSString

contains

The string to check in URL.

NSDictionary

parameters

Parameters 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

Type

Name

Description

NSUserActivity

userActivity

The NSUserActivity that was passed to your app delegate

void (^_Nullable)(int *_Nullable)

restorationHandler

pass 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

Type

Name

Description

FBSDKAppLinkUtility

facebookAppLinkUtilityClass

Returns
void.

Method signature

[[AppsFlyerLib shared] enableFacebookDeferredApplinksWithClass:[FBSDKAppLinkUtility class]]
AppsFlyerLib.shared().enableFacebookDeferredApplinks(with: FBSDKAppLinkUtility.self)

getAppsFlyerUID

Method signature

- (NSString *)getAppsFlyerUID;
getAppsFlyerUID()

Description
This method returns AppsFlyer’s internal id (unique for your app).

Input arguments
This method takes no input arguments.

Returns

Type

Description

NSString

AppsFlyer internal ID.

getSDKVersion

Method signature

- (NSString *)getSDKVersion;
getSDKVersion()

Description
Get SDK version.

Input arguments
This method takes no input arguments.

Returns

Type

Description

NSString

The 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

Type

Name

Description

NSURL

url

The URL that was passed to your app delegate.

AnyHashable

options

The 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

Type

Name

Description

AnyHashable

pushPayload

The 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

Type

Name

Description

NSString

eventName

Contains name of event that could be provided from predefined constants

AnyHashable

withValues

dictionary 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

Type

Name

Description

NSString

eventName

Contains name of event that could be provided from predefined constants

AnyHashable

withValues

dictionary 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

Type

Name

Description

Double

longitude

The location longitude

Double

latitude

The location latitude

Returns
void.

performOnAppAttribution

Method signature

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

Description
Used to manually trigger onAppOpenAttribution delegate.

Input arguments

Type

Name

Description

NSURL

URL

The 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

Type

Name

Description

NSData

deviceToken

The deviceToken is from didRegisterForRemoteNotificationsWithDeviceToken.

Returns
void.

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

Type

Name

Description

NSString

currentDeviceLanguage

Current 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:(id)host withHostPrefix:(id)hostPrefix;
setHost(host: String, withHostPrefix: String)

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

Input arguments

Type

Name

Description

NSString

host

hostname.

NSString

withHostPrefix

host prefix.

Returns
void.

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

Type

Name

Description

NSString

partnerId

ID of the partner (usually has _int suffix)

NSDictionary<NSString *, id> * _Nullable

partnerInfo

customer 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;

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

Input arguments

Type

Name

Description

NSArray<NSString *> * _Nullable

sharingFilter

One or more partner identifiers you wish to exclude. Must include letters/digits and underscores only.

Maximum partner ID length: 45

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()

Description
Block an event from being shared with integrated partners. This method overwrites -[setSharingFilter](#setsharingfilter).

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).

Input arguments

Type

Name

Description

NSArray<NSString *>

userEmails

Email array.

EmailCryptType

type

Encryption 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

Type

Name

Description

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

completionHandler

Returns
void.

validateAndLog

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

Type

Name

Description

NSString

productIdentifier

inAppPurchase in Swift.

NSString

price

NSString

currency

NSString

transactionId

NSDictionary

additionalParameters

void (^_Nullable)(int *))successBlock

successBlock

Completion handler for successful logging and validation.

void (^_Nullable)(int *_Nullable, id _Nullable))

failedBlock

Completion 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

Type

Name

Description

NSInteger

timeoutInterval

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.


Did this page help you?