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 {
0 commit comments