Skip to content

Commit 4326b91

Browse files
authored
Merge pull request #478 from BranchMetrics/TestBed-Swift
TestBed-Swift App Store Version
2 parents 4e6b8e0 + 28c0f69 commit 4326b91

File tree

10 files changed

+327
-188
lines changed

10 files changed

+327
-188
lines changed

Branch-TestBed-Swift/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Branch TestBed-Swift
2+
3+
This iOS application can be used to test Branch deep linking functionality and validate proposed use cases.
4+
5+
It is available on the App Store: https://testbed-swift.app.link/appstore
6+
17
## Create a personal copy of Branch's Swift TestBed app for testing!
28

39
1. From the command line:

Branch-TestBed-Swift/TestBed-Swift.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@
452452
INFOPLIST_FILE = "TestBed-Swift/Info.plist";
453453
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
454454
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
455-
PRODUCT_BUNDLE_IDENTIFIER = io.branch.Swift.TestBed;
455+
PRODUCT_BUNDLE_IDENTIFIER = "io.branch.TestBed-Swift";
456456
PRODUCT_NAME = "$(TARGET_NAME)";
457457
PROVISIONING_PROFILE = "";
458458
SWIFT_OBJC_BRIDGING_HEADER = "TestBed-Swift/TestBed-Swift-Bridging-Header.h";
@@ -473,7 +473,7 @@
473473
INFOPLIST_FILE = "TestBed-Swift/Info.plist";
474474
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
475475
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
476-
PRODUCT_BUNDLE_IDENTIFIER = io.branch.Swift.TestBed;
476+
PRODUCT_BUNDLE_IDENTIFIER = "io.branch.TestBed-Swift";
477477
PRODUCT_NAME = "$(TARGET_NAME)";
478478
PROVISIONING_PROFILE = "";
479479
SWIFT_OBJC_BRIDGING_HEADER = "TestBed-Swift/TestBed-Swift-Bridging-Header.h";

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,28 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414

1515
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1616

17-
if let branch = Branch.getInstance() {
18-
branch.setDebug()
17+
let defaultBranchKey = Bundle.main.object(forInfoDictionaryKey: "branch_key") as! String
18+
var branchKey = defaultBranchKey
19+
20+
if let pendingBranchKey = DataStore.getPendingBranchKey() as String? {
21+
if pendingBranchKey != "" {
22+
branchKey = pendingBranchKey
23+
}
24+
DataStore.setActiveBranchKey(branchKey)
25+
} else {
26+
branchKey = defaultBranchKey
27+
DataStore.setActiveBranchKey(defaultBranchKey)
28+
}
29+
30+
if let branch = Branch.getInstance(branchKey) {
31+
32+
if DataStore.getPendingSetDebugEnabled()! {
33+
branch.setDebug()
34+
DataStore.setActivePendingSetDebugEnabled(true)
35+
} else {
36+
DataStore.setActivePendingSetDebugEnabled(false)
37+
}
1938

20-
// Automatic Deeplinking on "~referring_link"
2139
let navigationController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as! UINavigationController
2240
branch.registerDeepLinkController(navigationController, forKey:"~referring_link")
2341

@@ -54,6 +72,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5472
let notificationName = Notification.Name("BranchCallbackCompleted")
5573
NotificationCenter.default.post(name: notificationName, object: nil)
5674
})
75+
} else {
76+
print("Branch TestBed: Invalid Key\n")
77+
DataStore.setActiveBranchKey("")
78+
DataStore.setPendingBranchKey("")
5779
}
5880
return true
5981
}

Branch-TestBed-Swift/TestBed-Swift/Base.lproj/LaunchScreen.storyboard

Lines changed: 20 additions & 43 deletions
Large diffs are not rendered by default.

Branch-TestBed-Swift/TestBed-Swift/Base.lproj/Main.storyboard

Lines changed: 174 additions & 98 deletions
Large diffs are not rendered by default.

Branch-TestBed-Swift/TestBed-Swift/ContentViewController.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ class ContentViewController: UIViewController {
3131
imageView.isHidden = false
3232
imageView.loadImageFromUrl(url: imageURL)
3333
print("ImageURL=\(imageURL)")
34+
3435
}
3536
}
3637

37-
universalObject.automaticallyListOnSpotlight = true
38-
universalObject.userCompletedAction(BNCRegisterViewEvent)
38+
if universalObject.canonicalIdentifier != "" {
39+
universalObject.automaticallyListOnSpotlight = true
40+
universalObject.userCompletedAction(BNCRegisterViewEvent)
41+
}
42+
3943
}
4044
} else if contentType == "LatestReferringParams" {
4145
if let latestReferringParams = Branch.getInstance().getLatestReferringParams() {

Branch-TestBed-Swift/TestBed-Swift/DataStore.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,48 @@ struct DataStore {
143143
userDefaults.set(value, forKey: "customEventMetadata")
144144
}
145145

146+
static func getActiveBranchKey() -> String? {
147+
if let value = userDefaults.string(forKey: "activeBranchKey") {
148+
return value
149+
} else {
150+
let value = ""
151+
userDefaults.setValue(value, forKey: "activeBranchKey")
152+
return value
153+
}
154+
}
155+
156+
static func setActiveBranchKey(_ value: String) {
157+
userDefaults.setValue(value, forKey: "activeBranchKey")
158+
}
159+
160+
static func getPendingBranchKey() -> String? {
161+
if let value = userDefaults.string(forKey: "pendingBranchKey") {
162+
return value
163+
} else {
164+
let value = ""
165+
userDefaults.setValue(value, forKey: "pendingBranchKey")
166+
return value
167+
}
168+
}
169+
170+
static func setPendingBranchKey(_ value: String) {
171+
userDefaults.setValue(value, forKey: "pendingBranchKey")
172+
}
173+
174+
static func getActiveSetDebugEnabled() -> Bool? {
175+
return userDefaults.bool(forKey: "activeSetDebug")
176+
}
177+
178+
static func setActivePendingSetDebugEnabled(_ value: Bool) {
179+
userDefaults.setValue(value, forKey: "activeSetDebug")
180+
}
181+
182+
static func getPendingSetDebugEnabled() -> Bool? {
183+
return userDefaults.bool(forKey: "pendingSetDebug")
184+
}
185+
186+
static func setPendingPendingSetDebugEnabled(_ value: Bool) {
187+
userDefaults.setValue(value, forKey: "pendingSetDebug")
188+
}
189+
146190
}

Branch-TestBed-Swift/TestBed-Swift/Info.plist

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<dict>
55
<key>CFBundleDevelopmentRegion</key>
66
<string>en</string>
7+
<key>CFBundleDisplayName</key>
8+
<string>Branch TestBed-Swift</string>
79
<key>CFBundleExecutable</key>
810
<string>$(EXECUTABLE_NAME)</string>
911
<key>CFBundleIdentifier</key>
@@ -15,15 +17,15 @@
1517
<key>CFBundlePackageType</key>
1618
<string>APPL</string>
1719
<key>CFBundleShortVersionString</key>
18-
<string>2</string>
20+
<string>5</string>
1921
<key>CFBundleSignature</key>
2022
<string>????</string>
2123
<key>CFBundleURLTypes</key>
2224
<array>
2325
<dict>
2426
<key>CFBundleURLSchemes</key>
2527
<array>
26-
<string>swift-testbed</string>
28+
<string>testbed-swift</string>
2729
</array>
2830
</dict>
2931
</array>
@@ -56,8 +58,8 @@
5658
<string>UIInterfaceOrientationLandscapeRight</string>
5759
</array>
5860
<key>branch_app_domain</key>
59-
<string>5oex.app.link</string>
61+
<string>app.link</string>
6062
<key>branch_key</key>
61-
<string>key_live_pkdWRsV0DEuNIHOijChGwpfhrBmbZnPg</string>
63+
<string>key_live_cnChxhZYcC9rBMAG82xLNjdcFBokyGD0</string>
6264
</dict>
6365
</plist>

Branch-TestBed-Swift/TestBed-Swift/TestBed-Swift.entitlements

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
<dict>
55
<key>com.apple.developer.associated-domains</key>
66
<array>
7-
<string>applinks:5oex.app.link</string>
8-
<string>applinks:5oex.test-app.link</string>
9-
<string>applinks:5oex-alternate.app.link</string>
10-
<string>applinks:5oex-alternate.test-app.link</string>
7+
<string>applinks:testbed-swift.app.link</string>
8+
<string>applinks:testbed-swift.test-app.link</string>
9+
<string>applinks:testbed-swift-alternate.app.link</string>
10+
<string>applinks:testbed-swift-alternate.test-app.link</string>
1111
</array>
1212
</dict>
1313
</plist>

Branch-TestBed-Swift/TestBed-Swift/ViewController.swift

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class ViewController: UITableViewController {
4040
@IBOutlet weak var rewardPointsToRedeemTextField: UITextField!
4141
@IBOutlet weak var customEventNameTextField: UITextField!
4242
@IBOutlet weak var customEventMetadataTextView: UITextView!
43+
@IBOutlet weak var activeBranchKeyTextField: UITextField!
44+
@IBOutlet weak var activeSetDebugEnabledSwitch: UISwitch!
45+
@IBOutlet weak var pendingBranchKeyTextField: UITextField!
46+
@IBOutlet weak var pendingSetDebugEnabledSwitch: UISwitch!
4347

4448
var linkProperties = [String: AnyObject]()
4549
var universalObjectProperties = [String: AnyObject]()
@@ -90,25 +94,20 @@ class ViewController: UITableViewController {
9094
name: Notification.Name("BranchCallbackCompleted"),
9195
object: nil)
9296

93-
94-
9597
linkTextField.text = ""
9698
refreshControlValues()
9799
refreshEnabledButtons()
98100
}
99101

100102
func applicationDidBecomeActive() {
101-
loadLinkPropertiesButton.isEnabled = false
102-
loadObjectPropertiesButton.isEnabled = false
103+
refreshEnabledButtons()
103104
}
104105

105106
func refreshEnabledButtons() {
106107
var enableButtons = false
107108

108109
if let clickedBranchLink = Branch.getInstance().getLatestReferringParams()["+clicked_branch_link"] as! Bool? {
109110
enableButtons = clickedBranchLink
110-
111-
print(Branch.getInstance().getLatestReferringParams().JSONDescription())
112111
}
113112
if enableButtons == true {
114113
loadLinkPropertiesButton.isEnabled = true
@@ -174,6 +173,8 @@ class ViewController: UITableViewController {
174173
self.performSegue(withIdentifier: "ShowContentView", sender: "FirstReferringParams")
175174
print("Branch TestBed: FirstReferringParams:\n", content)
176175
}
176+
case (6,0) :
177+
self.performSegue(withIdentifier: "ShowTextViewFormNavigationBar", sender: "pendingBranchKey")
177178
default : break
178179
}
179180
}
@@ -184,18 +185,20 @@ class ViewController: UITableViewController {
184185
setBranchLinkProperty(key)
185186
}
186187

187-
print(universalObjectProperties["$canonical_identifier"])
188188
if let canonicalIdentifier = universalObjectProperties["$canonical_identifier"] as? String {
189189
branchUniversalObject = BranchUniversalObject.init(canonicalIdentifier: canonicalIdentifier)
190190
} else {
191-
print(universalObjectProperties["$canonical_identifier"])
192-
branchUniversalObject = BranchUniversalObject.init(canonicalIdentifier: "_")
191+
var canonicalIdentifier = ""
192+
for _ in 1...18 {
193+
canonicalIdentifier.append(String(arc4random_uniform(10)))
194+
}
195+
branchUniversalObject = BranchUniversalObject.init(canonicalIdentifier: canonicalIdentifier)
193196
}
194197

195198
for key in universalObjectProperties.keys {
196199
setBranchUniversalObjectProperty(key)
197200
}
198-
201+
199202
branchUniversalObject.showShareSheet(with: branchLinkProperties, andShareText: shareText, from: self, anchor: actionButton) { (activityType, completed) in
200203
if (completed) {
201204
print(String(format: "Branch TestBed: Completed sharing to %@", activityType!))
@@ -216,7 +219,6 @@ class ViewController: UITableViewController {
216219
linkProperties[key] = value as AnyObject?
217220
}
218221
}
219-
220222
self.showAlert("Link Properties Loadded", withDescription: "")
221223
}
222224

@@ -245,7 +247,6 @@ class ViewController: UITableViewController {
245247
setBranchLinkProperty(key)
246248
}
247249

248-
print(universalObjectProperties["$canonical_identifier"])
249250
if let canonicalIdentifier = universalObjectProperties["$canonical_identifier"] as? String {
250251
branchUniversalObject = BranchUniversalObject.init(canonicalIdentifier: canonicalIdentifier)
251252
} else {
@@ -332,28 +333,10 @@ class ViewController: UITableViewController {
332333
}
333334
}
334335

335-
@IBAction func viewFirstReferringParamsButtonTouchUpInside(_ sender: AnyObject) {
336-
let branch = Branch.getInstance()
337-
let params = branch?.getFirstReferringParams()
338-
let content = String(format:"FirstReferringParams:\n\n%@", (params?.description)!)
339-
340-
self.performSegue(withIdentifier: "ShowContentView", sender: content)
341-
print("Branch TestBed: FirstReferringParams:\n", content)
342-
}
343-
344-
@IBAction func viewLatestReferringParamsButtonTouchUpInside(_ sender: AnyObject) {
345-
let branch = Branch.getInstance()
346-
let params = branch?.getFirstReferringParams()
347-
let content = String(format:"LatestReferringParams:\n\n%@", (params?.description)!)
348-
349-
self.performSegue(withIdentifier: "ShowContentView", sender: content)
350-
print("Branch TestBed: LatestReferringParams:\n", content)
336+
@IBAction func pendingSetDebugEnabledButtonValueChanged(_ sender: AnyObject) {
337+
DataStore.setPendingPendingSetDebugEnabled(self.pendingSetDebugEnabledSwitch.isOn)
351338
}
352339

353-
@IBAction func simulateContentAccessButtonTouchUpInside(_ sender: AnyObject) {
354-
self.branchUniversalObject.registerView()
355-
self.showAlert("Content Access Registered", withDescription: "")
356-
}
357340

358341
func textFieldDidChange(_ sender:UITextField) {
359342
sender.resignFirstResponder()
@@ -455,6 +438,15 @@ class ViewController: UITableViewController {
455438
} else {
456439
vc.contentType = "\nApp has not yet been opened via a Branch link"
457440
}
441+
case "pendingBranchKey":
442+
let nc = segue.destination as! UINavigationController
443+
let vc = nc.topViewController as! TextViewFormTableViewController
444+
vc.sender = sender as! String
445+
vc.viewTitle = "Branch Key"
446+
vc.header = "Branch Key"
447+
vc.footer = "This Branch key will be used the next time the application is closed (not merely backgrounded) and re-opened."
448+
vc.keyboardType = UIKeyboardType.alphabet
449+
vc.incumbantValue = DataStore.getPendingBranchKey()!
458450
default:
459451
break
460452
}
@@ -537,6 +529,14 @@ class ViewController: UITableViewController {
537529
DataStore.setCustomEventName(customEventName)
538530
self.customEventNameTextField.text = customEventName
539531
}
532+
case "pendingBranchKey":
533+
if let pendingBranchKey = vc.textView.text {
534+
guard self.pendingBranchKeyTextField.text != pendingBranchKey else {
535+
return
536+
}
537+
DataStore.setPendingBranchKey(pendingBranchKey)
538+
self.pendingBranchKeyTextField.text = pendingBranchKey
539+
}
540540
default: break
541541
}
542542
}
@@ -668,6 +668,14 @@ class ViewController: UITableViewController {
668668
} else {
669669
customEventMetadataTextView.text = ""
670670
}
671+
activeBranchKeyTextField.text = DataStore.getActiveBranchKey()
672+
activeSetDebugEnabledSwitch.isOn = DataStore.getActiveSetDebugEnabled()!
673+
pendingBranchKeyTextField.text = DataStore.getPendingBranchKey()
674+
pendingSetDebugEnabledSwitch.isOn = DataStore.getPendingSetDebugEnabled()!
675+
676+
if activeBranchKeyTextField.text == "" {
677+
showAlert("Initialization Failure", withDescription: "Close and re-open app to initialize Branch")
678+
}
671679
}
672680

673681
func showAlert(_ alertTitle: String, withDescription message: String) {

0 commit comments

Comments
 (0)