Getting Started with iOS
Specific configuration IDs and attribute code names are required to process app data into your Salesforce Audience Studio account. Contact your Salesforce Audience Studio representative for this information.
- site Config id
- exact attribute code names
- event ids (if needed)
- transaction attributes codes (if enabled)
iOS Setup
See instructions to download the Audience Studio framework
- Unzip the framework zip file provided by Audience Studio team.
- Copy iOSKruxLibUniversal.framework to your apps root folder.
- Open Xcode where you are developing the mobile app.
- Drag iOSKruxLibUniversal.framework into Xcode. This opens a popup as shown below:
- The Audience Studio Framework becomes part of your app as shown below
- The following dependent frameworks are required to use the Audience Studio framework:
- SystemConfiguration.framework
- AdSupport.framework
Audience Studio supports collecting location data in lat/long coordinates as a page attribute, but needs to configured in advanced in Audience Studio.
- Contact your Salesforce Audience Studio representative to enable the specific confID used in app to location_services_enabled.
- Add CoreLocation.framework to app
- Add the key NSLocationWhenInUseUsageDescription to the info.plist file of the application in order to request user's permission for iOS 8.0 and above.
Initializing KruxTracker in iOS
To start integration with the Audience Studio iOS SDK, import KruxTracker from the iOSKruxLibUniversal framework as shown below:
#import <iOSKruxLibUniversal/KruxTracker.h>
For Objective-C apps, KruxTracker must be imported by any file using the Audience Studio framework.
For Swift app, KruxTracker needs to be imported in a file named <App-name>-Bridging-Header.h. Then, it would be available to be used in any of the swift files without any import statements. Refer to https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html for more details.
Audience Studio will provide every app with a unique ConfigID which is generated in Audience Studio. This can be generated in Audience Studio or a Salesforce Audience Studio representative will help you get one for your app.
You should use that to initialize the KruxTracker. If you initialize without a ConfigID, the KruxTacker will not be initialized properly. If you use the wrong ConfigID, you will not be able to send the data to Audience Studio servers.
KruxTracker is a singleton and must be initialized with the ConfigID before being used to send data. Initialize it in the AppDelegate file as shown below so that it is available as soon as the app launches.
In Objective-C
In Swift
The initialization sets the default values and starts the scheduler that fetches the Audience Studio Config and segments every 30 minutes. There is a time interval restriction of 30 minutes on fetching config and segments. All these calls are performed in background threads and does not impact the main thread.
The debug and dryRun flags are useful for testing purposes. Please use them only during the development phase. They must be turned off before the final submission of the app.
Sending data to Audience Studio from iOS apps
KruxTracker exposes three methods to send data to Audience Studio servers. All calls are made asynchronously and will not impact the latency and stability of the core mobile app.
A queue is used to store requests when network or Audience Studio Config is unavailable. Queued data is sent when the user gets back network and the Audience Studio Config. The queue has a limit of 200 requests and stores the most recent ones when that limit is reached. Every config maps to a “site” in Audience Studio.
trackPageView
in iOS
The trackPageView
method helps app developers send user actions performed on apps to Audience Studio. These user actions need to specify a URL and a set of attributes Salesforce Audience Studio should track.
The URL sent is shown as a “section” in Audience Studio and the attributes are displayed as page or user attributes.
Example News-based App in iOS using Audience Studio
The trackPageView method helps app developers send user actions performed on apps to Audience Studio. These user actions need to specify a URL and a set of attributes Audience Studio needs to track.
The first argument is shown as a “section” in Audience Studio and the attributes can be either a page or user attributes.
Implement trackPageView
at least once for all users to report the app/site in Unique Trend report in Audience Studio UI
After determining the attributes to collect, send those exact names to your Solutions Manager for activation. Doing so adds the names to your attribute tree and segment creation in Audience Studio.
For the news-based app example you would call trackPageView
at the following places:
- User opens the iOS app For Objective-C:
For Swift:// Create a dictionary of page attributes NSDictionary *pageAttr = [[NSDictionary alloc] initWithObjectsAndKeys: :@"open_app", @"action", nil]; // Create a dictionary of user attributes NSDictionary *userAttr = [[NSDictionary alloc] init]; // Initialize Krux Tracker [[AppDelegate getKruxTracker] trackPageView:@"Home_Page" pageAttributes:pageAttr userAttributes:userAttr];
// Create Page attribute. let pageAttr = ["action": "open", "screen": "home"] // Create User attributes in applicable // Initialize Krux Tracker (AppDelegate.getKruxTracker()).trackPageView("Home_Page", pageAttributes:pageAttr, userAttributes:nil)
- User reads an "Entertainment" Article For Objective C:
For Swift:// Send Entertainment article // article_read is the page attribute and 'Entertainment' is its value NSDictionary *pageAttr = [[NSDictionary alloc] initWithObjectsAndKeys: :@"Entertainment", @"article_read", nil]; NSMutableDictionary *userAttr = [[NSMutableDictionary alloc] init]; [[AppDelegate getKruxTracker] trackPageView:@"Article_Page" pageAttributes:pageAttr userAttributes:userAttr];
// Send Entertainment article // article_read is the page attribute and 'Entertainment' is its value let pageAttr = ["article_read": "Entertainment"] (AppDelegate.getKruxTracker()).trackPageView("Article_Page", pageAttributes:pageAttr, userAttributes:nil)
- User logs in and reads a “Sports” Article For Objective C:
For Swift:// Send Sports article // article_read is the page attribute and 'Sports' is its value // login id is a user attribute(12345 in this example) and loginId is how we are going to represent it in Krux NSDictionary *pageAttr = [[NSDictionary alloc] initWithObjectsAndKeys: @"Sports", @"article_read", nil]; NSDictionary *userAttr = [[NSDictionary alloc] initWithObjectsAndKeys: :@"12345", @"loginId", nil]; [[AppDelegate getKruxTracker] trackPageView:@"Article_Page" pageAttributes:pageAttr userAttributes:userAttr];
// Send Sports article // article_read is the page attribute and 'Sports' is its value // login id is a user attribute(12345 in this example) and loginId is how we are going to represent it in Krux let pageAttr = ["article_read": "Sports"] let userAttr = ["loginId": "12345"] (AppDelegate.getKruxTracker()).trackPageView("Article_Page", pageAttributes: pageAttr, userAttributes: userAttr)
PLEASE NOTE: If you wish to pass more than one attribute value to a single attribute in the pixel call, please make sure the values are comma-separated when passing them.
FireEvent
in iOS
Audience Studio users can create events in the UI. They can then use the fireEvent
method to send information about an event to Audience Studio.
The first parameter of this method should be the unique id of the event that publisher wants to track. If the event contains attributes, you can send their values via this method call. The fireEvent
method must be called if you created an event in the "People > Actions - Manage Events" section of Audience Studio UI.
For example, if you created an event with unique id ‘HsdfRt12
,’ and created an attribute that you want to send data with that event ‘article_category
’. You might want to fire this event every time someone goes to a new article category.
For that case, you can call fireEvent
similarly:
In Objective C:
NSDictionary *attrs = [[NSDictionary alloc] initithObjectsAndKeys: @"Entertainment", @"article_category", nil];
[[AppDelegate getKruxTracker] fireEvent:@"HsdfRt12" eventAttributes:attrs withError:&err];
In Swift:
let attrs =["article_category": "Entertainment"]
do {
try (AppDelegate.getKruxTracker()).fireEvent("HsdfRt12", eventAttributes:attrs)
}
catch {
print(“Error: %@”,error)
}
TrackTransaction
iOS
This feature must be enabled to your account.
See description and requirements for Transaction segments.
Audience Studio users can send transaction data which includes an actual e-commerce purchase. The attributes that need to be sent with this data are “price”, “quantity” and “orderDate”. Please note that these names are configurable in Audience Studio and you should talk to you Salesforce Audience Studio representative to get the names of these attributes.
In the example below, we are using “totalPrice”, “quantity” and “dateOrder” as the attributes which correspond to “price”, “quantity” and “orderDate”.
Note that this is a just an example and you implementation will differ based off your settings in Audience Studio.
In Objective C:
NSDictionary *attr = [[NSDictionary alloc] initithObjectsAndKeys: :@"1000", @"totalPrice", @"5", @"quantity", @"2016-07-15", @"dateOrder" nil];
[[AppDelegate getKruxTracker] trackTransactionWithAttributes:attr];
In Swift:
let attr = ["totalPrice ": "1000", "quantity": "5", "dateOrder": "2016-07-15"];
(AppDelegate.getKruxTracker()).trackTransactionWithAttributes(attr)
Fetching data from Audience Studio for iOS Apps
KruxTracker
gathers information about Audience Studio user segments that a particular user might be a part of. This information is fetched asynchronously in the background when the tracker is initialized. App developers can use this information to customize the content or show the right ad to the user.
In ObjectiveC
[[AppDelegate getKruxTracker] getSegments]
In Swift
(AppDelegate.getKruxTracker()).getSegments()
Initialize KruxTracker during app open for segments to be available as early as possible during app usage.
Helper methods
On initialization, KruxTracker starts a scheduler that fetches config and segments every 30 minutes. The below methods are exposed but should not be used explicitly unless you want to control when the config and segments are fetched. We strongly recommend that you do not call these methods unless you want to be able to control the timing when config and segments are fetched.
There are two helper methods exposed to handle this scheduler:
In Objective-C,
[[AppDelegate getKruxTracker] startScheduler];[[AppDelegate getKruxTracker] stopScheduler];
In Swift,
(AppDelegate.getKruxTracker()).startScheduler()(AppDelegate.getKruxTracker()).stopScheduler()
To get the current version number of the Audience Studio SDK:
In Objective-C,
[[AppDelegate getKruxTracker] getKruxSDKVersionNo];
In Swift
(AppDelegate.getKruxTracker()).getKruxSDKVersionNo()
Consent Capture, Lookup, Consumer Remove, & Portability
This documentation supports SDK specific enhancements made as part of feature releases to support Consumer Rights Management. Please read supporting documentation on Consumer Rights Management features on Zendesk, here.
Many data protection and privacy regulations require you and your company to obtain consent from users before collecting data about them, to honor users' requests for how you use their data, to honor users’ right to be forgotten and to export users’ personal data when users request it. The SDK includes the following four methods as it relates to consent and consumer requests: - (void) consentSetRequest:(NSDictionary *)consentSetAttributes;
- (void) consentGetRequest:(NSDictionary *)consentGetAttributes;
-
(void)
consumerRemoveRequest:(NSDictionary *)consumerRemoveAttributes;
-
(void)
consumerPortabilityRequest:(NSDictionary *)consumerPortabilityAttributes;
The consentSetRequest
method accepts the following parameters:
Parameter | Description |
idt | Identification Type |
dt | Device Type |
idv | Identification Value |
pr | Policy Regime |
dc | Data Collection |
al | Analytics |
tg | Targeting |
cd | Cross Device |
sh | Sharing Data |
re | ReIdentification |
The consentGetRequest
method accepts the following parameters:
Parameter | Description |
idt | Identification Type |
dt | Device Type |
idv | Identification Value |
pr | Policy Regime |
The consumerRemoveRequest and consumerPortabilityRequest
methods accept the following parameters:
Parameter | Description |
idt | Identification Type |
dt | Device Type |
idv | Identification Value |
For additional information about the meaning of and supported values for these parameters, please consult the glossary of terms, here.idt
, dt
and idv
are user identification parameters that Audience Studio uses to manage Consumer Rights activities. Providing identification parameters is optional with the SDK; In absence of identification parameters, the SDK defaults to using idt=device
and dt=idfa
.
If any user identification parameters (idt
, dt
, or idv)
are provided, the caller must provide all identification parameters. If any one of them is missing, a "Wrong Identification Parameters" error is returned through callback.
These methods are implemented in an asynchronous fashion. If you want to handle response and/or errors for these requests, please implement the KruxConsentCallback
protocol, and provide its object as a parameter while initializing the SDK.
The SDK will forward response/error for a particular consent request by calling one of the methods of this consent callback object. The SDK is backward compatible, so you do not need to change application code if you don’t want to handle consent/consumer response/error messages.
Response Messages
Please refer to Consent and Consumer Webservice documentation here for more detail.
Error Messages
There are various error conditions under which consent set/get request might not be processed. A few examples of these situations are network not available, and an SDK internal error. For all of these errors, there will be one single message forwarded to client application through callback implementation. That message is "Could not process consent/consumer request".
If the consent/consumer service responds with an http error then that error will be forwarded to the application.
SDK in-memory consent management
- SDK runs a scheduler to fetch consent values every 30 minutes. So, if the consent settings are set using e.g., file upload, then consent values will be updated correctly.
- SDK is concerned only with the data collection field. Based on this value, it will decide whether to collect data or not.
- SDK manages in-memory consent record. This consent record gets updated either by a scheduler or whenever user sets the consent values by calling consent set method.
- SDK logs a warning message every 30 minutes if explicit consent via file upload, SDK interface, or an API call is not found.
Code snippet for KruxConsentCallback
protocol
@protocol KruxConsentCallback <NSObject>
- (void) handleConsentGetResponse:(NSString *) consentGetResponse;
- (void) handleConsentGetError:(NSString *) consentGetError;
- (void) handleConsentSetResponse:(NSString *) consentSetResponse;
- (void) handleConsentSetError:(NSString *) consentSetError;
- (void) handleConsumerRemoveResponse:(NSString *) consumerRemoveResponse;
- (void) handleConsumerRemoveError:(NSString *) consumerRemoveError;
- (void) handleConsumerPortabilityResponse:(NSString *) consumerPortabilityResponse;
- (void) handleConsumerPortabilityError:(NSString *) consumerPortabilityError;
@end
Objective C code snippet to call consent/consumer methods
- (void) sendRequests
{
NSDictionary *consentSetAttributes = [self getConsentAttributes];
NSDictionary *idAttributes = [self getIdParameters];
NSDictionary *consentGetAttributes = [self getIdParameters];
[self addPolicyRegimeParameter:consentGetAttributes];
[self addPolicyRegimeParameter:consentSetAttributes];
[[AppDelegate getKruxTracker] consentGetRequest:consentGetAttributes];
[[AppDelegate getKruxTracker] consentSetRequest:consentSetAttributes];
[[AppDelegate getKruxTracker] consumerRemoveRequest:idAttributes];
[[AppDelegate getKruxTracker] consumerPortabilityRequest:idAttributes];
}
- (void) addPolicyRegimeParameter: (NSDictionary *) attributes
{
[attributes setValue:@"gdpr" forKey:@"pr"];
}
- (NSDictionary *) getIdParameters
{
NSDictionary *consentAttributes = [[NSDictionary alloc] init];
[consentAttributes setValue:@"<idfa-value>" forKey:@"idv"];
[consentAttributes setValue:@"idfa" forKey:@"dt"];
[consentAttributes setValue:@"device" forKey:@"idt"];
return consentAttributes;
}
- (NSDictionary *) getConsentAttributes
{
NSMutableDictionary *consentAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:1], @"dc",
[NSNumber numberWithInt:1], @"cd",
[NSNumber numberWithInt:1], @"tg",
[NSNumber numberWithInt:1], @"al",
[NSNumber numberWithInt:1], @"sh",
[NSNumber numberWithInt:1], @"re", nil];
[consentAttributes addEntriesFromDictionary:[self getIdParameters]];
return consentAttributes;
}
Objective C code snippet containing KruxConsentCallback
implementationKruxConsentCallbackImpl.h
#import <iOSKruxLibUniversal/KruxConsentCallback.h>
@interface KruxConsentCallbackImpl : NSObject<KruxConsentCallback>
@end
KruxConsentCallbackImpl.m
#import <Foundation/Foundation.h>
#import "KruxConsentCallbakImpl.h"
@interface KruxConsentCallbackImpl()
@end
@implementation KruxConsentCallbackImpl
- (void) handleConsentGetResponse:(NSString *) consentGetResponse {
NSLog(@"Consent Get Response: %@", consentGetResponse);
}
- (void) handleConsentGetError:(NSString *) consentGetError {
NSLog(@"Consent Get Error: %@", consentGetError);
}
- (void) handleConsentSetResponse:(NSString *) consentSetResponse {
NSLog(@"Consent Set Response: %@", consentSetResponse);
}
- (void) handleConsentSetError:(NSString *) consentSetError {
NSLog(@"Consent Set Error: %@", consentSetError);
}
- (void) handleConsumerRemoveResponse:(NSString *) consumerRemoveResponse {
NSLog(@"Consumer Remove Response: %@", consumerRemoveResponse);
}
- (void) handleConsumerRemoveError:(NSString *) consumerRemoveError {
NSLog(@"Consumer Remove Error: %@", consumerRemoveError);
}
- (void) handleConsumerPortabilityResponse:(NSString *) consumerPortabilityResponse {
NSLog(@"Consumer Portability Response: %@", consumerPortabilityResponse);
}
- (void) handleConsumerPortabilityError:(NSString *) consumerPortabilityError {
NSLog(@"Consumer Portability Error: %@", consumerPortabilityError);
}
@end
Objective C code snippet containing SDK initialization with KruxConsentCallback
parameter
@implementation AppDelegate
static KruxTracker *kt;
+ (KruxTracker *)getKruxTracker {
return kt;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
KruxConsentCallbackImpl *consentCallback = [[KruxConsentCallbackImpl alloc] init];
kt = [KruxTracker sharedEventTrackerWithConfigId:@"REPLACE_WITH_YOUR_CONFID" debugFlag:true dryRunFlag:false consentCallback:consentCallback];
return YES;
}
Swift code snippet to call consent/consumer methods
func sendRequests() {
var consentSetAttributes = self.getConsentAttributes();
let idAttributes = self.getIdParameters()
var consentGetAttributes = self.getIdParameters()
self.addPolicyRegimeParameter(attributes: &consentSetAttributes)
self.addPolicyRegimeParameter(attributes: &consentGetAttributes)
(AppDelegate.getKruxTracker()).consentGetRequest(consentGetAttributes)
(AppDelegate.getKruxTracker()).consentSetRequest(consentSetAttributes)
(AppDelegate.getKruxTracker()).consumerRemoveRequest(idAttributes)
(AppDelegate.getKruxTracker()).consumerPortabilityRequest(idAttributes)
}
func addPolicyRegimeParameter( attributes:inout [String:Any]) {
attributes["pr"] = "gdpr";
}
func getIdParameters() -> [String:Any] {
var consentAttributes : [String:Any] = [:]
consentAttributes["idv"] = "REPLACE_WITH_IDFA_VALUE"
consentAttributes["dt"] = "idfa"
consentAttributes["idt"] = "device"
return consentAttributes
}
func getConsentAttributes() -> [String:Any] {
var consentAttributes : [String:Any] = [:]
consentAttributes["dc"] = 1
consentAttributes["cd"] = 1
consentAttributes["tg"] = 1
consentAttributes["al"] = 1
consentAttributes["sh"] = 1
consentAttributes["re"] = 1
let idParams = self.getIdParameters()
idParams.forEach { (k,v) in consentAttributes[k] = v }
return consentAttributes
}
Swift code snippet containing KruxConsentCallback
implementationKruxConsentCallbackImpl.swift
import Foundation
@objc class KruxConsentCallbackImpl: NSObject, KruxConsentCallback {
func handleConsentGetResponse(_ consentGetResponse: String) {
NSLog("Consent Get Response: %@", consentGetResponse as NSString)
}
func handleConsentGetError(_ consentGetError: String!) {
NSLog("Consent Get Error: %@", consentGetError as NSString)
}
func handleConsentSetResponse(_ consentSetResponse: String!) {
NSLog("Consent Set Response: %@", consentSetResponse as NSString)
}
func handleConsentSetError(_ consentSetError: String!) {
NSLog("Consent Set Error: %@", consentSetError as NSString)
}
func handleConsumerRemoveResponse(_ consumerRemoveResponse: String!) {
NSLog("Consumer Remove Response: %@", consumerRemoveResponse as NSString)
}
func handleConsumerRemoveError(_ consumerRemoveError: String!) {
NSLog("Consumer Remove Error: %@", consumerRemoveError as NSString)
}
func handleConsumerPortabilityResponse(_ consumerPortabilityResponse: String!) {
NSLog("Consumer Portability Response: %@", consumerPortabilityResponse as NSString)
}
func handleConsumerPortabilityError(_ consumerPortabilityError: String!) {
NSLog("Consumer Portability Error: %@", consumerPortabilityError as NSString)
}
}
Swift code snippet containing SDK initialization with KruxConsentCallback
parameter
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
static var kt: KruxTracker!
static var consentCallback:KruxConsentCallback!
static func getKruxTracker() -> KruxTracker {
return kt
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
AppDelegate.consentCallback = KruxConsentCallbackImpl()
AppDelegate.kt = KruxTracker.sharedEventTracker(withConfigId: "REPLACE_WITH_YOUR_CONFID", debugFlag: true,
dryRunFlag: false, consentCallback:AppDelegate.consentCallback)
return true
}
}
Debugging/Testing in iOS
KruxTracker exposes two parameters to help you ensure that you are able to send data to backend servers properly. They are:
debugFlag:true
This outputs debug messages while it is trying to fetch data/send data to Audience Studio backend servers. You should turn this off before the final submission of your app.
dryRunFlag: true
This does a dryRun
without sending any data to the Audience Studio servers. This is useful while you are developing an app. You should turn this off before the final submission of your app.
Upgrading to Audience Studio iOS SDK version 4.0.1
Initialization of KruxTracker
In the version 4.0.1, KruxTracker is a singleton that must be initialized with the unique config Id provided by Audience Studio. If you initialize without a configID, the KruxTacker will not be initialized and if you use the wrong configID, you will not be able to send the data to Audience Studio servers. It also takes debug and dryRun flags that are useful for testing purposes and must be set to false before the final submission of the app. It is recommended to initialize the KruxTracker as a static variable in AppDelegate.m so that its available as soon as the app launches.
Before,
// Initialize KruxTracker (earlier version)
kruxTracker = [[KruxTracker alloc] initWithConfigId:@""];
After,
// Initialize KruxTracker
kruxTracker = [KruxTracker sharedEventTrackerWithConfigId:@"<config id provided by Krux>" debugFlag:false dryRunFlag:false];
In this version, a time interval restriction of 30 minutes has been added on fetching config and segments.
Sending Data to Audience Studio
KruxTracker exposes three methods now to send data to Audience Studio servers as described earlier.
The method definition for trackPageView has changed and a new method has been added to send data related to transactions to the Audience Studio servers. There are no changes in the fireEvent method.
Following is the change in trackPageView usage:
Before,
// Send Sports article
// article_read is the page attribute and 'Sports' is its value
// login id is a user attribute(12345 in this example) and loginId is how we are going to represent it in Krux
NSMutableDictionary *pageAttr = [[NSMutableDictionary alloc] init];
NSMutableDictionary *userAttr = [[NSMutableDictionary alloc] init];
[pageAttr setObject:@"Sports" forKey:@"article_read"];
[userAttr setObject:@"12345" forKey:@"loginId"];
[_kruxTracker trackPageView:@"Article_Page" pageAttributes:pageAttr userAttributes:userAttr withError:&err];
After,
// Send Sports article
// article_read is the page attribute and 'Sports' is its value
// login id is a user attribute(12345 in this example) and loginId is how we are going to represent it in Krux
NSDictionary *pageAttr = [[NSDictionary alloc] initWithObjectsAndKeys: @"Sports", @"article_read", nil];
NSDictionary *userAttr = [[NSDictionary alloc] initWithObjectsAndKeys: :@"12345", @"loginId", nil];
[kruxTracker trackPageView:@"Article_Page" pageAttributes:pageAttr userAttributes:userAttr];
Transaction data can be sent to Audience Studio in the following way:
NSDictionary *attr = [[NSDictionary alloc] initithObjectsAndKeys: :@"1000", @"totalPrice", @"5", @"qty", @"07/15/2016", @"date" nil];
[kruxTracker trackTransactionWithAttributes:attr];
More Helper methods
New helper method has been exposed to provide more control on the scheduler as described earlier.
However, we strongly recommend that you do not use this and let the SDK manage the fetching of config and segments.
Testing
Before publishing your app with Audience Studio, see "Testing Your SDK Integration" and "Verifying the SDK Implementation with Charles Proxy" on how to test and verify your Audience Studio SDK implementation.
Updates for iOS version 4.5.1/App Tracking Transparency Framework
The following dependent frameworks are required to use the AppTrackingTransparency.framework:
- SystemConfiguration.framework
- AdSupport.framework
To display the App Tracking Transparency authorization request for accessing the IDFA, update your Info.plist
to add the NSUserTrackingUsageDescription
key with a custom message describing your usage.
Below is an example description text:
To present the authorization request, call requestTrackingAuthorizationWithCompletionHandler:
. Please wait
for the completion callback, so that if the user grants the App Tracking Transparency permission.
Swift
import AppTrackingTransparency
import AdSupport
...
func requestIDFA() {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
// Tracking authorization completed. Start loading ads here.
// loadAd()
})
}
Objective C
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/AdSupport.h>
...
- (void)requestIDFA {
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// Tracking authorization completed. Start loading ads here.
// [self loadAd];
}];
}
For more information about the possible status values, see ATTrackingManager.AuthorizationStatus
0 Comments