Commit f172e74c by Demid Merzlyakov

AppsFlyer basic initialization.

parent 4c71fc76
......@@ -13,13 +13,16 @@ import MoEngage
import GoogleMobileAds
import Swarm
import DTBiOSSDK
import AppsFlyerLib
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private let appsFlyer = AppsFlyerLib.shared()
private let appsFlyerLog = Logger(componentName: "AppsFlyer")
private let log = Logger(componentName: "AppDelegate")
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
ThemeManager.refreshAppearance()
......@@ -31,13 +34,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
self.window = UIWindow(frame: UIScreen.main.bounds)
appsFlyerLog.info("AppsFlyer initialize with AppsFlyerId: \(kAppsFlyerId), Apple App ID: \(kAppsFlyerAppId)")
appsFlyer.appsFlyerDevKey = kAppsFlyerId
appsFlyer.appleAppID = kAppsFlyerAppId
appsFlyer.delegate = self
#if DEBUG
appsFlyer.isDebug = true
#else
appsFlyer.isDebug = false
#endif
// Note that the Amazon SDK will get assigned a proper value for consent status inside CCPAHelper.onAppLaunch
// So, make sure this call happens after the
CCPAHelper.shared.onAppLaunch()
// As of DTB 3.4.6 the Amazon SDK freezes the main thread on startup for a couple of seconds, which got us rejected during an AppStore Review. We're going to move this initialization to the AppDelegate for now. The consent status is going to be set earlier within CCPAHelper.shared.onAppLaunch(), so make sure CCPAHelper's onAppLaunch is called before Amazon's setAppKey
// TODO: remove setAppKey from here, if Amazon has fixed the freeze on startup.
Logger(componentName: "Amazon A9").info("Amazon SDK initialization start")
log.info("Amazon SDK (Amazon A9) initialization start")
DTBAds.sharedInstance().setAppKey(a9AppKey)
FirebaseApp.configure()
ConfigManager.shared.updateConfig()
......@@ -55,7 +68,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
flurrySession = flurrySession?.withDataSaleOptOut(!canCollectData)
}
Logger(componentName: "Flurry").info("Initialize Flurry.")
log.info("Initialize Flurry with partner ID: \(kFlurryPartnerId)")
Flurry.startSession(kFlurryPartnerId, with: FlurrySessionBuilder
.init()
.withCrashReporting(false)
......@@ -65,13 +78,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var moEngageConfig = MOSDKConfig(appID: kMoEngageAppId)
moEngageConfig.appGroupID = "group.com.onelouder.oneweather.MoEngage"
let moeLogger = Logger(componentName: "MoEngage")
#if DEBUG
moeLogger.info("Initialize MoEngage (TEST)")
log.info("Initialize MoEngage (TEST)")
MoEngage.enableSDKLogs(true)
MoEngage.sharedInstance().initializeTest(with: moEngageConfig, andLaunchOptions: launchOptions)
#else
moeLogger.info("Initialize MoEngage (LIVE)")
log.info("Initialize MoEngage (LIVE)")
MoEngage.sharedInstance().initializeLive(with: moEngageConfig, andLaunchOptions: launchOptions)
#endif
......@@ -79,8 +91,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
log.info("Open URL: \(url) with options: \(options)")
//TODO: move to Router?
#if DEBUG
//TODO: REMOVE THIS'
//TODO: move to Router?
#warning("THIS IS A DEBUG-ONLY PIECE OF CODE! Not even temporary! Remove before making a production build.")
#else
#error("THIS IS A DEBUG-ONLY PIECE OF CODE! Not even temporary! Remove before making a production build.")
#endif
appsFlyer.handleOpen(url, options: options)
return true
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
log.info("Continue userActivity \(userActivity)")
appsFlyer.continue(userActivity, restorationHandler: nil)
return true
}
func applicationDidBecomeActive(_ application: UIApplication) {
LocationManager.shared.updateEverythingIfNeeded()
appsFlyer.start()
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
......@@ -88,3 +121,28 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
extension AppDelegate: AppsFlyerLibDelegate {
func onConversionDataSuccess(_ conversionInfo: [AnyHashable : Any]) {
let status = conversionInfo["af_status"] as? String
if status == "Non-organic" {
let sourceID = conversionInfo["media_source"] as? String
let campaign = conversionInfo["campaign"] as? String
appsFlyerLog.info("This is a non-organic install. Media source: \(sourceID ?? String(describing: conversionInfo["media_source"])) Campaign: \(campaign ?? String(describing: conversionInfo["campaign"]))")
}
else if status == "Organic" {
appsFlyerLog.info("This is an organic install.")
}
}
func onConversionDataFail(_ error: Error) {
appsFlyerLog.error("conversion data fail: \(error)")
}
func onAppOpenAttribution(_ attributionData: [AnyHashable : Any]) {
appsFlyerLog.info("app open attribution: \(attributionData)")
}
func onAppOpenAttributionFailure(_ error: Error) {
appsFlyerLog.error("app open attribution error: \(error)")
}
}
......@@ -17,6 +17,10 @@ let kOLAppMetricsKey: String = "OLAppMetricsKey"
let WDT_APP_ID = "e3b73414"
let WDT_APP_KEY = "25e8d6b72de3bcd528f7769b073cc335"
//MARK: - keys for AppsFlyer
let kAppsFlyerId = "62r3MKqdd6eqtj5jN5wdm6"
let kAppsFlyerAppId = "1044809694" // taken from the app page in AppStoreConnect
//MARK: - InApp
let kInAppOneWeatherProId = "com.onelouder.oneweather.inapp1"
......
......@@ -8,6 +8,7 @@
import Foundation
import MoEngage
import AppsFlyerLib
public class PushNotificationsManager: NSObject {
// MARK: - Private
......@@ -142,6 +143,15 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
log.info("MoEngage push: location found: \(newLoc)")
}
private func isMoEngagePush(_ response: UNNotificationResponse) -> Bool {
let userInfo = response.notification.request.content.userInfo
guard userInfo["moengage"] as? [String: Any] != nil else {
log.debug("No MoEngage data found.")
return false
}
return true
}
private func handleMoEngageDeeplinks(for response: UNNotificationResponse) {
let userInfo = response.notification.request.content.userInfo
......@@ -202,8 +212,16 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
}
public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
MoEngage.sharedInstance().userNotificationCenter(center, didReceive: response) // not sure we should call it for PushPin notifications, too
handleMoEngageDeeplinks(for: response)
MoEngage.sharedInstance().userNotificationCenter(center, didReceive: response) // not sure we should call it for AppsFlyer notifications
log.debug("Got a push notification: \(response.notification.request.content.userInfo)")
if isMoEngagePush(response) {
handleMoEngageDeeplinks(for: response)
}
else {
log.info("Handle push notification with AppsFlyer")
AppsFlyerLib.shared().handlePushNotification(response.notification.request.content.userInfo)
}
completionHandler()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment