Skip to content

Commit 2312d1b

Browse files
author
Dan Walkowski
committed
Merge pull request #266 from BranchMetrics/BUO-returns-spotlight-ID
Spotlight IDs returned in indexing callbacks
2 parents a71fc56 + db22af3 commit 2312d1b

File tree

7 files changed

+336
-35
lines changed

7 files changed

+336
-35
lines changed

Branch-SDK/Branch-SDK/BNCContentDiscoveryManager.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,34 @@
1414
- (NSString *)standardSpotlightIdentifierFromActivity:(NSUserActivity *)userActivity;
1515

1616
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description;
17+
1718
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description callback:(callbackWithUrl)callback;
19+
1820
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable callback:(callbackWithUrl)callback;
21+
1922
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type callback:(callbackWithUrl)callback;
23+
2024
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl callback:(callbackWithUrl)callback;
25+
2126
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords callback:(callbackWithUrl)callback;
27+
2228
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords;
29+
2330
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords userInfo:(NSDictionary *)userInfo;
31+
2432
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable thumbnailUrl:(NSURL *)thumbnailUrl userInfo:(NSDictionary *)userInfo;
33+
2534
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords userInfo:(NSDictionary *)userInfo;
35+
2636
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords userInfo:(NSDictionary *)userInfo callback:(callbackWithUrl)callback;
37+
2738
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords userInfo:(NSDictionary *)userInfo expirationDate:(NSDate *)expirationDate callback:(callbackWithUrl)callback;
2839

2940

41+
42+
/* This one has a different callback, which includes the spotlightIdentifier, and requires a different signature
43+
It cannot be part of the stack of method signatures above, because of the different callback type.*/
44+
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords userInfo:(NSDictionary *)userInfo expirationDate:(NSDate *)expirationDate callback:(callbackWithUrl)callback spotlightCallback:(callbackWithUrlAndSpotlightIdentifier)spotlightCallback;
45+
46+
3047
@end

Branch-SDK/Branch-SDK/BNCContentDiscoveryManager.m

Lines changed: 255 additions & 33 deletions
Large diffs are not rendered by default.

Branch-SDK/Branch-SDK/Branch.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,22 @@ typedef NS_ENUM(NSUInteger, BranchPromoCodeUsageType) {
13311331
*/
13321332
- (void)createDiscoverableContentWithTitle:(NSString *)title description:(NSString *)description thumbnailUrl:(NSURL *)thumbnailUrl linkParams:(NSDictionary *)linkParams type:(NSString *)type publiclyIndexable:(BOOL)publiclyIndexable keywords:(NSSet *)keywords expirationDate:(NSDate *)expirationDate callback:(callbackWithUrl)callback;
13331333

1334+
/**
1335+
Take the current screen and make it discoverable, adding it to Apple's Core Spotlight index. Will be public if specified. You can override the type as desired, using one of the types provided in MobileCoreServices.
1336+
1337+
@param title Title for the spotlight preview item.
1338+
@param description Description for the spotlight preview item.
1339+
@param thumbnailUrl Url to an image to be used for the thumnbail in spotlight.
1340+
@param linkParams Additional params to be added to the NSUserActivity. These will also be added to the Branch link.
1341+
@param publiclyIndexable Whether or not this item should be added to Apple's public search index.
1342+
@param type The type to use for the NSUserActivity, taken from the list of constants provided in the MobileCoreServices framework.
1343+
@param keywords A set of keywords to be used in Apple's search index.
1344+
@param expirationDate ExpirationDate after which this will not appear in Apple's search index.
1345+
@param callback Callback called with the Branch url this will fallback to.
1346+
@warning These functions are only usable on iOS 9 or above. Earlier versions will simply receive the callback with an error.
1347+
*/
1348+
- (void)createDiscoverableContentWithTitle:(NSString *)title description:(NSString *)description thumbnailUrl:(NSURL *)thumbnailUrl linkParams:(NSDictionary *)linkParams type:(NSString *)type publiclyIndexable:(BOOL)publiclyIndexable keywords:(NSSet *)keywords expirationDate:(NSDate *)expirationDate spotlightCallback:(callbackWithUrlAndSpotlightIdentifier)spotlightCallback;
1349+
13341350
#pragma mark - Referral Code methods
13351351

13361352
///-------------------------

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,11 +894,14 @@ - (void)createDiscoverableContentWithTitle:(NSString *)title description:(NSStri
894894
- (void)createDiscoverableContentWithTitle:(NSString *)title description:(NSString *)description thumbnailUrl:(NSURL *)thumbnailUrl linkParams:(NSDictionary *)linkParams type:(NSString *)type publiclyIndexable:(BOOL)publiclyIndexable keywords:(NSSet *)keywords callback:(callbackWithUrl)callback {
895895
[self.contentDiscoveryManager indexContentWithTitle:title description:description publiclyIndexable:publiclyIndexable type:type thumbnailUrl:thumbnailUrl keywords:keywords userInfo:linkParams callback:callback];
896896
}
897-
898897
- (void)createDiscoverableContentWithTitle:(NSString *)title description:(NSString *)description thumbnailUrl:(NSURL *)thumbnailUrl linkParams:(NSDictionary *)linkParams type:(NSString *)type publiclyIndexable:(BOOL)publiclyIndexable keywords:(NSSet *)keywords expirationDate:(NSDate *)expirationDate callback:(callbackWithUrl)callback {
899898
[self.contentDiscoveryManager indexContentWithTitle:title description:description publiclyIndexable:publiclyIndexable type:type thumbnailUrl:thumbnailUrl keywords:keywords userInfo:linkParams expirationDate:expirationDate callback:callback];
900899
}
901900

901+
//Use this with iOS 9+ only
902+
- (void)createDiscoverableContentWithTitle:(NSString *)title description:(NSString *)description thumbnailUrl:(NSURL *)thumbnailUrl linkParams:(NSDictionary *)linkParams type:(NSString *)type publiclyIndexable:(BOOL)publiclyIndexable keywords:(NSSet *)keywords expirationDate:(NSDate *)expirationDate spotlightCallback:(callbackWithUrlAndSpotlightIdentifier)spotlightCallback {
903+
[self.contentDiscoveryManager indexContentWithTitle:title description:description publiclyIndexable:publiclyIndexable type:type thumbnailUrl:thumbnailUrl keywords:keywords userInfo:linkParams expirationDate:expirationDate callback:nil spotlightCallback:spotlightCallback];
904+
}
902905

903906
#pragma mark - Referral methods
904907

Branch-SDK/Branch-SDK/BranchUniversalObject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef NS_ENUM(NSInteger, ContentIndexMode) {
3030
@property (nonatomic) ContentIndexMode contentIndexMode;
3131
@property (nonatomic, strong) NSArray *keywords;
3232
@property (nonatomic, strong) NSDate *expirationDate;
33+
@property (nonatomic, strong) NSString *spotlightIdentifier;
3334

3435
- (instancetype)initWithCanonicalIdentifier:(NSString *)canonicalIdentifier;
3536
- (instancetype)initWithTitle:(NSString *)title;
@@ -43,6 +44,7 @@ typedef NS_ENUM(NSInteger, ContentIndexMode) {
4344
- (void)showShareSheetWithLinkProperties:(BranchLinkProperties *)linkProperties andShareText:(NSString *)shareText fromViewController:(UIViewController *)viewController andCallback:(callback)callback;
4445
- (void)listOnSpotlight;
4546
- (void)listOnSpotlightWithCallback:(callbackWithUrl)callback;
47+
- (void)listOnSpotlightWithIdentifierCallback:(callbackWithUrlAndSpotlightIdentifier)spotlightCallback;
4648

4749
// Convenience method for initSession methods that return BranchUniversalObject, but can be used safely by anyone.
4850
+ (BranchUniversalObject *)getBranchUniversalObjectFromDictionary:(NSDictionary *)dictionary;

Branch-SDK/Branch-SDK/BranchUniversalObject.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ - (void)listOnSpotlightWithCallback:(callbackWithUrl)callback {
173173
else {
174174
publiclyIndexable = YES;
175175
}
176+
176177
[[Branch getInstance] createDiscoverableContentWithTitle:self.title
177178
description:self.contentDescription
178179
thumbnailUrl:[NSURL URLWithString:self.imageUrl]
@@ -184,6 +185,28 @@ - (void)listOnSpotlightWithCallback:(callbackWithUrl)callback {
184185
callback:callback];
185186
}
186187

188+
189+
//This one uses a callback that returns the SpotlightIdentifier
190+
- (void)listOnSpotlightWithIdentifierCallback:(callbackWithUrlAndSpotlightIdentifier)spotlightCallback {
191+
BOOL publiclyIndexable;
192+
if (self.contentIndexMode == ContentIndexModePrivate) {
193+
publiclyIndexable = NO;
194+
}
195+
else {
196+
publiclyIndexable = YES;
197+
}
198+
199+
[[Branch getInstance] createDiscoverableContentWithTitle:self.title
200+
description:self.contentDescription
201+
thumbnailUrl:[NSURL URLWithString:self.imageUrl]
202+
linkParams:self.metadata.copy
203+
type:self.type
204+
publiclyIndexable:publiclyIndexable
205+
keywords:[NSSet setWithArray:self.keywords]
206+
expirationDate:self.expirationDate
207+
spotlightCallback:spotlightCallback];
208+
}
209+
187210
+ (BranchUniversalObject *)getBranchUniversalObjectFromDictionary:(NSDictionary *)dictionary {
188211
BranchUniversalObject *universalObject = [[BranchUniversalObject alloc] init];
189212

Branch-TestBed/Branch-TestBed/ViewController.m

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,26 @@ - (IBAction)cmdShareLink:(id)sender {
6666
- (IBAction)cmdRegisterView:(id)sender {
6767
[self.branchUniversalObject registerView];
6868
}
69+
6970
- (IBAction)cmdIndexSpotlight:(id)sender {
70-
[self.branchUniversalObject listOnSpotlight];
71+
[self.branchUniversalObject listOnSpotlightWithCallback:^(NSString *url, NSError *error) {
72+
if (!error) {
73+
NSLog(@"shortURL: %@", url);
74+
} else {
75+
NSLog(@"error: %@", error);
76+
}
77+
}];
78+
}
79+
80+
//example using callbackWithURLandSpotlightIdentifier
81+
- (IBAction)cmdIndexSpotlightWithIdentifier:(id)sender {
82+
[self.branchUniversalObject listOnSpotlightWithIdentifierCallback:^(NSString *url, NSString *spotlightIdentifier, NSError *error) {
83+
if (!error) {
84+
NSLog(@"shortURL: %@ spotlight ID: %@", url, spotlightIdentifier);
85+
} else {
86+
NSLog(@"error: %@", error);
87+
}
88+
}];
7189
}
7290

7391
- (IBAction)cmdRefreshRewards:(id)sender {

0 commit comments

Comments
 (0)