Skip to content

Commit 1e4f54d

Browse files
parthkalavadiaE-B-Smith
authored andcommitted
Show functionality added to automatic DeepLink Controller - AIS-254 (#629)
* Show the functionality added to automatic deep link Controller. * Updated the Test-bed app to support the new functionality. * Support for the old API added to present deeplinking controller. * BranchDeepLinkingControllerCompletionDelegate updated to support new API. * Logs api changed to BNCLogWarning to support new version of SDK. * The change log for show view controller updated. * The readme was updated with docs of show functionality. * Minor changes according to reviews * Removed the automatic deep link controller from testbed projects
1 parent f050980 commit 1e4f54d

File tree

11 files changed

+256
-35
lines changed

11 files changed

+256
-35
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// BNCDeepLinkViewControllerInstance.h
3+
// Branch-TestBed
4+
//
5+
// Created by Parth Kalavadia on 5/15/17.
6+
// Copyright © 2017 Parth Kalavadia. All rights reserved.
7+
//
8+
#import <Foundation/Foundation.h>
9+
#import "BranchDeepLinkingController.h"
10+
@interface BNCDeepLinkViewControllerInstance : NSObject
11+
12+
@property (strong, nonatomic)UIViewController<BranchDeepLinkingController>* viewController;
13+
@property (assign)BNCViewControllerPresentationOption option;
14+
15+
@end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// BNCDeepLinkViewControllerInstance.m
3+
// Branch-TestBed
4+
//
5+
// Created by Parth Kalavadia on 5/15/17.
6+
// Copyright © 2017 Parth Kalavadia. All rights reserved.
7+
//
8+
#import "BNCDeepLinkViewControllerInstance.h"
9+
10+
@implementation BNCDeepLinkViewControllerInstance
11+
12+
@end

Branch-SDK/Branch-SDK/Branch.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
366366
*/
367367
- (BOOL)handleDeepLink:(NSURL *)url;
368368

369+
369370
/**
370371
Have Branch end the current deep link session and start a new session with the provided URL.
371372
@@ -437,7 +438,14 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
437438
/// @name Deep Link Controller
438439
///---------------------------
439440

440-
- (void)registerDeepLinkController:(UIViewController <BranchDeepLinkingController> *)controller forKey:(NSString *)key;
441+
- (void)registerDeepLinkController:(UIViewController <BranchDeepLinkingController> *)controller forKey:(NSString *)key __attribute__((deprecated(("This API is deprecated. Please use registerDeepLinkController: forKey: withOption:"))));
442+
443+
/**
444+
Allow Branch to handle a view controller with options to push, present or show.
445+
Note:
446+
* If push option is used and the rootviewcontroller of window is not of type UINavigationViewController, than the sharing View controller would be presented automatically
447+
*/
448+
- (void)registerDeepLinkController:(UIViewController <BranchDeepLinkingController> *)controller forKey:(NSString *)key withPresentation:(BNCViewControllerPresentationOption)option;
441449

442450
#pragma mark - Configuration methods
443451

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 147 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#import "BNCEncodingUtils.h"
2020
#import "BNCContentDiscoveryManager.h"
2121
#import "BNCStrongMatchHelper.h"
22+
#import "BNCDeepLinkViewControllerInstance.h"
2223
#import "BranchUniversalObject.h"
2324
#import "BranchSetIdentityRequest.h"
2425
#import "BranchLogoutRequest.h"
@@ -694,7 +695,7 @@ - (BOOL)checkAppleSearchAdsAttribution {
694695
[ADClientClass methodForSelector:sharedClient];
695696

696697
if (!ADClientIsAvailable) {
697-
BNCLogWarning(@"delayForAppleAds is true but ADClient is not available. Is the iAD.framework included and iOS 10?");
698+
BNCLogWarning(@"`delayForAppleAds` is true but ADClient is not available. Is the iAD.framework included and iOS 10?");
698699
return NO;
699700
}
700701

@@ -790,6 +791,16 @@ - (void)registerDeepLinkController:(UIViewController <BranchDeepLinkingControlle
790791
self.deepLinkControllers[key] = controller;
791792
}
792793

794+
- (void)registerDeepLinkController:(UIViewController <BranchDeepLinkingController> *)controller forKey:(NSString *)key withPresentation:(BNCViewControllerPresentationOption)option{
795+
796+
BNCDeepLinkViewControllerInstance* deepLinkModal = [[BNCDeepLinkViewControllerInstance alloc] init];
797+
798+
deepLinkModal.viewController = controller;
799+
deepLinkModal.option = option;
800+
801+
self.deepLinkControllers[key] = deepLinkModal;
802+
}
803+
793804

794805
#pragma mark - Identity methods
795806

@@ -1660,7 +1671,7 @@ - (void)initializeSession {
16601671
}
16611672

16621673
- (void)handleInitSuccess {
1663-
1674+
16641675
self.isInitialized = YES;
16651676
NSDictionary *latestReferringParams = [self getLatestReferringParams];
16661677
if (self.shouldCallSessionInitCallback) {
@@ -1669,10 +1680,10 @@ - (void)handleInitSuccess {
16691680
}
16701681
else if (self.sessionInitWithBranchUniversalObjectCallback) {
16711682
self.sessionInitWithBranchUniversalObjectCallback(
1672-
[self getLatestReferringBranchUniversalObject],
1673-
[self getLatestReferringBranchLinkProperties],
1674-
nil
1675-
);
1683+
[self getLatestReferringBranchUniversalObject],
1684+
[self getLatestReferringBranchLinkProperties],
1685+
nil
1686+
);
16761687
}
16771688
}
16781689

@@ -1698,18 +1709,114 @@ - (void)handleInitSuccess {
16981709
branchSharingController.deepLinkingCompletionDelegate = self;
16991710
self.deepLinkPresentingController = [[[UIApplicationClass sharedApplication].delegate window] rootViewController];
17001711

1701-
if ([self.deepLinkPresentingController presentedViewController]) {
1702-
[self.deepLinkPresentingController dismissViewControllerAnimated:NO completion:^{
1703-
[self.deepLinkPresentingController presentViewController:branchSharingController animated:YES completion:NULL];
1704-
}];
1712+
if([self.deepLinkControllers[key] isKindOfClass:[BNCDeepLinkViewControllerInstance class]]) {
1713+
BNCDeepLinkViewControllerInstance* deepLinkInstance = self.deepLinkControllers[key];
1714+
UIViewController <BranchDeepLinkingController> *branchSharingController = deepLinkInstance.viewController;
1715+
1716+
if ([branchSharingController respondsToSelector:@selector(configureControlWithData:)]) {
1717+
[branchSharingController configureControlWithData:latestReferringParams];
1718+
}
1719+
else {
1720+
BNCLogWarning(@"View controller does not implement configureControlWithData:");
1721+
}
1722+
branchSharingController.deepLinkingCompletionDelegate = self;
1723+
self.deepLinkPresentingController = [[[UIApplicationClass sharedApplication].delegate window] rootViewController];
1724+
switch (deepLinkInstance.option) {
1725+
case BNCViewControllerOptionPresent:
1726+
[self presentSharingViewController:branchSharingController];
1727+
break;
1728+
1729+
case BNCViewControllerOptionPush:
1730+
1731+
if ([self.deepLinkPresentingController isKindOfClass:[UINavigationController class]]) {
1732+
1733+
if ([[(UINavigationController*)self.deepLinkPresentingController viewControllers] containsObject:branchSharingController]) {
1734+
[self removeViewControllerFromRootNavigationController:branchSharingController];
1735+
[(UINavigationController*)self.deepLinkPresentingController pushViewController:branchSharingController animated:false];
1736+
}
1737+
else {
1738+
[(UINavigationController*)self.deepLinkPresentingController pushViewController:branchSharingController animated:true];
1739+
}
1740+
}
1741+
else {
1742+
deepLinkInstance.option = BNCViewControllerOptionPresent;
1743+
[self presentSharingViewController:branchSharingController];
1744+
}
1745+
1746+
break;
1747+
1748+
default:
1749+
if ([self.deepLinkPresentingController isKindOfClass:[UINavigationController class]]) {
1750+
if ([self.deepLinkPresentingController respondsToSelector:@selector(showViewController:sender:)]) {
1751+
1752+
if ([[(UINavigationController*)self.deepLinkPresentingController viewControllers] containsObject:branchSharingController]) {
1753+
[self removeViewControllerFromRootNavigationController:branchSharingController];
1754+
}
1755+
1756+
[self.deepLinkPresentingController showViewController:branchSharingController sender:self];
1757+
}
1758+
else {
1759+
deepLinkInstance.option = BNCViewControllerOptionPush;
1760+
[(UINavigationController*)self.deepLinkPresentingController pushViewController:branchSharingController animated:true];
1761+
}
1762+
}
1763+
else {
1764+
deepLinkInstance.option = BNCViewControllerOptionPresent;
1765+
[self presentSharingViewController:branchSharingController];
1766+
}
1767+
break;
1768+
}
17051769
}
17061770
else {
1707-
[self.deepLinkPresentingController presentViewController:branchSharingController animated:YES completion:NULL];
1771+
1772+
//Support for old API
1773+
UIViewController <BranchDeepLinkingController> *branchSharingController = self.deepLinkControllers[key];
1774+
if ([branchSharingController respondsToSelector:@selector(configureControlWithData:)]) {
1775+
[branchSharingController configureControlWithData:latestReferringParams];
1776+
}
1777+
else {
1778+
BNCLogWarning(@"View controller does not implement configureControlWithData:");
1779+
}
1780+
branchSharingController.deepLinkingCompletionDelegate = self;
1781+
self.deepLinkPresentingController = [[[UIApplicationClass sharedApplication].delegate window] rootViewController];
1782+
1783+
if ([self.deepLinkPresentingController presentedViewController]) {
1784+
[self.deepLinkPresentingController dismissViewControllerAnimated:NO completion:^{
1785+
[self.deepLinkPresentingController presentViewController:branchSharingController animated:YES completion:NULL];
1786+
}];
1787+
}
1788+
else {
1789+
[self.deepLinkPresentingController presentViewController:branchSharingController animated:YES completion:NULL];
1790+
}
17081791
}
17091792
}
17101793
}
17111794
}
17121795

1796+
-(void)removeViewControllerFromRootNavigationController:(UIViewController*)branchSharingController{
1797+
1798+
NSMutableArray* viewControllers = [NSMutableArray arrayWithArray: [(UINavigationController*)self.deepLinkPresentingController viewControllers]];
1799+
1800+
if ([viewControllers lastObject] == branchSharingController) {
1801+
1802+
[(UINavigationController*)self.deepLinkPresentingController popViewControllerAnimated:YES];
1803+
}else {
1804+
[viewControllers removeObject:branchSharingController];
1805+
((UINavigationController*)self.deepLinkPresentingController).viewControllers = viewControllers;
1806+
}
1807+
}
1808+
1809+
-(void)presentSharingViewController: (UIViewController <BranchDeepLinkingController> *)branchSharingController{
1810+
if ([self.deepLinkPresentingController presentedViewController]) {
1811+
[self.deepLinkPresentingController dismissViewControllerAnimated:NO completion:^{
1812+
[self.deepLinkPresentingController presentViewController:branchSharingController animated:YES completion:NULL];
1813+
}];
1814+
}
1815+
else {
1816+
[self.deepLinkPresentingController presentViewController:branchSharingController animated:YES completion:NULL];
1817+
}
1818+
}
1819+
17131820
- (void)handleInitFailure:(NSError *)error {
17141821
self.isInitialized = NO;
17151822

@@ -1734,6 +1841,35 @@ - (void)deepLinkingControllerCompleted {
17341841
[self.deepLinkPresentingController dismissViewControllerAnimated:YES completion:NULL];
17351842
}
17361843

1844+
- (void)deepLinkingControllerCompletedFrom:(UIViewController *)viewController {
1845+
1846+
[self.deepLinkControllers enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
1847+
1848+
if([obj isKindOfClass:[BNCDeepLinkViewControllerInstance class]]) {
1849+
BNCDeepLinkViewControllerInstance* deepLinkInstance = (BNCDeepLinkViewControllerInstance*) obj;
1850+
1851+
if (deepLinkInstance.viewController == viewController) {
1852+
1853+
switch (deepLinkInstance.option) {
1854+
case BNCViewControllerOptionPresent:
1855+
[viewController dismissViewControllerAnimated:YES completion:nil];
1856+
break;
1857+
1858+
default:
1859+
[self removeViewControllerFromRootNavigationController:viewController];
1860+
break;
1861+
}
1862+
}
1863+
1864+
}else {
1865+
//Support for old API
1866+
if ((UIViewController*)obj == viewController)
1867+
[self.deepLinkPresentingController dismissViewControllerAnimated:YES completion:nil];
1868+
}
1869+
1870+
}];
1871+
}
1872+
17371873
#pragma mark - FABKit methods
17381874

17391875
+ (NSString *)bundleIdentifier {

Branch-SDK/Branch-SDK/BranchDeepLinkingController.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
// Created by Graham Mueller on 6/18/15.
66
// Copyright (c) 2015 Branch Metrics. All rights reserved.
77
//
8-
8+
#import <Foundation/Foundation.h>
9+
#import <UIKit/UIKit.h>
910
@protocol BranchDeepLinkingControllerCompletionDelegate <NSObject>
1011

11-
- (void)deepLinkingControllerCompleted;
12+
- (void)deepLinkingControllerCompleted __attribute__((deprecated(("This API is deprecated. Instead, use deepLinkingControllerCompletedFrom: viewController"))));;
13+
- (void)deepLinkingControllerCompletedFrom:(UIViewController*) viewController;
1214

1315
@end
1416

17+
typedef NS_ENUM(NSInteger, BNCViewControllerPresentationOption) {
18+
BNCViewControllerOptionShow,
19+
BNCViewControllerOptionPush,
20+
BNCViewControllerOptionPresent
21+
};
22+
1523
@protocol BranchDeepLinkingController <NSObject>
1624

1725
- (void)configureControlWithData:(NSDictionary *)data;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
63F65BFA1D654EF30055A2F6 /* DictionaryTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63F65BF91D654EF30055A2F6 /* DictionaryTableViewCell.swift */; };
8181
63F8BB201D57D2BE0013B6F7 /* LinkPropertiesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63F8BB1F1D57D2BE0013B6F7 /* LinkPropertiesTableViewController.swift */; };
8282
63F8BB241D57E7730013B6F7 /* ArrayTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63F8BB231D57E7730013B6F7 /* ArrayTableViewController.swift */; };
83+
F155BFEF1EF37EDB00BF4566 /* BNCLog.m in Sources */ = {isa = PBXBuildFile; fileRef = F155BFEE1EF37EDB00BF4566 /* BNCLog.m */; };
84+
F155BFF21EF37EEA00BF4566 /* BNCDeepLinkViewControllerInstance.m in Sources */ = {isa = PBXBuildFile; fileRef = F155BFF11EF37EEA00BF4566 /* BNCDeepLinkViewControllerInstance.m */; };
8385
/* End PBXBuildFile section */
8486

8587
/* Begin PBXFileReference section */
@@ -215,6 +217,10 @@
215217
63F65BF91D654EF30055A2F6 /* DictionaryTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryTableViewCell.swift; sourceTree = "<group>"; };
216218
63F8BB1F1D57D2BE0013B6F7 /* LinkPropertiesTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkPropertiesTableViewController.swift; sourceTree = "<group>"; };
217219
63F8BB231D57E7730013B6F7 /* ArrayTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayTableViewController.swift; sourceTree = "<group>"; };
220+
F155BFED1EF37EDB00BF4566 /* BNCLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNCLog.h; sourceTree = "<group>"; };
221+
F155BFEE1EF37EDB00BF4566 /* BNCLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCLog.m; sourceTree = "<group>"; };
222+
F155BFF01EF37EEA00BF4566 /* BNCDeepLinkViewControllerInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNCDeepLinkViewControllerInstance.h; sourceTree = "<group>"; };
223+
F155BFF11EF37EEA00BF4566 /* BNCDeepLinkViewControllerInstance.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCDeepLinkViewControllerInstance.m; sourceTree = "<group>"; };
218224
/* End PBXFileReference section */
219225

220226
/* Begin PBXFrameworksBuildPhase section */
@@ -319,8 +325,15 @@
319325
4D4F28161E400F9800282A34 /* BranchViewHandler.m */,
320326
4D4F28171E400F9800282A34 /* NSMutableDictionary+Branch.h */,
321327
4D4F28181E400F9800282A34 /* NSMutableDictionary+Branch.m */,
328+
<<<<<<< HEAD
329+
F155BFF01EF37EEA00BF4566 /* BNCDeepLinkViewControllerInstance.h */,
330+
F155BFF11EF37EEA00BF4566 /* BNCDeepLinkViewControllerInstance.m */,
331+
F155BFED1EF37EDB00BF4566 /* BNCLog.h */,
332+
F155BFEE1EF37EDB00BF4566 /* BNCLog.m */,
333+
=======
322334
4DB47D5C1F042C5900C53C29 /* NSString+Branch.h */,
323335
4DB47D5D1F042C5900C53C29 /* NSString+Branch.m */,
336+
>>>>>>> 12ca4d3428198933aac335d042e534dbd4e81da8
324337
4D4F28191E400F9800282A34 /* Requests */,
325338
);
326339
path = "Branch-SDK";
@@ -558,6 +571,7 @@
558571
4D4F28571E400F9800282A34 /* BranchView.m in Sources */,
559572
4D4F28591E400F9800282A34 /* NSMutableDictionary+Branch.m in Sources */,
560573
4D4F28601E400F9800282A34 /* BranchOpenRequest.m in Sources */,
574+
F155BFF21EF37EEA00BF4566 /* BNCDeepLinkViewControllerInstance.m in Sources */,
561575
4D4F28401E400F9800282A34 /* BNCContentDiscoveryManager.m in Sources */,
562576
4D4F28411E400F9800282A34 /* BNCDeviceInfo.m in Sources */,
563577
4D4F28451E400F9800282A34 /* BNCLinkCache.m in Sources */,
@@ -569,6 +583,7 @@
569583
63F8BB241D57E7730013B6F7 /* ArrayTableViewController.swift in Sources */,
570584
63AAF1011CF7F58900CA98BD /* ContentViewController.swift in Sources */,
571585
63F8BB201D57D2BE0013B6F7 /* LinkPropertiesTableViewController.swift in Sources */,
586+
F155BFEF1EF37EDB00BF4566 /* BNCLog.m in Sources */,
572587
6306FFF11D6BEFA30031D2E3 /* ArrayTableViewCell.swift in Sources */,
573588
4D4F285B1E400F9800282A34 /* BranchCloseRequest.m in Sources */,
574589
4D9E765C1E774DB100BD0620 /* BranchShareLink.m in Sources */,

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2727
DataStore.setActiveBranchKey(defaultBranchKey)
2828
}
2929

30-
31-
// Deeplinking logic for use when automaticallyDisplayDeepLinkController = true
32-
/*
33-
let navigationController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as! UINavigationController
34-
branch.registerDeepLinkController(navigationController, forKey:"~referring_link")
35-
36-
*/
37-
38-
3930
if let branch = Branch.getInstance(branchKey) {
4031

32+
branch.setDebug();
4133
if DataStore.getPendingSetDebugEnabled()! {
4234
branch.setDebug()
4335
DataStore.setActivePendingSetDebugEnabled(true)
4436
} else {
4537
DataStore.setActivePendingSetDebugEnabled(false)
4638
}
47-
48-
39+
branch.registerDeepLinkController(kCATransitionFromLeft, forKey: <#T##String!#>, withPresentation: <#T##BNCViewControllerPresentationOption#>)
4940
branch.initSession(launchOptions: launchOptions, andRegisterDeepLinkHandler: { (params, error) in
5041
if (error == nil) {
5142

0 commit comments

Comments
 (0)