Skip to content

Commit 09cda1d

Browse files
author
Edward Smith
committed
Updated example for iOS 7 and updated version.
1 parent befa0f8 commit 09cda1d

File tree

9 files changed

+97
-49
lines changed

9 files changed

+97
-49
lines changed

Branch-SDK/Branch-SDK/BNCConfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
NSString * const BNC_API_VERSION = @"v1";
1818
NSString * const BNC_LINK_URL = @"https://bnc.lt";
19-
NSString * const BNC_SDK_VERSION = @"0.14.7";
19+
NSString * const BNC_SDK_VERSION = @"0.14.8";

Branch-SDK/Branch-SDK/BranchShareLink.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ - (void) shareDidComplete:(BOOL)completed activityError:(NSError*)error {
109109
// Log share initiated event
110110
[self.universalObject userCompletedAction:BNCShareInitiatedEvent];
111111

112+
NSMutableArray *items = [NSMutableArray new];
112113
BranchShareActivityItem *item = nil;
113-
_activityItems = [NSPointerArray weakObjectsPointerArray];
114114
if (self.shareText.length) {
115115
item = [[BranchShareActivityItem alloc] initWithPlaceholderItem:self.shareText];
116116
item.itemType = BranchShareActivityItemTypeShareText;
117117
item.parent = self;
118-
[_activityItems addPointer:(__bridge void * _Nullable)(item)];
118+
[items addObject:item];
119119
}
120120

121121
NSString *URLString =
@@ -130,16 +130,22 @@ - (void) shareDidComplete:(BOOL)completed activityError:(NSError*)error {
130130
item = [[BranchShareActivityItem alloc] initWithPlaceholderItem:URL];
131131
item.itemType = BranchShareActivityItemTypeBranchURL;
132132
item.parent = self;
133+
[items addObject:item];
134+
133135
[_activityItems addPointer:(__bridge void * _Nullable)(item)];
134136

135137
if (self.shareObject) {
136138
item = [[BranchShareActivityItem alloc] initWithPlaceholderItem:self.shareObject];
137139
item.itemType = BranchShareActivityItemTypeOther;
138140
item.parent = self;
139-
[_activityItems addPointer:(__bridge void * _Nullable)(item)];
141+
[items addObject:item];
140142
}
141143

142-
return [_activityItems allObjects];
144+
_activityItems = [NSPointerArray weakObjectsPointerArray];
145+
for (item in items)
146+
[_activityItems addPointer:(__bridge void * _Nullable)(item)];
147+
148+
return items;
143149
}
144150

145151
- (void) presentActivityViewControllerFromViewController:(UIViewController*_Nullable)viewController

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ class ViewController: UITableViewController, BranchShareLinkDelegate {
210210
return _dateFormatter!
211211
}
212212

213+
//MARK: - Share a Branch Universal Object with BranchShareLink
214+
213215
@IBAction func shareBranchLinkAction(_ sender: AnyObject) {
214216
let canonicalIdentifier = "id-" + self.dateFormatter().string(from: Date.init())
215217

@@ -327,6 +329,8 @@ class ViewController: UITableViewController, BranchShareLinkDelegate {
327329
}
328330
}
329331

332+
//MARK: - Link Properties
333+
330334
@IBAction func loadLinkPropertiesButtonTouchUpInside(_ sender: AnyObject) {
331335
let branch = Branch.getInstance()
332336
let params: Dictionary = (branch?.getLatestReferringParams())!
@@ -383,10 +387,10 @@ class ViewController: UITableViewController, BranchShareLinkDelegate {
383387
if (error == nil) {
384388
print(self.branchLinkProperties.description())
385389
print(self.branchUniversalObject.description())
386-
print("Link Created: \(url?.description)")
390+
print("Link Created: \(String(describing: url?.description))")
387391
self.linkTextField.text = url
388392
} else {
389-
print(String(format: "Branch TestBed: %@", error as! CVarArg))
393+
print(String(format: "Branch TestBed: %@", error! as CVarArg))
390394
self.showAlert("Link Creation Failed", withDescription: error!.localizedDescription)
391395
}
392396

@@ -406,7 +410,7 @@ class ViewController: UITableViewController, BranchShareLinkDelegate {
406410
}
407411

408412
if (error != nil || !changed) {
409-
print(String(format: "Branch TestBed: Didn't redeem anything: %@", error as! CVarArg))
413+
print(String(format: "Branch TestBed: Didn't redeem anything: %@", error! as CVarArg))
410414
self.showAlert("Redemption Unsuccessful", withDescription: error!.localizedDescription)
411415
} else {
412416
print("Branch TestBed: Five Points Redeemed!")

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

Lines changed: 18 additions & 17 deletions
Large diffs are not rendered by default.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="rgL-wI-yV3">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="rgL-wI-yV3">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
77
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
99
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
1010
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1111
</dependencies>
@@ -319,7 +319,7 @@
319319
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
320320
</state>
321321
<connections>
322-
<action selector="shareLinkButtonTouchUpInside:" destination="i3m-ex-Bu1" eventType="touchUpInside" id="yok-zE-KD6"/>
322+
<action selector="shareLinkAsActivityItem:" destination="i3m-ex-Bu1" eventType="touchUpInside" id="1yu-mO-vP8"/>
323323
</connections>
324324
</button>
325325
</subviews>

Branch-TestBed/Branch-TestBed/ViewController.m

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ - (IBAction)simulateContentAccessButtonTouchUpInsideButtonTouchUpInside:(id)send
206206
[self showAlert:@"Content Access Registered" withDescription:@""];
207207
}
208208

209+
- (NSDateFormatter*) dateFormatter {
210+
if (_dateFormatter) return _dateFormatter;
211+
212+
_dateFormatter = [[NSDateFormatter alloc] init];
213+
_dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
214+
_dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssX";
215+
_dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
216+
return _dateFormatter;
217+
}
218+
219+
#pragma mark - Share a Branch Link
209220

210221
- (IBAction)oldShareLinkButtonTouchUpInside:(id)sender {
211222
// This method uses the old way of sharing Branch links.
@@ -216,23 +227,17 @@ - (IBAction)oldShareLinkButtonTouchUpInside:(id)sender {
216227
[linkProperties addControlParam:@"$desktop_url" withValue: desktop_url];
217228
[linkProperties addControlParam:@"$ios_url" withValue: ios_url];
218229

219-
[self.branchUniversalObject showShareSheetWithLinkProperties:linkProperties andShareText:shareText fromViewController:self.parentViewController completion:^(NSString *activityType, BOOL completed) {
220-
if (completed) {
221-
NSLog(@"%@", [NSString stringWithFormat:@"Branch TestBed: Completed sharing to %@", activityType]);
222-
} else {
223-
NSLog(@"%@", [NSString stringWithFormat:@"Branch TestBed: Sharing failed"]);
230+
[self.branchUniversalObject showShareSheetWithLinkProperties:linkProperties
231+
andShareText:shareText
232+
fromViewController:self.parentViewController
233+
completion:^(NSString *activityType, BOOL completed) {
234+
if (completed) {
235+
NSLog(@"Branch TestBed: Completed sharing to %@", activityType);
236+
} else {
237+
NSLog(@"Branch TestBed: Sharing failed");
238+
}
224239
}
225-
}];
226-
}
227-
228-
- (NSDateFormatter*) dateFormatter {
229-
if (_dateFormatter) return _dateFormatter;
230-
231-
_dateFormatter = [[NSDateFormatter alloc] init];
232-
_dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
233-
_dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssX";
234-
_dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
235-
return _dateFormatter;
240+
];
236241
}
237242

238243
- (IBAction)shareLinkButtonTouchUpInside:(id)sender {
@@ -258,8 +263,38 @@ - (IBAction)shareLinkButtonTouchUpInside:(id)sender {
258263
[shareLink presentActivityViewControllerFromViewController:self anchor:nil];
259264
}
260265

266+
- (IBAction)shareLinkAsActivityItem:(id)sender {
267+
// Share as an activity item.
268+
269+
BranchLinkProperties *linkProperties = [[BranchLinkProperties alloc] init];
270+
linkProperties.feature = feature;
271+
linkProperties.campaign = @"sharing campaign";
272+
[linkProperties addControlParam:@"$desktop_url" withValue: desktop_url];
273+
[linkProperties addControlParam:@"$ios_url" withValue: ios_url];
274+
275+
BranchShareLink *shareLink =
276+
[[BranchShareLink alloc]
277+
initWithUniversalObject:self.branchUniversalObject
278+
linkProperties:linkProperties];
279+
280+
shareLink.title = @"Share your test link!";
281+
shareLink.delegate = self;
282+
shareLink.shareText = [NSString stringWithFormat:
283+
@"Shared from Branch's Branch-TestBed at %@.",
284+
[self.dateFormatter stringFromDate:[NSDate date]]];
285+
286+
UIActivityViewController *activityController =
287+
[[UIActivityViewController alloc]
288+
initWithActivityItems:shareLink.activityItems
289+
applicationActivities:nil];
290+
291+
if (activityController) {
292+
[self presentViewController:activityController animated:YES completion:nil];
293+
}
294+
}
295+
261296
- (void) branchShareLinkWillShare:(BranchShareLink*)shareLink {
262-
// This example shows changing the share text.
297+
// This delegate example shows changing the share text.
263298
//
264299
// Link properties, such as alias or channel can be overridden here based on the users'
265300
// choice stored in shareSheet.activityType.
@@ -283,6 +318,8 @@ - (void) branchShareLink:(BranchShareLink*)shareLink
283318
}
284319
}
285320

321+
#pragma mark - Commerce Events
322+
286323
- (IBAction) sendCommerceEvent:(id)sender {
287324
BNCProduct *product = [BNCProduct new];
288325
product.price = [NSDecimalNumber decimalNumberWithString:@"1000.99"];

Branch.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "Branch"
3-
s.version = "0.14.7"
3+
s.version = "0.14.8"
44
s.summary = "Create an HTTP URL for any piece of content in your app"
55
s.description = <<-DESC
66
- Want the highest possible conversions on your sharing feature?

carthage-files/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.14.7</string>
18+
<string>0.14.8</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>0.14.7</string>
22+
<string>0.14.8</string>
2323
<key>NSPrincipalClass</key>
2424
<string></string>
2525
</dict>

scripts/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Options:
3131
USAGE
3232
}
3333

34-
version=0.14.7
34+
version=0.14.8
3535

3636
if (( $# == 0 )); then
3737
echo $version

0 commit comments

Comments
 (0)