Skip to content

Commit cef92ee

Browse files
authored
Added an example of opening a Branch link in-app. (#621)
1 parent bbfa61d commit cef92ee

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</viewController>
4545
<placeholder placeholderIdentifier="IBFirstResponder" id="iyd-KZ-HuG" userLabel="First Responder" sceneMemberID="firstResponder"/>
4646
</objects>
47-
<point key="canvasLocation" x="2616" y="712"/>
47+
<point key="canvasLocation" x="2501" y="502"/>
4848
</scene>
4949
<!--Branch-TestBed-->
5050
<scene sceneID="6p6-00-fPO">
@@ -479,9 +479,39 @@
479479
</tableViewCellContentView>
480480
<color key="backgroundColor" red="0.14117647059999999" green="0.14117647059999999" blue="0.14117647059999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
481481
</tableViewCell>
482-
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="ekc-rb-YQC">
482+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="hIc-Wy-IwP">
483483
<rect key="frame" x="0.0" y="528" width="375" height="44"/>
484484
<autoresizingMask key="autoresizingMask"/>
485+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="hIc-Wy-IwP" id="a7U-nA-KGh">
486+
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
487+
<autoresizingMask key="autoresizingMask"/>
488+
<subviews>
489+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iq4-GJ-TsK">
490+
<rect key="frame" x="92.5" y="8" width="190" height="27"/>
491+
<color key="backgroundColor" red="0.28235294119999998" green="0.2784313725" blue="0.28627450980000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
492+
<constraints>
493+
<constraint firstAttribute="height" constant="27" id="V81-5w-ylh"/>
494+
<constraint firstAttribute="width" constant="190" id="voP-Ga-PLG"/>
495+
</constraints>
496+
<fontDescription key="fontDescription" type="system" pointSize="12"/>
497+
<state key="normal" title="Open Branch Link">
498+
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
499+
</state>
500+
<connections>
501+
<action selector="openBranchLinkInApp:" destination="i3m-ex-Bu1" eventType="touchUpInside" id="aKD-Pr-t8d"/>
502+
</connections>
503+
</button>
504+
</subviews>
505+
<constraints>
506+
<constraint firstItem="iq4-GJ-TsK" firstAttribute="centerX" secondItem="a7U-nA-KGh" secondAttribute="centerX" id="5u5-aB-u5a"/>
507+
<constraint firstItem="iq4-GJ-TsK" firstAttribute="top" secondItem="a7U-nA-KGh" secondAttribute="topMargin" id="95W-kB-LM5"/>
508+
</constraints>
509+
</tableViewCellContentView>
510+
<color key="backgroundColor" red="0.14117647059999999" green="0.14117647059999999" blue="0.14117647059999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
511+
</tableViewCell>
512+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="ekc-rb-YQC">
513+
<rect key="frame" x="0.0" y="572" width="375" height="44"/>
514+
<autoresizingMask key="autoresizingMask"/>
485515
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ekc-rb-YQC" id="By0-RI-7TX">
486516
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
487517
<autoresizingMask key="autoresizingMask"/>

Branch-TestBed/Branch-TestBed/ViewController.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ - (void) branchShareLink:(BranchShareLink*)shareLink
320320

321321
#pragma mark - Commerce Events
322322

323+
- (IBAction) openBranchLinkInApp:(id)sender {
324+
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:NSUserActivityTypeBrowsingWeb];
325+
NSURL *URL = [NSURL URLWithString:@"https://bnc.lt/ZPOc/Y6aKU0rzcy"]; // <= Your URL goes here.
326+
activity.webpageURL = URL;
327+
Branch *branch = [Branch getInstance];
328+
[branch resetUserSession];
329+
[branch continueUserActivity:activity];
330+
}
331+
323332
- (IBAction) sendCommerceEvent:(id)sender {
324333
BNCProduct *product = [BNCProduct new];
325334
product.price = [NSDecimalNumber decimalNumberWithString:@"1000.99"];
@@ -358,6 +367,8 @@ - (IBAction) sendCommerceEvent:(id)sender {
358367
}];
359368
}
360369

370+
#pragma mark - Spotlight
371+
361372
//example using callbackWithURLandSpotlightIdentifier
362373
- (IBAction)registerWithSpotlightButtonTouchUpInside:(id)sender {
363374
[self.branchUniversalObject addMetadataKey:@"deeplink_text" value:@"This link was generated for Spotlight registration"];

0 commit comments

Comments
 (0)