概览 :AppsFlyer iOS SDK V6和相关插件的迁移指南。V6包括对iOS 14的支持。
关于iOS SDK V6
SDK V6请参考此文章。包括V6.01。
AppsFlyer iOS SDK V6 Beta:
- 允许 应用程序所有者和开发人员为iOS 14版本发布做准备,在该版本中,应用程序用户需要选择同意应用程序收集用户IDFA。
- 为iOS移动应用提供应用归因和事件报告功能。
- 包括对以前版本的API方法的重大更改。
获取V6 Beta的完整信息,并将其集成到不具有早期版本AppsFlyer SDK的新应用中,请阅读我们的iOS SDK V6 Beta开发者集成指南 。
迁移到iOS SDK V6 Beta
要迁移到iOS SDK V6,请完成以下步骤(1-5)。
1.更新SDK版本
下载SDK V6 beta并将其添加到您的Xcode。
2.实施SDK V6
iOS SDK V6 beta的大多数内容与早期版本相同。但是,在以下情况下,您将需要部署新代码:
- 您想从iOS 14用户那里收集IDFA,在这种情况下,您需要征得他们的同意。
- 您需要深层链接功能,但尚未部署。
要在用户选择同意时收集IDFA,并添加深层链接功能,请将以下代码添加到SDK初始化中 :
在 AppDelegate.h 中:请做如下操作:
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
-(void)sendLaunch:(UIApplication *)application {
[[AppsFlyerLib shared] start];
}
// Replace 'appsFlyerDevKey', `appleAppID` with your DevKey, Apple App ID
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[AppsFlyerLib shared].appsFlyerDevKey = @"";
[AppsFlyerLib shared].appleAppID = @"";
[AppsFlyerLib shared].delegate = self;
[AppsFlyerLib shared].isDebug = true;
// The following block is for applications wishing to collect IDFA.
// for iOS 14 and above - The user will be prompted for permission to collect IDFA.
// If permission granted, the IDFA will be collected by the SDK.
// for iOS 13 and below - The IDFA will be collected by the SDK. The user will NOT be prompted for permission.
if (@available(iOS 14, *)) {
[[AppsFlyerLib shared] waitForAdvertisingIdentifierWithTimeoutInterval:60];
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status){
}];
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sendLaunch:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
return YES;
}
// Deep linking
// Open URI-scheme for iOS 9 and above
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *) options {
[[AppsFlyerLib shared] handleOpenUrl:url options:options];
return YES;
}
// Open URI-scheme for iOS 8 and below
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation {
[[AppsFlyerLib shared] handleOpenURL:url sourceApplication:sourceApplication withAnnotation:annotation];
return YES;
}
// Open Universal Links
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
[[AppsFlyerLib shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
return YES;
}
// Report Push Notification attribution data for re-engagements
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[AppsFlyerLib shared] handlePushNotification:userInfo];
}
// AppsFlyerLib implementation
//Handle Conversion Data (Deferred Deep Link)
-(void)onConversionDataSuccess:(NSDictionary*) installData {
id status = [installData objectForKey:@"af_status"];
if([status isEqualToString:@"Non-organic"]) {
id sourceID = [installData objectForKey:@"media_source"];
id campaign = [installData objectForKey:@"campaign"];
NSLog(@"This is a none organic install. Media source: %@ Campaign: %@",sourceID,campaign);
} else if([status isEqualToString:@"Organic"]) {
NSLog(@"This is an organic install.");
}
}
-(void)onConversionDataFail:(NSError *) error {
NSLog(@"%@",error);
}
//Handle Direct Deep Link
- (void) onAppOpenAttribution:(NSDictionary*) attributionData {
NSLog(@"%@",attributionData);
}
- (void) onAppOpenAttributionFailure:(NSError *)error {
NSLog(@"%@",error);
}
// support for scene delegate
#pragma mark - UISceneSession lifecycle
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13)){
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}
- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet *)sceneSessions API_AVAILABLE(ios(13.0)){
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
@end
在 AppDelegate.swift里,添加以下框架:
import UIKit
import AppTrackingTransparency
import AppsFlyerLib
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Replace 'appsFlyerDevKey', `appleAppID` with your DevKey, Apple App ID
AppsFlyerLib.shared().appsFlyerDevKey = ""
AppsFlyerLib.shared().appleAppID = ""
AppsFlyerLib.shared().delegate = self
// Set isDebug to true to see AppsFlyer debug logs
AppsFlyerLib.shared().isDebug = true
// The following block is for applications wishing to collect IDFA.
// for iOS 14 and above - The user will be prompted for permission to collect IDFA.
// If permission granted, the IDFA will be collected by the SDK.
// for iOS 13 and below - The IDFA will be collected by the SDK. The user will NOT be prompted for permission.
if #available(iOS 14, *) {
// Set a timeout for the SDK to wait for the IDFA collection before handling app launch
AppsFlyerLib.shared().waitForAdvertiserId(timeoutInterval: 60)
// Show the user the Apple IDFA consent dialog (AppTrackingTransparency)
// Can be called in any place
ATTrackingManager.requestTrackingAuthorization { (status) in
}
}
return true
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Start the SDK (start the IDFA timeout set above, for iOS 14 or later)
AppsFlyerLib.shared().start()
}
// Open Deeplinks
// Open URI-scheme for iOS 8 and below
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
AppsFlyerLib.shared().handleOpen(url, sourceApplication: sourceApplication, withAnnotation: annotation)
return true
}
// Open URI-scheme for iOS 9 and above
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
AppsFlyerLib.shared().handleOpen(url, options: options)
return true
}
// Report Push Notification attribution data for re-engagements
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
AppsFlyerLib.shared().handlePushNotification(userInfo)
}
}
extension AppDelegate: AppsFlyerLibDelegate {
// Handle Organic/Non-organic installation
func onConversionDataSuccess(_ data: [AnyHashable: Any]) {
print("onConversionDataSuccess data:")
for (key, value) in data {
print(key, ":", value)
}
if let status = data["af_status"] as? String {
if (status == "Non-organic") {
if let sourceID = data["media_source"],
let campaign = data["campaign"] {
print("This is a Non-Organic install. Media source: \(sourceID) Campaign: \(campaign)")
}
} else {
print("This is an organic install.")
}
if let is_first_launch = data["is_first_launch"] as? Bool,
is_first_launch {
print("First Launch")
} else {
print("Not First Launch")
}
}
}
func onConversionDataFail(_ error: Error) {
print("\(error)")
}
// Handle Deeplink
func onAppOpenAttribution(_ attributionData: [AnyHashable: Any]) {
//Handle Deep Link Data
print("onAppOpenAttribution data:")
for (key, value) in attributionData {
print(key, ":",value)
}
}
func onAppOpenAttributionFailure(_ error: Error) {
print("\(error)")
}
}
3.支持AppTrackingTransparency(ATT)
对于iOS 14及更高版本,如果要访问与应用程序相关的数据以记录用户或设备(例如IDFA),则需要通过弹出窗口请求用户授权 。如果用户选择同意,则IDFA将被传递到SDK。
要配置在弹出窗口中显示给用户的文本:
4.更改APIs
AppsFlyer iOS SDK V6进行了一些API名称更改,请使用下表将API名称从早期的SDK版本更改为当前名称。
API名称(在V6之前) | 当前的API名称(V6和更高版本) |
---|---|
AppsFlyerTracker | AppsFlyerLib |
disableIAdTracking | disableCollectASA |
trackAppLaunchWithCompletionHandler |
startWithCompletionHandler |
trackLocation |
logLocationEvent |
trackAppLaunch |
开始 |
trackEvent |
logEvent |
disableAppleAdSupportTracking |
disableAdvertiserIdentifier |
validateAndTrackInAppPurchase |
validateAndLogInAppPurchase |
isStopTracking |
isStopped |
deviceTrackingDisabled/deviceLoggingDisabled |
anonymizeUser |
sharedTracker (Objective C) | shared |
5.确保推送通知集成
请遵循主要iOS SDK V6指南中的 推送通知说明 ,以确保您的推送通知使用 handle Push NotificationData 方法进行了集成。
插件
以下V6 Beta插件可用:
Unity
AppsFlyer Unity V6插件(beta)可帮助应用所有者和开发人员为iOS 14做准备,为在Unity开发平台上开发的Android和iOS移动应用提供应用归因和事件报告功能。该插件在功能上等同于AppsFlyer iOS和Android SDK。
要更新您早期版本的插件,请参阅有关迁移到Unity插件V6 beta的指南:
- From Unity plugin V4 (requires removal of the old plugin)
- From Unity plugin V5 (requires update of the Unity package)