迁移到iOS SDK V6(Beta)和插件

概览 :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初始化中

Objective-CSwift

在 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

3.支持AppTrackingTransparency(ATT)

对于iOS 14及更高版本,如果要访问与应用程序相关的数据以记录用户或设备(例如IDFA),则需要通过弹出窗口请求用户授权 。如果用户选择同意,则IDFA将被传递到SDK。

要配置在弹出窗口中显示给用户的文本:

  1. 选择project下面的Info.plist文件在Xcode Project Navigator中。
  2. 在列表中添加一个条目:按   Information Property List旁边的+

  3. 向下滚动并选择“ Privacy - Tracking Usage Description
  4. 将征求收集IDFA的权限时要向用户显示的文本添加为  value  

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
API名称变更

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的指南:

React Native

AppsFlyer React Native V6插件(测试版)能够帮助App所有者和开发人员为iOS 14做好准备,包括继续为安卓和iOS的用户提供归因和事件报告等功能。该插件在功能上等同于AppsFlyer iOS和Android SDK。

要从早期版本更新插件:

  1. 删除早期的插件,并按照我们在 GitHub指南 的说明进行替换。
  2. 通过 重命名和删除 必要的API来更改集成代码。
这篇文章有帮助吗?