@@ -57,131 +57,126 @@ class AppDelegate: UIResponder, UIApplicationDelegate, AdjustDelegate, AppsFlyer
5757 activateSingular ( )
5858 activateStitch ( )
5959
60- if let branch = Branch . getInstance ( branchKey) {
60+ let branch = Branch . getInstance ( branchKey)
6161
62- if StartupOptionsData . getPendingSetDebugEnabled ( ) ! {
63- branch. setDebug ( )
64- StartupOptionsData . setActiveSetDebugEnabled ( true )
65- } else {
66- StartupOptionsData . setActiveSetDebugEnabled ( false )
62+ if StartupOptionsData . getPendingSetDebugEnabled ( ) ! {
63+ branch. setDebug ( )
64+ StartupOptionsData . setActiveSetDebugEnabled ( true )
65+ } else {
66+ StartupOptionsData . setActiveSetDebugEnabled ( false )
67+ }
68+
69+ // To use automaticallyDisplayDeepLinkController:
70+ // 1) Uncomment the following code block
71+ // 2) Comment out the code in the 'if (error == nil)' code block in initSession callback below
72+ // 3) Change automaticallyDisplayDeepLinkController to true
73+ /* let navigationController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as! UINavigationController
74+ branch.registerDeepLinkController(navigationController, forKey:"~referring_link")*/
75+
76+ // Required. Initialize session. automaticallyDisplayDeepLinkController is optional (default is false).
77+
78+ branch. initSession (
79+ launchOptions: launchOptions,
80+ automaticallyDisplayDeepLinkController: false ,
81+ deepLinkHandler: { params, error in
82+
83+ defer {
84+ let notificationName = Notification . Name ( " BranchCallbackCompleted " )
85+ NotificationCenter . default. post ( name: notificationName, object: nil )
86+ }
87+
88+ guard error == nil else {
89+ print ( " Branch TestBed: Initialization failed: " + error!. localizedDescription)
90+ return
6791 }
6892
69- // To use automaticallyDisplayDeepLinkController:
70- // 1) Uncomment the following code block
71- // 2) Comment out the code in the 'if (error == nil)' code block in initSession callback below
72- // 3) Change automaticallyDisplayDeepLinkController to true
73- /* let navigationController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as! UINavigationController
74- branch.registerDeepLinkController(navigationController, forKey:"~referring_link")*/
93+ guard let paramsDictionary = ( params as? Dictionary < String , Any > ) else {
94+ print ( " No Branch parameters returned " )
95+ return
96+ }
7597
76- // Required. Initialize session. automaticallyDisplayDeepLinkController is optional (default is false).
98+
99+ let clickedBranchLink = params ? [ BRANCH_INIT_KEY_CLICKED_BRANCH_LINK] as! Bool ?
77100
78- branch. initSession (
79- launchOptions: launchOptions,
80- automaticallyDisplayDeepLinkController: false ,
81- deepLinkHandler: { params, error in
82-
83- defer {
84- let notificationName = Notification . Name ( " BranchCallbackCompleted " )
85- NotificationCenter . default. post ( name: notificationName, object: nil )
86- }
87-
88- guard error == nil else {
89- print ( " Branch TestBed: Initialization failed: " + error!. localizedDescription)
90- return
101+ if let referringLink = paramsDictionary [ " ~referring_link " ] as! String ? ,
102+ let trackerId = paramsDictionary [ " ios_tracker_id " ] as! String ? ,
103+ let clickedBranchLink = clickedBranchLink,
104+ clickedBranchLink {
105+ var adjustUrl = URLComponents ( string: referringLink)
106+ var adjust_tracker : URLQueryItem
107+ //
108+ // Here's how to add Adjust attribution:
109+ //
110+ // Check if the deeplink is a Universal link.
111+ if referringLink. starts ( with: " https:// " ) || referringLink. starts ( with: " http:// " ) {
112+ adjust_tracker = URLQueryItem ( name: " adjust_t " , value: trackerId)
113+ } else {
114+ adjust_tracker = URLQueryItem ( name: " adjust_tracker " , value: trackerId)
91115 }
92-
93- guard let paramsDictionary = ( params as? Dictionary < String , Any > ) else {
94- print ( " No Branch parameters returned " )
95- return
116+ let adjust_campaign = URLQueryItem ( name: " adjust_campaign " , value: paramsDictionary [ BRANCH_INIT_KEY_CAMPAIGN] as? String )
117+ let adjust_adgroup = URLQueryItem ( name: " adjust_adgroup " , value: paramsDictionary [ BRANCH_INIT_KEY_CHANNEL] as? String )
118+ let adjust_creative = URLQueryItem ( name: " adjust_creative " , value: paramsDictionary [ BRANCH_INIT_KEY_FEATURE] as? String )
119+ let queryItems = [ adjust_tracker, adjust_campaign, adjust_adgroup, adjust_creative]
120+ adjustUrl? . queryItems = queryItems
121+ if let url = adjustUrl? . url {
122+ Adjust . appWillOpen ( url)
96123 }
124+ }
125+
126+ // Deeplinking logic for use when automaticallyDisplayDeepLinkController = false
127+ if let clickedBranchLink = clickedBranchLink,
128+ clickedBranchLink {
129+ let nc = self . window!. rootViewController as! UINavigationController
130+ let storyboard = UIStoryboard ( name: " Content " , bundle: nil )
131+ let contentViewController = storyboard. instantiateViewController ( withIdentifier: " Content " ) as! ContentViewController
132+ nc. pushViewController ( contentViewController, animated: true )
97133
98-
99- let clickedBranchLink = params ? [ BRANCH_INIT_KEY_CLICKED_BRANCH_LINK] as! Bool ?
134+ let referringLink = paramsDictionary [ " ~referring_link " ] as! String
135+ let content = String ( format: " \n Referring link: \( referringLink) \n \n Session Details: \n \( paramsDictionary. JSONDescription ( ) ) " )
136+ contentViewController. content = content
137+ contentViewController. contentType = " Content "
138+ } else {
139+ print ( String ( format: " Branch TestBed: Finished init with params \n %@ " , paramsDictionary. description) )
140+ }
141+
142+ // Adobe
143+ if IntegratedSDKsData . activeAdobeEnabled ( ) ! {
144+ let adobeVisitorID = ADBMobile . trackingIdentifier ( )
100145
101- if let referringLink = paramsDictionary [ " ~referring_link " ] as! String ? ,
102- let trackerId = paramsDictionary [ " ios_tracker_id " ] as! String ? ,
103- let clickedBranchLink = clickedBranchLink,
104- clickedBranchLink {
105- var adjustUrl = URLComponents ( string: referringLink)
106- var adjust_tracker : URLQueryItem
107- //
108- // Here's how to add Adjust attribution:
109- //
110- // Check if the deeplink is a Universal link.
111- if referringLink. starts ( with: " https:// " ) || referringLink. starts ( with: " http:// " ) {
112- adjust_tracker = URLQueryItem ( name: " adjust_t " , value: trackerId)
113- } else {
114- adjust_tracker = URLQueryItem ( name: " adjust_tracker " , value: trackerId)
115- }
116- let adjust_campaign = URLQueryItem ( name: " adjust_campaign " , value: paramsDictionary [ BRANCH_INIT_KEY_CAMPAIGN] as? String )
117- let adjust_adgroup = URLQueryItem ( name: " adjust_adgroup " , value: paramsDictionary [ BRANCH_INIT_KEY_CHANNEL] as? String )
118- let adjust_creative = URLQueryItem ( name: " adjust_creative " , value: paramsDictionary [ BRANCH_INIT_KEY_FEATURE] as? String )
119- let queryItems = [ adjust_tracker, adjust_campaign, adjust_adgroup, adjust_creative]
120- adjustUrl? . queryItems = queryItems
121- if let url = adjustUrl? . url {
122- Adjust . appWillOpen ( url)
123- }
124- }
146+ branch. setRequestMetadataKey ( " $adobe_visitor_id " , value: adobeVisitorID)
147+ }
148+
149+
150+ // Amplitude
151+ if IntegratedSDKsData . activeAmplitudeEnabled ( ) ! {
152+ var userID : String
125153
126- // Deeplinking logic for use when automaticallyDisplayDeepLinkController = false
127- if let clickedBranchLink = clickedBranchLink,
128- clickedBranchLink {
129- let nc = self . window!. rootViewController as! UINavigationController
130- let storyboard = UIStoryboard ( name: " Content " , bundle: nil )
131- let contentViewController = storyboard. instantiateViewController ( withIdentifier: " Content " ) as! ContentViewController
132- nc. pushViewController ( contentViewController, animated: true )
133-
134- let referringLink = paramsDictionary [ " ~referring_link " ] as! String
135- let content = String ( format: " \n Referring link: \( referringLink) \n \n Session Details: \n \( paramsDictionary. JSONDescription ( ) ) " )
136- contentViewController. content = content
137- contentViewController. contentType = " Content "
154+ if paramsDictionary [ " developer_identity " ] != nil {
155+ userID = paramsDictionary [ " developer_identity " ] as! String
138156 } else {
139- print ( String ( format: " Branch TestBed: Finished init with params \n %@ " , paramsDictionary. description) )
140- }
141-
142- // Adobe
143- if IntegratedSDKsData . activeAdobeEnabled ( ) ! {
144- let adobeVisitorID = ADBMobile . trackingIdentifier ( )
145-
146- branch. setRequestMetadataKey ( " $adobe_visitor_id " , value: adobeVisitorID)
157+ userID = " Anonymous "
147158 }
148159
160+ Amplitude . instance ( ) . setUserId ( userID)
161+ branch. setRequestMetadataKey ( " $amplitude_user_id " ,
162+ value: userID)
163+ }
164+
165+ // Mixpanel
166+ if IntegratedSDKsData . activeMixpanelEnabled ( ) ! {
167+ var userID : String
149168
150- // Amplitude
151- if IntegratedSDKsData . activeAmplitudeEnabled ( ) ! {
152- var userID : String
153-
154- if paramsDictionary [ " developer_identity " ] != nil {
155- userID = paramsDictionary [ " developer_identity " ] as! String
156- } else {
157- userID = " Anonymous "
158- }
159-
160- Amplitude . instance ( ) . setUserId ( userID)
161- branch. setRequestMetadataKey ( " $amplitude_user_id " ,
162- value: userID)
169+ if paramsDictionary [ " developer_identity " ] != nil {
170+ userID = paramsDictionary [ " developer_identity " ] as! String
171+ } else {
172+ userID = " Anonymous "
163173 }
164174
165- // Mixpanel
166- if IntegratedSDKsData . activeMixpanelEnabled ( ) ! {
167- var userID : String
168-
169- if paramsDictionary [ " developer_identity " ] != nil {
170- userID = paramsDictionary [ " developer_identity " ] as! String
171- } else {
172- userID = " Anonymous "
173- }
174-
175- Mixpanel . sharedInstance ( ) ? . identify ( userID)
176- branch. setRequestMetadataKey ( " $mixpanel_distinct_id " ,
177- value: userID)
178- }
179- } )
180- } else {
181- print ( " Branch TestBed: Invalid Key \n " )
182- StartupOptionsData . setActiveBranchKey ( " " )
183- StartupOptionsData . setPendingBranchKey ( " " )
184- }
175+ Mixpanel . sharedInstance ( ) ? . identify ( userID)
176+ branch. setRequestMetadataKey ( " $mixpanel_distinct_id " ,
177+ value: userID)
178+ }
179+ } )
185180
186181 return true
187182 }
0 commit comments