Skip to content

Commit bcaad90

Browse files
committed
SDK-554 fix some nullability options and test project compilation. This project needs to be reworked as it hasn't been used/updated in some time.
1 parent 74ebddc commit bcaad90

File tree

9 files changed

+164
-168
lines changed

9 files changed

+164
-168
lines changed

Branch-SDK/Branch-SDK/Branch.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,21 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
168168
169169
@warning This method is not meant to be used in production!
170170
*/
171-
+ (nullable Branch *) getTestInstance __attribute__((deprecated(("Use `Branch.useTestBranchKey = YES;` instead."))));
171+
+ (Branch *)getTestInstance __attribute__((deprecated(("Use `Branch.useTestBranchKey = YES;` instead."))));
172172

173173

174174
/**
175175
Gets the global, live Branch instance.
176176
*/
177-
+ (nullable Branch *)getInstance;
177+
+ (Branch *)getInstance;
178178

179179
/**
180180
Gets the global Branch instance, configures using the specified key
181181
182182
@param branchKey The Branch key to be used by the Branch instance. This can be any live or test key.
183183
@warning This method is not the recommended way of using Branch. Try using your project's `Info.plist` if possible.
184184
*/
185-
+ (nullable Branch *)getInstance:(NSString *)branchKey;
185+
+ (Branch *)getInstance:(NSString *)branchKey;
186186

187187
/**
188188
Set the network service class.
@@ -947,7 +947,7 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
947947
*/
948948
- (void) sendCommerceEvent:(BNCCommerceEvent*)commerceEvent
949949
metadata:(NSDictionary<NSString*,id>*)metadata
950-
withCompletion:(void (^) (NSDictionary*response, NSError*error))completion __attribute__((deprecated(("Please use BranchEvent to track commerce events."))));
950+
withCompletion:(void (^) (NSDictionary* _Nullable response, NSError* _Nullable error))completion __attribute__((deprecated(("Please use BranchEvent to track commerce events."))));
951951

952952

953953
#pragma mark - Query methods

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,16 @@ + (void)load {
206206
// deprecated
207207
+ (Branch *)getTestInstance {
208208
Branch.useTestBranchKey = YES;
209-
return Branch.getInstance;
209+
return [Branch getInstance];
210210
}
211211

212212
+ (Branch *)getInstance {
213-
return [Branch getInstanceInternal:self.class.branchKey returnNilIfNoCurrentInstance:NO];
213+
return [Branch getInstanceInternal:self.class.branchKey];
214214
}
215215

216216
+ (Branch *)getInstance:(NSString *)branchKey {
217217
self.branchKey = branchKey;
218-
return [Branch getInstanceInternal:self.branchKey returnNilIfNoCurrentInstance:NO];
218+
return [Branch getInstanceInternal:self.branchKey];
219219
}
220220

221221
- (id)initWithInterface:(BNCServerInterface *)interface
@@ -1496,14 +1496,10 @@ - (void)removeAllPrivateContentFromSpotLightWithCallback:(void (^)(NSError * err
14961496

14971497
#pragma mark - Private methods
14981498

1499-
+ (Branch *)getInstanceInternal:(NSString *)key returnNilIfNoCurrentInstance:(BOOL)returnNilIfNoCurrentInstance {
1499+
+ (Branch *)getInstanceInternal:(NSString *)key {
15001500

15011501
static Branch *branch = nil;
15021502
@synchronized (self) {
1503-
if (!branch && returnNilIfNoCurrentInstance) {
1504-
return nil;
1505-
}
1506-
15071503
static dispatch_once_t onceToken = 0;
15081504
dispatch_once(&onceToken, ^{
15091505
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];

Branch-TestBed-Swift/TestBed-Swift/AppDelegate.swift

Lines changed: 104 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -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:"\nReferring link: \(referringLink)\n\nSession 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:"\nReferring link: \(referringLink)\n\nSession 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
}

Branch-TestBed-Swift/TestBed-Swift/CommerceEventDetailsTableViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class CommerceEventDetailsTableViewController: UITableViewController, UITextFiel
101101
}
102102

103103
func refreshControls() {
104-
guard var commerceEvent = CommerceEventData.commerceEvent() else {
104+
guard let commerceEvent = CommerceEventData.commerceEvent() else {
105105
return
106106
}
107107

Branch-TestBed-Swift/TestBed-Swift/CommerceEventTableViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class CommerceEventTableViewController: UITableViewController {
9090
disableTouches:true
9191
)
9292

93-
Branch.getInstance()?.send(
93+
Branch.getInstance().send(
9494
commerceEvent,
9595
metadata: commerceEventCustomMetadata,
9696
withCompletion: { (response, error) in

Branch-TestBed-Swift/TestBed-Swift/CustomEventTableViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ class CustomEventTableViewController: UITableViewController {
107107
}
108108

109109
if customEventMetadata.count == 0 {
110-
branch?.userCompletedAction(customEventName)
110+
branch.userCompletedAction(customEventName)
111111
} else {
112-
branch?.userCompletedAction(customEventName, withState: customEventMetadata)
112+
branch.userCompletedAction(customEventName, withState: customEventMetadata)
113113
}
114114
self.showAlert(String(format: "Custom event '%@' dispatched", customEventName), withDescription: "")
115115
}

0 commit comments

Comments
 (0)