diff --git a/DeepLinkKit.podspec b/DeepLinkKit.podspec index 87cb6f3..204a8a6 100644 --- a/DeepLinkKit.podspec +++ b/DeepLinkKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "DeepLinkKit" - s.version = "1.0.0" + s.version = "1.1.0" s.summary = "A splendid route-matching, block-based way to handle your deep links." s.description = <<-DESC DeepLink Kit is a splendid route-handling block-based way to handle deep links. Use DeepLink Kit to parse incoming URLs, extract parameters from the host, url etc.. and even build outgoing deeplinks. All with a simple, block-based interface. diff --git a/DeepLinkKit/Router/DPLDeepLinkRouter.h b/DeepLinkKit/Router/DPLDeepLinkRouter.h index 434fed4..30080c8 100644 --- a/DeepLinkKit/Router/DPLDeepLinkRouter.h +++ b/DeepLinkKit/Router/DPLDeepLinkRouter.h @@ -77,7 +77,7 @@ typedef void(^DPLRouteCompletionBlock)(BOOL handled, NSError *error); /** Attempts to handle an incoming URL. - @param url The incoming URL from `application:didFinishLaunchingWithOptions:' or `application:openURL:sourceApplication:annotation:' + @param url The incoming URL from `application:openURL:sourceApplication:annotation:' @param completionHandler A block executed after the deep link has been handled. @return YES if the incoming URL is handled, otherwise NO. @@ -86,6 +86,16 @@ typedef void(^DPLRouteCompletionBlock)(BOOL handled, NSError *error); - (BOOL)handleURL:(NSURL *)url withCompletion:(DPLRouteCompletionBlock)completionHandler; +/** + Attempts to handle an incoming user activity. + @param userActivity The incoming user activity from `application:continueUserActivity:restorationHandler:' + @param completionHandler A block executed after the user activity has been handled. + @return YES if the incoming user activity is handled, otherwise NO. + + @see DPLRouteCompletionBlock + */ +- (BOOL)handleUserActivity:(NSUserActivity *)userActivity withCompletion:(DPLRouteCompletionBlock)completionHandler; + ///-------------------- /// @name Configuration diff --git a/DeepLinkKit/Router/DPLDeepLinkRouter.m b/DeepLinkKit/Router/DPLDeepLinkRouter.m index a81e2c8..d07d148 100644 --- a/DeepLinkKit/Router/DPLDeepLinkRouter.m +++ b/DeepLinkKit/Router/DPLDeepLinkRouter.m @@ -139,6 +139,15 @@ - (BOOL)handleURL:(NSURL *)url withCompletion:(DPLRouteCompletionBlock)completio } +- (BOOL)handleUserActivity:(NSUserActivity *)userActivity withCompletion:(DPLRouteCompletionBlock)completionHandler { + if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) { + return [self handleURL:userActivity.webpageURL withCompletion:completionHandler]; + } + + return NO; +} + + - (BOOL)handleRoute:(NSString *)route withDeepLink:(DPLDeepLink *)deepLink error:(NSError *__autoreleasing *)error { id handler = self[route]; diff --git a/Podfile.lock b/Podfile.lock index d0e10b6..ad11872 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,11 +1,11 @@ PODS: - - DeepLinkKit (1.0.0) + - DeepLinkKit (1.1.0) - Expecta (1.0.0) - - KIF (3.2.2): - - KIF/XCTest (= 3.2.2) - - KIF/XCTest (3.2.2) + - KIF (3.2.3): + - KIF/XCTest (= 3.2.3) + - KIF/XCTest (3.2.3) - OCMock (3.1.2) - - Specta (1.0.0) + - Specta (1.0.2) DEPENDENCIES: - DeepLinkKit (from `.`) @@ -19,10 +19,10 @@ EXTERNAL SOURCES: :path: . SPEC CHECKSUMS: - DeepLinkKit: 5d7deb38ad7bc7daf8670eb8878cd8b806ef9689 + DeepLinkKit: 3979713c8a0b6bd3259fb7917e572acf56645a35 Expecta: 32604574add2c46a36f8d2f716b6c5736eb75024 - KIF: b0bd762b0c7890b04920cf618021d6d4fd5127bd + KIF: a94bffe9c97e449e44f8fa481c53243d21309e1e OCMock: a10ea9f0a6e921651f96f78b6faee95ebc813b92 - Specta: 96fe05fe5c7348b5223f85e862904f6e832abb14 + Specta: 9cec98310dca411f7c7ffd6943552b501622abfe COCOAPODS: 0.37.1 diff --git a/README.md b/README.md index 3c929c2..8fe7927 100644 --- a/README.md +++ b/README.md @@ -80,11 +80,24 @@ self.router[@"/log/:message"] = ^(DPLDeepLink *link) { sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { - [self.router handleURL:url withCompletion:NULL]; + return [self.router handleURL:url withCompletion:NULL]; +} +``` +**6. Passing `NSUserActivity` objects to the router** (optional) +
+_**Note:** If your application supports [Apple's new universal links](https://developer.apple.com/library/prerelease/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS9.html#//apple_ref/doc/uid/TP40016198-DontLinkElementID_2), implement the following in your app delegate:_ - return YES; +```objc +- (BOOL)application:(UIApplication *)application + continueUserActivity:(NSUserActivity *)userActivity + restorationHandler:(void (^)(NSArray *))restorationHandler { + + return [self.router handleUserActivity:userActivity withCompletion:NULL]; } ``` + + + Learn more about the DeepLinkKit by reading our [Integration Guide](http://www.usebutton.com/sdk/deep-links/integration-guide). ## Route Registration Examples diff --git a/SampleApps/ReceiverDemo/DPLReceiverAppDelegate.m b/SampleApps/ReceiverDemo/DPLReceiverAppDelegate.m index 168b1c4..685a8e4 100644 --- a/SampleApps/ReceiverDemo/DPLReceiverAppDelegate.m +++ b/SampleApps/ReceiverDemo/DPLReceiverAppDelegate.m @@ -47,4 +47,12 @@ - (BOOL)application:(UIApplication *)application return [self.router handleURL:url withCompletion:NULL]; } + +- (BOOL)application:(UIApplication *)application + continueUserActivity:(NSUserActivity *)userActivity + restorationHandler:(void (^)(NSArray *))restorationHandler { + + return [self.router handleUserActivity:userActivity withCompletion:NULL]; +} + @end diff --git a/Tests/Router/DPLDeepLinkRouterSpec.m b/Tests/Router/DPLDeepLinkRouterSpec.m index cdc179f..a0ef2ae 100644 --- a/Tests/Router/DPLDeepLinkRouterSpec.m +++ b/Tests/Router/DPLDeepLinkRouterSpec.m @@ -173,6 +173,34 @@ expect(isHandled).to.beFalsy(); }); }); + + it(@"handles an incoming user activity that is a web browsing activity type", ^{ + waitUntil(^(DoneCallback done) { + + NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:NSUserActivityTypeBrowsingWeb]; + activity.webpageURL = [NSURL URLWithString:@"https://dlc.com/say/hello"];; + + router[@"/say/:word"] = ^{}; + + BOOL isHandled = [router handleUserActivity:activity withCompletion:^(BOOL handled, NSError *error) { + expect(handled).to.beTruthy(); + expect(error).to.beNil(); + done(); + }]; + expect(isHandled).to.beTruthy(); + }); + }); + + it(@"does NOT handle an incoming user activity that is a NOT web browsing activity type", ^{ + + NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"derpType"]; + activity.webpageURL = [NSURL URLWithString:@"https://dlc.com/say/hello"];; + + router[@"/say/:word"] = ^{}; + + BOOL isHandled = [router handleUserActivity:activity withCompletion:NULL]; + expect(isHandled).to.beFalsy(); + }); }); SpecEnd