Skip to content

Commit

Permalink
Merge pull request #210 from BranchMetrics/update-ios-lib
Browse files Browse the repository at this point in the history
chore: update iOS library
  • Loading branch information
aaustin authored Sep 15, 2016
2 parents 63e5ac6 + 7fae095 commit 775333e
Show file tree
Hide file tree
Showing 44 changed files with 1,181 additions and 280 deletions.
Binary file removed src/android/dependencies/Branch-2.0.2.jar
Binary file not shown.
Binary file added src/android/dependencies/Branch-2.4.0.jar
Binary file not shown.
12 changes: 6 additions & 6 deletions src/ios/dependencies/Branch-SDK/BNCCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

@class BranchUniversalObject, BranchLinkProperties;

typedef void (^callbackWithParams) (NSDictionary *params, NSError *error);
typedef void (^callbackWithUrl) (NSString *url, NSError *error);
typedef void (^callbackWithStatus) (BOOL changed, NSError *error);
typedef void (^callbackWithList) (NSArray *list, NSError *error);
typedef void (^callbackWithUrlAndSpotlightIdentifier) (NSString *url, NSString *spotlightIdentifier, NSError *error);
typedef void (^callbackWithBranchUniversalObject) (BranchUniversalObject *universalObject, BranchLinkProperties *linkProperties, NSError *error);
typedef void (^callbackWithParams) (NSDictionary * _Nonnull params, NSError * _Nullable error);
typedef void (^callbackWithUrl) (NSString * _Nonnull url, NSError * _Nullable error);
typedef void (^callbackWithStatus) (BOOL changed, NSError * _Nullable error);
typedef void (^callbackWithList) (NSArray * _Nullable list, NSError * _Nullable error);
typedef void (^callbackWithUrlAndSpotlightIdentifier) (NSString * _Nullable url, NSString * _Nullable spotlightIdentifier, NSError * _Nullable error);
typedef void (^callbackWithBranchUniversalObject) (BranchUniversalObject * _Nonnull universalObject, BranchLinkProperties * _Nonnull linkProperties, NSError * _Nullable error);

#endif /* BNCCallbacks_h */
2 changes: 1 addition & 1 deletion src/ios/dependencies/Branch-SDK/BNCConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef Branch_SDK_Config_h
#define Branch_SDK_Config_h

#define SDK_VERSION @"0.12.5"
#define SDK_VERSION @"0.12.9"

#define BNC_PROD_ENV
//#define BNC_STAGE_ENV
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "Branch.h"

@interface BNCContentDiscoveryManager : NSObject
@interface BNCContentDiscoveryManager : NSObject<NSUserActivityDelegate>

- (NSString *)spotlightIdentifierFromActivity:(NSUserActivity *)userActivity;
- (NSString *)standardSpotlightIdentifierFromActivity:(NSUserActivity *)userActivity;
Expand Down
160 changes: 85 additions & 75 deletions src/ios/dependencies/Branch-SDK/BNCContentDiscoveryManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2015 Branch Metrics. All rights reserved.
//

#import "BNCPreferenceHelper.h"
#import "BNCContentDiscoveryManager.h"
#import "BNCSystemObserver.h"
#import "BNCError.h"
Expand All @@ -29,7 +30,7 @@

@interface BNCContentDiscoveryManager ()

@property (strong, nonatomic) NSUserActivity *currentUserActivity;
@property (strong, nonatomic) NSMutableDictionary *userInfo;

@end

Expand All @@ -39,18 +40,14 @@ @implementation BNCContentDiscoveryManager

- (NSString *)spotlightIdentifierFromActivity:(NSUserActivity *)userActivity {
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
if ([userActivity.activityType hasPrefix:BRANCH_SPOTLIGHT_PREFIX]) {
return userActivity.activityType;
}
// If it has our prefix, then the link identifier is just the last piece of the identifier.
NSString *activityIdentifier = userActivity.userInfo[CSSearchableItemActivityIdentifier];
BOOL isBranchIdentifier = [activityIdentifier hasPrefix:BRANCH_SPOTLIGHT_PREFIX];

// CoreSpotlight version. Matched if it has our prefix, then the link identifier is just the last piece of the identifier.
if ([userActivity.activityType isEqualToString:CSSearchableItemActionType]) {
NSString *activityIdentifier = userActivity.userInfo[CSSearchableItemActivityIdentifier];
BOOL isBranchIdentifier = [activityIdentifier hasPrefix:BRANCH_SPOTLIGHT_PREFIX];

if (isBranchIdentifier) {
return activityIdentifier;
}
// Checking for CSSearchableItemActionType in the activity for legacy spotlight indexing (pre 0.12.7)
// Now we index NSUserActivies with type set to io.branch. + bundleId for better SEO
if ([userActivity.activityType isEqualToString:CSSearchableItemActionType] || isBranchIdentifier) {
return activityIdentifier;
}
#endif

Expand All @@ -59,16 +56,14 @@ - (NSString *)spotlightIdentifierFromActivity:(NSUserActivity *)userActivity {

- (NSString *)standardSpotlightIdentifierFromActivity:(NSUserActivity *)userActivity {
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
// CoreSpotlight version. Matched if it has our prefix, then the link identifier is just the last piece of the identifier.
if ([userActivity.activityType isEqualToString:CSSearchableItemActionType] && userActivity.userInfo[CSSearchableItemActivityIdentifier]) {
if (userActivity.userInfo[CSSearchableItemActivityIdentifier]) {
return userActivity.userInfo[CSSearchableItemActivityIdentifier];
}
#endif

return nil;
}


#pragma mark - Content Indexing

- (void)indexContentWithTitle:(NSString *)title
Expand Down Expand Up @@ -309,7 +304,7 @@ - (void)indexContentWithTitle:(NSString *)title
if ([BNCSystemObserver getOSVersion].integerValue < 9) {
NSError *error = [NSError errorWithDomain:BNCErrorDomain code:BNCVersionError userInfo:@{ NSLocalizedDescriptionKey: @"Cannot use CoreSpotlight indexing service prior to iOS 9" }];
if (callback) {
callback(nil, error);
callback([BNCPreferenceHelper preferenceHelper].userUrl, error);
}
else if (spotlightCallback) {
spotlightCallback(nil, nil, error);
Expand All @@ -319,7 +314,7 @@ - (void)indexContentWithTitle:(NSString *)title
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
NSError *error = [NSError errorWithDomain:BNCErrorDomain code:BNCBadRequestError userInfo:@{ NSLocalizedDescriptionKey: @"CoreSpotlight is not available because the base SDK for this project is less than 9.0" }];
if (callback) {
callback(nil, error);
callback([BNCPreferenceHelper preferenceHelper].userUrl, error);
}
else if (spotlightCallback) {
spotlightCallback(nil, nil, error);
Expand All @@ -334,7 +329,7 @@ - (void)indexContentWithTitle:(NSString *)title
if (!isIndexingAvailable) {
NSError *error = [NSError errorWithDomain:BNCErrorDomain code:BNCVersionError userInfo:@{ NSLocalizedDescriptionKey: @"Cannot use CoreSpotlight indexing service on this device/OS" }];
if (callback) {
callback(nil, error);
callback([BNCPreferenceHelper preferenceHelper].userUrl, error);
}
else if (spotlightCallback) {
spotlightCallback(nil, nil, error);
Expand All @@ -345,7 +340,7 @@ - (void)indexContentWithTitle:(NSString *)title
if (!title) {
NSError *error = [NSError errorWithDomain:BNCErrorDomain code:BNCBadRequestError userInfo:@{ NSLocalizedDescriptionKey: @"Spotlight Indexing requires a title" }];
if (callback) {
callback(nil, error);
callback([BNCPreferenceHelper preferenceHelper].userUrl, error);
}
else if (spotlightCallback) {
spotlightCallback(nil, nil, error);
Expand Down Expand Up @@ -397,7 +392,7 @@ - (void)indexContentWithTitle:(NSString *)title
[[Branch getInstance] getSpotlightUrlWithParams:spotlightLinkData callback:^(NSDictionary *data, NSError *urlError) {
if (urlError) {
if (callback) {
callback(nil, urlError);
callback([BNCPreferenceHelper preferenceHelper].userUrl, urlError);
}
else if (spotlightCallback) {
spotlightCallback(nil, nil, urlError);
Expand Down Expand Up @@ -430,8 +425,6 @@ - (void)indexContentWithUrl:(NSString *)url spotlightIdentifier:(NSString *)spot
attributes = ((id (*)(id, SEL, NSString *))[attributes methodForSelector:initAttributesSelector])(attributes, initAttributesSelector, type);
SEL setIdentifierSelector = NSSelectorFromString(@"setIdentifier:");
((void (*)(id, SEL, NSString *))[attributes methodForSelector:setIdentifierSelector])(attributes, setIdentifierSelector, spotlightIdentifier);
SEL setRelatedUniqueIdentifierSelector = NSSelectorFromString(@"setRelatedUniqueIdentifier:");
((void (*)(id, SEL, NSString *))[attributes methodForSelector:setRelatedUniqueIdentifierSelector])(attributes, setRelatedUniqueIdentifierSelector, spotlightIdentifier);
SEL setTitleSelector = NSSelectorFromString(@"setTitle:");
((void (*)(id, SEL, NSString *))[attributes methodForSelector:setTitleSelector])(attributes, setTitleSelector, title);
SEL setContentDescriptionSelector = NSSelectorFromString(@"setContentDescription:");
Expand All @@ -440,65 +433,82 @@ - (void)indexContentWithUrl:(NSString *)url spotlightIdentifier:(NSString *)spot
((void (*)(id, SEL, NSURL *))[attributes methodForSelector:setThumbnailURLSelector])(attributes, setThumbnailURLSelector, thumbnailUrl);
SEL setThumbnailDataSelector = NSSelectorFromString(@"setThumbnailData:");
((void (*)(id, SEL, NSData *))[attributes methodForSelector:setThumbnailDataSelector])(attributes, setThumbnailDataSelector, thumbnailData);
// NSUserActivity.CSSearchableItemAttributeSet.contentURL
SEL setContentURLSelector = NSSelectorFromString(@"setContentURL:");
((void (*)(id, SEL, NSURL *))[attributes methodForSelector:setContentURLSelector])(attributes, setContentURLSelector, [NSURL URLWithString:url]);

// Index via the NSUserActivity strategy
// Currently (iOS 9 Beta 4) we need a strong reference to this, or it isn't indexed
self.currentUserActivity = [[NSUserActivity alloc] initWithActivityType:spotlightIdentifier];
self.currentUserActivity.title = title;
self.currentUserActivity.webpageURL = [NSURL URLWithString:url]; // This should allow indexed content to fall back to the web if user doesn't have the app installed. Unable to test as of iOS 9 Beta 4
self.currentUserActivity.eligibleForSearch = YES;
self.currentUserActivity.eligibleForPublicIndexing = publiclyIndexable;
SEL setContentAttributeSetSelector = NSSelectorFromString(@"setContentAttributeSet:");
((void (*)(id, SEL, id))[self.currentUserActivity methodForSelector:setContentAttributeSetSelector])(self.currentUserActivity, setContentAttributeSetSelector, attributes);
self.currentUserActivity.userInfo = userInfo; // As of iOS 9 Beta 4, this gets lost and never makes it through to application:continueActivity:restorationHandler:
self.currentUserActivity.requiredUserInfoKeys = [NSSet setWithArray:userInfo.allKeys]; // This, however, seems to force the userInfo to come through.
self.currentUserActivity.keywords = keywords;
[self.currentUserActivity becomeCurrent];
NSDictionary *userActivityIndexingParams = @{@"title": title,
@"url": url,
@"spotlightId": spotlightIdentifier,
@"userInfo": [userInfo mutableCopy],
@"keywords": keywords,
@"publiclyIndexable": [NSNumber numberWithBool:publiclyIndexable],
@"attributeSet": attributes
};
[self indexUsingNSUserActivity:userActivityIndexingParams];

// Index via the CoreSpotlight strategy
//get the CSSearchableItem Class object
id CSSearchableItemClass = NSClassFromString(@"CSSearchableItem");
//alloc an empty instance
id searchableItem = [CSSearchableItemClass alloc];
//create-by-name a selector fot the init method we want
SEL initItemSelector = NSSelectorFromString(@"initWithUniqueIdentifier:domainIdentifier:attributeSet:");
//call the selector on the searchableItem with appropriate arguments
searchableItem = ((id (*)(id, SEL, NSString *, NSString *, id))[searchableItem methodForSelector:initItemSelector])(searchableItem, initItemSelector, spotlightIdentifier, BRANCH_SPOTLIGHT_PREFIX, attributes);

//create an assignment method to set the expiration date on the searchableItem
SEL expirationSelector = NSSelectorFromString(@"setExpirationDate:");
//now invoke it on the searchableItem, providing the expirationdate
((void (*)(id, SEL, NSDate *))[searchableItem methodForSelector:expirationSelector])(searchableItem, expirationSelector, expirationDate);


Class CSSearchableIndexClass = NSClassFromString(@"CSSearchableIndex");
SEL defaultSearchableIndexSelector = NSSelectorFromString(@"defaultSearchableIndex");
id defaultSearchableIndex = ((id (*)(id, SEL))[CSSearchableIndexClass methodForSelector:defaultSearchableIndexSelector])(CSSearchableIndexClass, defaultSearchableIndexSelector);
SEL indexSearchableItemsSelector = NSSelectorFromString(@"indexSearchableItems:completionHandler:");
void (^__nullable completionBlock)(NSError *indexError) = ^void(NSError *__nullable indexError) {
if (callback || spotlightCallback) {
if (indexError) {
if (callback) {
callback(nil, indexError);
}
else if (spotlightCallback) {
spotlightCallback(nil, nil, indexError);
}
}
else {
if (callback) {
callback(url, nil);
}
else if (spotlightCallback) {
spotlightCallback(url, spotlightIdentifier, nil);
}
}
// Not handling error scenarios because they are already handled upstream by the caller
if (url) {
if (callback) {
callback(url, nil);
} else if (spotlightCallback) {
spotlightCallback(url, spotlightIdentifier, nil);
}
};
((void (*)(id, SEL, NSArray *, void (^ __nullable)(NSError * __nullable error)))[defaultSearchableIndex methodForSelector:indexSearchableItemsSelector])(defaultSearchableIndex, indexSearchableItemsSelector, @[searchableItem], completionBlock);
}
#endif
}

#pragma mark Delegate Methods

- (void)userActivityWillSave:(NSUserActivity *)userActivity {
[userActivity addUserInfoEntriesFromDictionary:self.userInfo];
}

#pragma mark Helper Methods

- (UIViewController *)getActiveViewController {
Class UIApplicationClass = NSClassFromString(@"UIApplication");
UIViewController *rootViewController = [UIApplicationClass sharedApplication].keyWindow.rootViewController;
return [self getActiveViewController:rootViewController];
}

- (UIViewController *)getActiveViewController:(UIViewController *)rootViewController {
UIViewController *activeController;
if ([rootViewController isKindOfClass:[UINavigationController class]]) {
activeController = ((UINavigationController *)rootViewController).topViewController;
} else if ([rootViewController isKindOfClass:[UITabBarController class]]) {
activeController = ((UITabBarController *)rootViewController).selectedViewController;
} else {
activeController = rootViewController;
}
return activeController;
}

- (void)indexUsingNSUserActivity:(NSDictionary *)params {
self.userInfo = params[@"userInfo"];
self.userInfo[CSSearchableItemActivityIdentifier] = params[@"spotlightId"];

UIViewController *activeViewController = [self getActiveViewController];

if (!activeViewController) {
// if no view controller, don't index. Current use case: iMessage extensions
return;
}
NSString *uniqueIdentifier = [NSString stringWithFormat:@"io.branch.%@", [[NSBundle mainBundle] bundleIdentifier]];
// Can't create any weak references here to the userActivity, otherwise it will not index.
activeViewController.userActivity = [[NSUserActivity alloc] initWithActivityType:uniqueIdentifier];
activeViewController.userActivity.delegate = self;
activeViewController.userActivity.title = params[@"title"];
activeViewController.userActivity.webpageURL = [NSURL URLWithString:params[@"url"]];
activeViewController.userActivity.eligibleForSearch = YES;
activeViewController.userActivity.eligibleForPublicIndexing = [params[@"publiclyIndexable"] boolValue];
activeViewController.userActivity.userInfo = self.userInfo; // This alone doesn't pass userInfo through
activeViewController.userActivity.requiredUserInfoKeys = [NSSet setWithArray:self.userInfo.allKeys]; // This along with the delegate method userActivityWillSave, however, seem to force the userInfo to come through.
activeViewController.userActivity.keywords = params[@"keywords"];
SEL setContentAttributeSetSelector = NSSelectorFromString(@"setContentAttributeSet:");
((void (*)(id, SEL, id))[activeViewController.userActivity methodForSelector:setContentAttributeSetSelector])(activeViewController.userActivity, setContentAttributeSetSelector, params[@"attributeSet"]);

[activeViewController.userActivity becomeCurrent];
}

@end
4 changes: 2 additions & 2 deletions src/ios/dependencies/Branch-SDK/BNCEncodingUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ + (NSString *)encodeDictionaryToJsonString:(NSDictionary *)dictionary {
value = [BNCEncodingUtils encodeArrayToJsonString:obj];
string = NO;
}
else if ([obj isKindOfClass:[NSDictionary class]]) {
else if ([obj isKindOfClass:[NSDictionary class]] || [obj isKindOfClass:[NSMutableDictionary class]]) {
value = [BNCEncodingUtils encodeDictionaryToJsonString:obj];
string = NO;
}
Expand Down Expand Up @@ -297,7 +297,7 @@ + (NSString *)encodeArrayToJsonString:(NSArray *)array {
value = [BNCEncodingUtils encodeArrayToJsonString:obj];
string = NO;
}
else if ([obj isKindOfClass:[NSDictionary class]]) {
else if ([obj isKindOfClass:[NSDictionary class]] || [obj isKindOfClass:[NSMutableDictionary class]]) {
value = [BNCEncodingUtils encodeDictionaryToJsonString:obj];
string = NO;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ios/dependencies/Branch-SDK/BNCFabricAnswers.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "BNCFabricAnswers.h"
#import "BNCPreferenceHelper.h"
#import "Answers.h"
#import "../Fabric/Answers.h"

@implementation BNCFabricAnswers

Expand Down
1 change: 1 addition & 0 deletions src/ios/dependencies/Branch-SDK/BNCLinkData.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef NS_ENUM(NSUInteger, BranchLinkType) {
- (void)setupChannel:(NSString *)channel;
- (void)setupFeature:(NSString *)feature;
- (void)setupStage:(NSString *)stage;
- (void)setupCampaign:(NSString *)campaign;
- (void)setupParams:(NSDictionary *)params;
- (void)setupMatchDuration:(NSUInteger)duration;
- (void)setupIgnoreUAString:(NSString *)ignoreUAString;
Expand Down
Loading

0 comments on commit 775333e

Please sign in to comment.