Skip to content

Commit 28c0f69

Browse files
author
David Westgate
committed
Added new TestBed-Swift
1 parent 78e9a00 commit 28c0f69

File tree

60 files changed

+6637
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+6637
-0
lines changed

Branch-TestBed-Swift/Podfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
platform :ios, '7.0'
2+
3+
target "TestBed-Swift" do
4+
pod "Branch"
5+
end

Branch-TestBed-Swift/Podfile.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
PODS:
2+
- Branch (0.12.11):
3+
- Branch/Core (= 0.12.11)
4+
- Branch/without-IDFA (= 0.12.11)
5+
- Branch/Core (0.12.11)
6+
- Branch/without-IDFA (0.12.11)
7+
8+
DEPENDENCIES:
9+
- Branch
10+
11+
SPEC CHECKSUMS:
12+
Branch: a620b19dc96fffabb7873a86c80c77c75395a664
13+
14+
PODFILE CHECKSUM: b8eaac19532c4179c1c4ce62932a85facd7ac4b7
15+
16+
COCOAPODS: 1.0.0

Branch-TestBed-Swift/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
7+
## Create a personal copy of Branch's Swift TestBed app for testing!
8+
9+
1. From the command line:
10+
- Clone the repo: `git clone [email protected]:BranchMetrics/ios-branch-deep-linking.git`
11+
- `cd ios-branch-deep-linking/Branch-TestBed-Swift`
12+
- `pod install`
13+
2. In Finder open: **TestBed-Swift.xcworkspace**
14+
3. In Xcode click on the root node of the project: TestBed-Swift
15+
4. Under Targets select TestBed-Swift, then the General tab
16+
5. Change the Bundle Identifier to something **unique** (for this demo we'll use `io.branch.Swift.TestBed`)
17+
6. Change the Team to your Team (it must be a *paid* Apple Developer Account) and click **Fix Issue** to generate a new Provisioning Profile
18+
7. Log in to the [Branch dashboard](https://dashboard.branch.io) and create a new app from the drop-down menu in the top right corner
19+
8. On the Settings, screen copy the Branch key
20+
9. In the Xcode project's **info.plist** file, change the `branch_key` entry to the value of your new Branch key key
21+
10. Add a new String key to the **info.plist** file: `branch_app_domain`
22+
11. Populate the new `branch_app_domain` key with the value of the **Default domain name** field found in the Custom Link Domain section of the dashboard's Link Settings tab
23+
12. Populate the Branch dashboard with the following values:
24+
- Always try to open app: Checked
25+
- I have an iOS App: Checked
26+
- iOS URL: `swift-testbed://` (from the **info.plist** file, this is URL Types > URL Schemes > Item 0)
27+
- Custom URL: (enter a web site here if you haven't published the app to the App Store - http://www.branch.io, for example)
28+
- Default URL: (any web site will do: http://www.branch.io, for example)
29+
30+
## Set up Universal Links
31+
32+
> **NOTE:** these steps will not work if you do not have a *paid* Apple Developer Account
33+
34+
1. In the **TestBed-Swift.entitlements** file, add entries for the new Branch Live and Test link domains. For example:
35+
- **applinks:xxxx.app.link**
36+
- **applinks:xxxx.test-app.link**
37+
- **applinks:xxxx-alternate.app.link**
38+
- **applinks:xxxx-alternate.test-app.link**
39+
2. Run the app and make sure that it launches properly on a device or on a simulator
40+
3. Select the **TestBed-Swift.entitlements** file and ensure the **TestBed-Swift** box is checked inside Target Membership
41+
4. Populate the Branch dashboard with the following values:
42+
- Enable Universal Links: checked
43+
- Bundle Identifier: as set in the project above
44+
- Apple App Prefix: (find this in the Apple developer dashboard: https://developer.apple.com/account/ios/identifier/bundle)
45+
4. Save the settings - you are done!
46+
47+
### Test
48+
1. If the app was installed on the test device already:
49+
- Delete the app from the device
50+
- Clear Safari web content, history and cookies (Settings > Safari > Clear History and Website Data)
51+
- Reset the device's IDFA (Settings > Privacy > Advertising > Reset Advertising Identifier...)
52+
2. Create a Marketing link from the Branch dashboard
53+
3. Paste the link into Notes on an iPhone
54+
4. Tap the link - you will get redirected to the web page
55+
5. Install the app on the device via Xcode
56+
6. Tapping on the link should now open the app directly

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

Lines changed: 508 additions & 0 deletions
Large diffs are not rendered by default.

Branch-TestBed-Swift/TestBed-Swift.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Branch-TestBed-Swift/TestBed-Swift.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//
2+
// AppDelegate.swift
3+
// TestBed-Swift
4+
//
5+
// Created by David Westgate on 8/29/16.
6+
// Copyright © 2016 Branch Metrics. All rights reserved.
7+
//
8+
import UIKit
9+
10+
@UIApplicationMain
11+
class AppDelegate: UIResponder, UIApplicationDelegate {
12+
13+
var window: UIWindow?
14+
15+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
16+
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+
}
38+
39+
let navigationController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as! UINavigationController
40+
branch.registerDeepLinkController(navigationController, forKey:"~referring_link")
41+
42+
// Required. Initialize session. automaticallyDisplayDeepLinkController is optional (default is false).
43+
branch.initSession(launchOptions: launchOptions, automaticallyDisplayDeepLinkController: true, deepLinkHandler: { params, error in
44+
45+
if (error == nil) {
46+
47+
// Deeplinking logic for use when automaticallyDisplayDeepLinkController = false
48+
/*
49+
if let clickedBranchLink = params[BRANCH_INIT_KEY_CLICKED_BRANCH_LINK] as! Bool? {
50+
51+
if clickedBranchLink {
52+
53+
let nc = self.window!.rootViewController as! UINavigationController
54+
let storyboard = UIStoryboard(name: "Main", bundle: nil)
55+
let contentViewController = storyboard.instantiateViewController(withIdentifier: "Content") as! ContentViewController
56+
nc.pushViewController(contentViewController, animated: true)
57+
58+
let dict = params as Dictionary
59+
let referringLink = dict["~referring_link"]
60+
let content = String(format:"\nReferring link: \(referringLink)\n\nSession Details:\n\(dict.JSONDescription())")
61+
contentViewController.content = content
62+
63+
}
64+
} else {
65+
print(String(format: "Branch TestBed: Finished init with params\n%@", params.description))
66+
}
67+
*/
68+
69+
} else {
70+
print("Branch TestBed: Initialization failed\n%@", error!.localizedDescription)
71+
}
72+
let notificationName = Notification.Name("BranchCallbackCompleted")
73+
NotificationCenter.default.post(name: notificationName, object: nil)
74+
})
75+
} else {
76+
print("Branch TestBed: Invalid Key\n")
77+
DataStore.setActiveBranchKey("")
78+
DataStore.setPendingBranchKey("")
79+
}
80+
return true
81+
}
82+
83+
// Respond to URI scheme links
84+
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
85+
if (!Branch.getInstance().handleDeepLink(url)) {
86+
// do other deep link routing for the Facebook SDK, Pinterest SDK, etc
87+
}
88+
89+
return true
90+
}
91+
92+
// Respond to Universal Links
93+
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
94+
// pass the url to the handle deep link call
95+
Branch.getInstance().continue(userActivity);
96+
return true
97+
}
98+
99+
func application(_ application: UIApplication, didReceiveRemoteNotification launchOptions: [AnyHashable: Any]) -> Void {
100+
Branch.getInstance().handlePushNotification(launchOptions)
101+
}
102+
103+
func applicationWillResignActive(_ application: UIApplication) {
104+
}
105+
106+
func applicationDidEnterBackground(_ application: UIApplication) {
107+
}
108+
109+
func applicationWillEnterForeground(_ application: UIApplication) {
110+
}
111+
112+
func applicationDidBecomeActive(_ application: UIApplication) {
113+
}
114+
115+
func applicationWillTerminate(_ application: UIApplication) {
116+
}
117+
118+
}
119+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// ArrayTableViewCell.swift
3+
// TestBed-Swift
4+
//
5+
// Created by David Westgate on 8/29/16.
6+
// Copyright © 2016 Branch Metrics. All rights reserved.
7+
//
8+
import UIKit
9+
10+
class ArrayTableViewCell: UITableViewCell {
11+
12+
@IBOutlet weak var elementLabel: UILabel!
13+
14+
override func awakeFromNib() {
15+
super.awakeFromNib()
16+
}
17+
18+
override func setSelected(_ selected: Bool, animated: Bool) {
19+
super.setSelected(selected, animated: animated)
20+
}
21+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//
2+
// ArrayTableViewController.swift
3+
// TestBed-Swift
4+
//
5+
// Created by David Westgate on 8/29/16.
6+
// Copyright © 2016 Branch Metrics. All rights reserved.
7+
//
8+
import UIKit
9+
10+
class ArrayTableViewController: UITableViewController {
11+
12+
var array = [String]()
13+
var incumbantValue = ""
14+
var viewTitle = "Default Array Title"
15+
var header = "Default Array Header"
16+
var placeholder = "Default Array Placeholder"
17+
var footer = "Default Array Footer"
18+
var keyboardType = UIKeyboardType.default
19+
20+
override func viewDidLoad() {
21+
super.viewDidLoad()
22+
23+
title = viewTitle
24+
}
25+
26+
override func didReceiveMemoryWarning() {
27+
super.didReceiveMemoryWarning()
28+
}
29+
30+
// MARK: - Table view data source
31+
32+
override func numberOfSections(in tableView: UITableView) -> Int {
33+
return 1
34+
}
35+
36+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
37+
return array.count
38+
}
39+
40+
41+
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
42+
43+
let cellIdentifier = "ArrayTableViewCell"
44+
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! ArrayTableViewCell
45+
46+
cell.elementLabel.text = array[(indexPath as NSIndexPath).row]
47+
48+
return cell
49+
}
50+
51+
52+
// Override to support conditional editing of the table view.
53+
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
54+
// Return false if you do not want the specified item to be editable.
55+
return true
56+
}
57+
58+
59+
// Override to support editing the table view.
60+
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
61+
if editingStyle == .delete {
62+
// Delete the row from the data source
63+
array.remove(at: (indexPath as NSIndexPath).row)
64+
65+
tableView.deleteRows(at: [indexPath], with: .fade)
66+
} else if editingStyle == .insert {
67+
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
68+
}
69+
}
70+
71+
override func viewWillDisappear(_ animated: Bool) {
72+
super.viewWillDisappear(animated)
73+
}
74+
75+
76+
// MARK: - Navigation
77+
78+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
79+
if segue.identifier == "AddElement" {
80+
let nc = segue.destination as! UINavigationController
81+
let vc = nc.topViewController as! TextFieldFormTableViewController
82+
vc.incumbantValue = incumbantValue
83+
vc.viewTitle = viewTitle
84+
vc.header = header
85+
vc.placeholder = placeholder
86+
vc.footer = footer
87+
vc.keyboardType = UIKeyboardType.default
88+
}
89+
}
90+
91+
@IBAction func unwindByCancelling(_ segue:UIStoryboardSegue) { }
92+
93+
@IBAction func unwindTextFieldFormTableViewController(_ sender: UIStoryboardSegue) {
94+
if let vc = sender.source as? TextFieldFormTableViewController {
95+
96+
if let receivedValue = vc.textField.text {
97+
98+
guard receivedValue.characters.count > 0 else {
99+
return
100+
}
101+
102+
guard !array.contains(receivedValue) else {
103+
return
104+
}
105+
106+
array.append(receivedValue)
107+
array.sort()
108+
tableView.reloadData()
109+
110+
}
111+
}
112+
}
113+
114+
}

0 commit comments

Comments
 (0)