1.工程集成
pod 'AppsFlyerFramework'
2.初始化
private func initAppsFlyer() {
AppsFlyerLib.shared().appleAppID = appleAppID
AppsFlyerLib.shared().appsFlyerDevKey = appsFlyerDevKey
#if DEBUG
AppsFlyerLib.shared().isDebug = true
#else
#endif
AppsFlyerLib.shared().deepLinkDelegate = self
AppsFlyerLib.shared().delegate = self
// Only for ATT
AppsFlyerLib.shared().waitForATTUserAuthorization(timeoutInterval: 10)
// For Scene Delegate
NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActiveNotification),
name: UIApplication.didBecomeActiveNotification,
object: nil)
}
@objc func didBecomeActiveNotification() {
// With Listener
AppsFlyerLib.shared().start(completionHandler: { (dictionary, error) in
if (error != nil){
print(error ?? "")
return
} else {
print(dictionary ?? "")
return
}
})
}
// 转化成功回调
func onConversionDataSuccess(_ conversionInfo: [AnyHashable : Any]) {
if let status = conversionInfo["af_status"] as? String {
if status == "Non-organic" {
} else {
print("This is an organic install.")
}
}
}
// 转化失败回调
func onConversionDataFail(_ error: Error) {
print("转化数据获取失败: \(error)")
}
// 深度链接回调
func onAppOpenAttribution(_ attributionData: [AnyHashable : Any]) {
print("深度链接数据: \(attributionData)")
}
func onAppOpenAttributionFailure(_ error: Error) {
print("深度链接数据获取失败: \(error)")
}
func didResolveDeepLink(_ result: DeepLinkResult) {}