Skip to content

Commit

Permalink
Merge pull request #8 from hokolinks/ios_nsuseractivity
Browse files Browse the repository at this point in the history
Universal links refactor and tests pod update
  • Loading branch information
ivanbruel committed Jun 29, 2015
2 parents 32a44bd + b360b8e commit d1ee9a1
Show file tree
Hide file tree
Showing 20 changed files with 1,217 additions and 1,191 deletions.
2 changes: 1 addition & 1 deletion Hoko.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Hoko'
s.version = '2.0'
s.version = '2.0.1'
s.platform = :ios, '5.0'
s.license = 'Apache'
s.summary = 'Connect all your platforms with a single link with HOKO deep linking technology'
Expand Down
1 change: 0 additions & 1 deletion Hoko/HOKApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

NSString *const HOKAppUnknownBuild = @"Unknown Build";
NSString *const HOKAppUnknownVersion = @"Unknown Version";
NSString *const HOKAppIconKey = @"HKAppIconKey";

NSString *const HOKAppEnvironmentDebug = @"debug";
NSString *const HOKAppEnvironmentRelease = @"release";
Expand Down
14 changes: 14 additions & 0 deletions Hoko/HOKDeeplinking.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@
*/
- (BOOL)openURL:(hok_nullable NSURL *)url sourceApplication:(hok_nullable NSString *)sourceApplication annotation:(hok_nullable id)annotation NS_AVAILABLE_IOS(4_2);

/**
* continueUserActivity:restorationHandler is a mimicked method from the UIApplicationDelegate protocol
* for iOS >= 8.0. It serves many purposes, but HOKO uses it to open Smartlinks directly from the
* NSUserActivity object. This method call will only return YES if the NSUserActivity is
* NSUserActivityTypeBrowsingWeb and the webpageURL property has the hoko.link domain. This will trigger
* a link resolve on the HOKO backend, resulting on a deeplink open by the App itself.
*
* @param userActivity The NSUserActivity object from the AppDelegate call.
* @param restorationHandler The restoration handler from the AppDelegate call.
*
* @return YES in case it contains a Smartlink, NO otherwise.
*/
- (BOOL)continueUserActivity:(hok_nonnull NSUserActivity *)userActivity restorationHandler:(hok_nonnull void(^)(NSArray * __hok_nullable restorableObjects))restorationHandler NS_AVAILABLE_IOS(8_0);

/**
* openSmartlink: serves the purpose of handling the open of a Smartlink, by resolving it through
* HOKO's backend, opening the resolved deeplink and calling the mapped route's target block.
Expand Down
20 changes: 18 additions & 2 deletions Hoko/HOKDeeplinking.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ - (instancetype)initWithToken:(NSString *)token debugMode:(BOOL)debugMode
self = [super init];
if (self) {
_routing = [[HOKRouting alloc] initWithToken:token
debugMode:debugMode];
debugMode:debugMode];
_handling = [HOKHandling new];
_linkGenerator = [[HOKLinkGenerator alloc] initWithToken:token];
_deferredDeeplinking = [[HOKDeferredDeeplinking alloc] initWithToken:token];
Expand Down Expand Up @@ -97,6 +97,22 @@ - (void)openSmartlink:(NSString *)smartlink completion:(void (^)(HOKDeeplink *de
}];
}

- (BOOL)continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorableObjects))restorationHandler
{
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
NSURL *webpageURL = userActivity.webpageURL;
if (webpageURL && [webpageURL.host rangeOfString:@"hoko.link"].location != NSNotFound) {
[self openSmartlink:userActivity.webpageURL.absoluteString completion:^(HOKDeeplink *deeplink) {
if (!deeplink) {
[self handleOpenURL:nil];
}
}];
return YES;
}
}
return NO;
}

#pragma mark - Handlers
- (void)addHandler:(id<HOKHandlerProcotol>)handler
{
Expand Down Expand Up @@ -134,7 +150,7 @@ - (void)triggerDeferredDeeplinking
#pragma mark - Swizzling
+ (void)load
{
[HOKSwizzling swizzleHKDeeplinking];
[HOKSwizzling swizzleHOKDeeplinking];
}

@end
6 changes: 3 additions & 3 deletions Hoko/HOKDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ - (void)initReachabilityCallback {
self.networkReachability = SCNetworkReachabilityCreateWithName(NULL, [HOKDeviceReachabilityUrl UTF8String]);
if (self.networkReachability != NULL) {
SCNetworkReachabilityContext context = {0, (__bridge void*)self, NULL, NULL, NULL};
if (SCNetworkReachabilitySetCallback(self.networkReachability, HKDeviceNetworkReachabilityCallback, &context)) {
dispatch_queue_t queue = dispatch_queue_create("HKReachabilityQueue", DISPATCH_QUEUE_SERIAL);
if (SCNetworkReachabilitySetCallback(self.networkReachability, HOKDeviceNetworkReachabilityCallback, &context)) {
dispatch_queue_t queue = dispatch_queue_create("HOKReachabilityQueue", DISPATCH_QUEUE_SERIAL);
if (SCNetworkReachabilitySetDispatchQueue(self.networkReachability, queue)) {
reachabilityInitated = YES;
} else {
Expand All @@ -206,7 +206,7 @@ - (void)initReachabilityCallback {
}
}

static void HKDeviceNetworkReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void *info) {
static void HOKDeviceNetworkReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void *info) {
if (info != NULL && [(__bridge NSObject*)info isKindOfClass:[HOKDevice class]]) {
@autoreleasepool {
HOKDevice *device = (__bridge HOKDevice *)info;
Expand Down
2 changes: 0 additions & 2 deletions Hoko/HOKNetworkOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ typedef NS_ENUM(NSUInteger, HOKNetworkOperationType) {
HOKNetworkOperationTypePUT,
};

FOUNDATION_EXPORT NSString *const HKNetworkingOperationEndpoint;

@interface HOKNetworkOperation : NSOperation <NSCoding>

- (instancetype)initWithOperation:(HOKNetworkOperation *)operation;
Expand Down
16 changes: 8 additions & 8 deletions Hoko/HOKRouting.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ - (HOKDeeplink *)deeplinkForURL:(NSURL *)url

- (HOKDeeplink *)deeplinkForURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation route:(HOKRoute **)route
{
HOKURL *hkURL = [[HOKURL alloc]initWithURL:url];
HOKURL *hokURL = [[HOKURL alloc]initWithURL:url];
NSDictionary *routeParameters;
// Search for a match with any given route
for (HOKRoute *hokRoute in self.routes) {
if([hkURL matchesWithRoute:hokRoute routeParameters:&routeParameters]) {
HOKDeeplink *deeplink = [HOKDeeplink deeplinkWithURLScheme:hkURL.scheme
if([hokURL matchesWithRoute:hokRoute routeParameters:&routeParameters]) {
HOKDeeplink *deeplink = [HOKDeeplink deeplinkWithURLScheme:hokURL.scheme
route:hokRoute.route
routeParameters:routeParameters
queryParameters:hkURL.queryParameters
queryParameters:hokURL.queryParameters
sourceApplication:sourceApplication
deeplinkURL:url.absoluteString];
if (route) {
Expand All @@ -98,10 +98,10 @@ - (HOKDeeplink *)deeplinkForURL:(NSURL *)url sourceApplication:(NSString *)sourc
}

// Default Route
HOKDeeplink *deeplink = [HOKDeeplink deeplinkWithURLScheme:hkURL.scheme
HOKDeeplink *deeplink = [HOKDeeplink deeplinkWithURLScheme:hokURL.scheme
route:nil
routeParameters:nil
queryParameters:hkURL.queryParameters
queryParameters:hokURL.queryParameters
sourceApplication:sourceApplication
deeplinkURL:url.absoluteString];
if (self.defaultRoute) {
Expand All @@ -119,11 +119,11 @@ - (BOOL)canOpenURL:(NSURL *)url
}

// Look for a matching route for this URL
HOKURL *hkURL = [[HOKURL alloc] initWithURL:url];
HOKURL *hokURL = [[HOKURL alloc] initWithURL:url];

// Search for a match with any given route
for (HOKRoute *route in self.routes) {
if([hkURL matchesWithRoute:route routeParameters:nil]) {
if([hokURL matchesWithRoute:route routeParameters:nil]) {
return YES;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Hoko/HOKSwizzling.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#import <Foundation/Foundation.h>

/**
* HKSwizzling is a helper class to swizzle some particular functions out of the AppDelegate.
* HOKSwizzling is a helper class to swizzle some particular functions out of the AppDelegate.
* Making it easier to integrate the Hoko Framework.
*/
@interface HOKSwizzling : NSObject

+ (void)swizzleHKDeeplinking;
+ (void)swizzleHOKDeeplinking;

@end
22 changes: 8 additions & 14 deletions Hoko/HOKSwizzling.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ + (IMP)swizzleClassWithClassname:(NSString *)classname
}
}

#pragma mark - HKDeeplinking Swizzles
+ (void)swizzleHKDeeplinking
#pragma mark - HOKDeeplinking Swizzles
+ (void)swizzleHOKDeeplinking
{
NSString *appDelegateClassName = [self appDelegateClassName];
if (appDelegateClassName) {
Expand All @@ -128,7 +128,9 @@ + (void)swizzleHKDeeplinking
+ (void)swizzleOpenURLWithAppDelegateClassName:(NSString *)appDelegateClassName
{
__block IMP implementation = [HOKSwizzling swizzleClassWithClassname:appDelegateClassName originalSelector:@selector(application:openURL:sourceApplication:annotation:) block:^BOOL(id blockSelf, UIApplication *application, NSURL *url, NSString *sourceApplication, id annotation){

BOOL result = [[Hoko deeplinking] openURL:url sourceApplication:sourceApplication annotation:annotation];

if (!result && implementation) {
BOOL (*func)() = (void *)implementation;
result = func(blockSelf, @selector(application:openURL:sourceApplication:annotation:), application, url, sourceApplication, annotation);
Expand All @@ -140,7 +142,9 @@ + (void)swizzleOpenURLWithAppDelegateClassName:(NSString *)appDelegateClassName
+ (void)swizzleLegacyOpenURLWithAppDelegateClassName:(NSString *)appDelegateClassName
{
__block IMP implementation = [HOKSwizzling swizzleClassWithClassname:appDelegateClassName originalSelector:@selector(application:handleOpenURL:) block:^BOOL(id blockSelf, UIApplication *application, NSURL *url){

BOOL result = [[Hoko deeplinking] handleOpenURL:url];

if (!result && implementation) {
BOOL (*func)() = (void *)implementation;
result = func(blockSelf, @selector(application:handleOpenURL:), application, url);
Expand All @@ -153,19 +157,9 @@ + (void)swizzleLegacyOpenURLWithAppDelegateClassName:(NSString *)appDelegateClas
+ (void)swizzleContinueUserActivityWithAppDelegateClassName:(NSString *)appDelegateClassName {
__block IMP implementation = [HOKSwizzling swizzleClassWithClassname:appDelegateClassName originalSelector:@selector(application:continueUserActivity:restorationHandler:) block:^BOOL(id blockSelf, UIApplication *application, NSUserActivity *userActivity, id restorationHandler){

if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
NSURL *webpageURL = userActivity.webpageURL;
if (webpageURL && [webpageURL.host rangeOfString:@"hoko.link"].location != NSNotFound) {
[[Hoko deeplinking] openSmartlink:userActivity.webpageURL.absoluteString completion:^(HOKDeeplink *deeplink) {
if (!deeplink) {
[[Hoko deeplinking] handleOpenURL:nil];
}
}];
return YES;
}
}
BOOL result = [[Hoko deeplinking] continueUserActivity:userActivity restorationHandler:restorationHandler];

if (implementation) {
if (!result && implementation) {
BOOL (*func)() = (void *)implementation;
return func(blockSelf, @selector(application:continueUserActivity:restorationHandler:), application, userActivity, restorationHandler);
}
Expand Down
4 changes: 2 additions & 2 deletions Hoko/Hoko.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
+ (void)setupWithToken:(hok_nonnull NSString *)token;

/**
* The HKDeeplinking module provides all the necessary APIs to map, handle and generate deeplinks.
* The HOKDeeplinking module provides all the necessary APIs to map, handle and generate deeplinks.
* Different APIs as provided in order to be as versatile as your application requires them to be.
*
* @return A reference to the HKDeeplinking instance.
* @return A reference to the HOKDeeplinking instance.
*/
+ (hok_nonnull HOKDeeplinking *)deeplinking;

Expand Down
2 changes: 1 addition & 1 deletion Hoko/Hoko.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#import "HOKDeeplinking+Private.h"
#import "HOKNetworkOperationQueue.h"

NSString *const HokoVersion = @"2.0";
NSString *const HokoVersion = @"2.0.1";

@interface Hoko ()

Expand Down
4 changes: 2 additions & 2 deletions Tests/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- Expecta (0.3.2)
- Hoko (2.0)
- Hoko (2.0.1)
- OCMock (3.1.2)
- OHHTTPStubs (3.1.12):
- OHHTTPStubs/Core (= 3.1.12)
Expand All @@ -18,7 +18,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Expecta: 8c507baf13211207b1e9d0a741480600e6b4ed15
Hoko: f7c347d34cba3bf11e6065b3e70e745b1a517af6
Hoko: c2996b879027d6e463401f03639b17818e69ed99
OCMock: a10ea9f0a6e921651f96f78b6faee95ebc813b92
OHHTTPStubs: 8cf0cfe6f34f13fc88fdf5b2a1b2c2536e8c0261

Expand Down
7 changes: 4 additions & 3 deletions Tests/Pods/Local Podspecs/Hoko.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Tests/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d1ee9a1

Please sign in to comment.