Skip to content

Commit 27353a2

Browse files
committed
Merge pull request #59 from usebutton/feature/universal_link_support
Adds support for universal links
2 parents f2cebb1 + 3331b4d commit 27353a2

File tree

7 files changed

+80
-12
lines changed

7 files changed

+80
-12
lines changed

DeepLinkKit.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "DeepLinkKit"
3-
s.version = "1.0.0"
3+
s.version = "1.1.0"
44
s.summary = "A splendid route-matching, block-based way to handle your deep links."
55
s.description = <<-DESC
66
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.

DeepLinkKit/Router/DPLDeepLinkRouter.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ typedef void(^DPLRouteCompletionBlock)(BOOL handled, NSError *error);
7777

7878
/**
7979
Attempts to handle an incoming URL.
80-
@param url The incoming URL from `application:didFinishLaunchingWithOptions:' or `application:openURL:sourceApplication:annotation:'
80+
@param url The incoming URL from `application:openURL:sourceApplication:annotation:'
8181
@param completionHandler A block executed after the deep link has been handled.
8282
@return YES if the incoming URL is handled, otherwise NO.
8383
@@ -86,6 +86,16 @@ typedef void(^DPLRouteCompletionBlock)(BOOL handled, NSError *error);
8686
- (BOOL)handleURL:(NSURL *)url withCompletion:(DPLRouteCompletionBlock)completionHandler;
8787

8888

89+
/**
90+
Attempts to handle an incoming user activity.
91+
@param userActivity The incoming user activity from `application:continueUserActivity:restorationHandler:'
92+
@param completionHandler A block executed after the user activity has been handled.
93+
@return YES if the incoming user activity is handled, otherwise NO.
94+
95+
@see DPLRouteCompletionBlock
96+
*/
97+
- (BOOL)handleUserActivity:(NSUserActivity *)userActivity withCompletion:(DPLRouteCompletionBlock)completionHandler;
98+
8999

90100
///--------------------
91101
/// @name Configuration

DeepLinkKit/Router/DPLDeepLinkRouter.m

+9
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ - (BOOL)handleURL:(NSURL *)url withCompletion:(DPLRouteCompletionBlock)completio
139139
}
140140

141141

142+
- (BOOL)handleUserActivity:(NSUserActivity *)userActivity withCompletion:(DPLRouteCompletionBlock)completionHandler {
143+
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
144+
return [self handleURL:userActivity.webpageURL withCompletion:completionHandler];
145+
}
146+
147+
return NO;
148+
}
149+
150+
142151
- (BOOL)handleRoute:(NSString *)route withDeepLink:(DPLDeepLink *)deepLink error:(NSError *__autoreleasing *)error {
143152
id handler = self[route];
144153

Podfile.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
PODS:
2-
- DeepLinkKit (1.0.0)
2+
- DeepLinkKit (1.1.0)
33
- Expecta (1.0.0)
4-
- KIF (3.2.2):
5-
- KIF/XCTest (= 3.2.2)
6-
- KIF/XCTest (3.2.2)
4+
- KIF (3.2.3):
5+
- KIF/XCTest (= 3.2.3)
6+
- KIF/XCTest (3.2.3)
77
- OCMock (3.1.2)
8-
- Specta (1.0.0)
8+
- Specta (1.0.2)
99

1010
DEPENDENCIES:
1111
- DeepLinkKit (from `.`)
@@ -19,10 +19,10 @@ EXTERNAL SOURCES:
1919
:path: .
2020

2121
SPEC CHECKSUMS:
22-
DeepLinkKit: 5d7deb38ad7bc7daf8670eb8878cd8b806ef9689
22+
DeepLinkKit: 3979713c8a0b6bd3259fb7917e572acf56645a35
2323
Expecta: 32604574add2c46a36f8d2f716b6c5736eb75024
24-
KIF: b0bd762b0c7890b04920cf618021d6d4fd5127bd
24+
KIF: a94bffe9c97e449e44f8fa481c53243d21309e1e
2525
OCMock: a10ea9f0a6e921651f96f78b6faee95ebc813b92
26-
Specta: 96fe05fe5c7348b5223f85e862904f6e832abb14
26+
Specta: 9cec98310dca411f7c7ffd6943552b501622abfe
2727

2828
COCOAPODS: 0.37.1

README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,24 @@ self.router[@"/log/:message"] = ^(DPLDeepLink *link) {
8080
sourceApplication:(NSString *)sourceApplication
8181
annotation:(id)annotation {
8282

83-
[self.router handleURL:url withCompletion:NULL];
83+
return [self.router handleURL:url withCompletion:NULL];
84+
}
85+
```
86+
**6. Passing `NSUserActivity` objects to the router** (optional)
87+
<br/>
88+
_**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:_
8489

85-
return YES;
90+
```objc
91+
- (BOOL)application:(UIApplication *)application
92+
continueUserActivity:(NSUserActivity *)userActivity
93+
restorationHandler:(void (^)(NSArray *))restorationHandler {
94+
95+
return [self.router handleUserActivity:userActivity withCompletion:NULL];
8696
}
8797
```
98+
99+
100+
88101
Learn more about the DeepLinkKit by reading our [Integration Guide](http://www.usebutton.com/sdk/deep-links/integration-guide).
89102

90103
## Route Registration Examples

SampleApps/ReceiverDemo/DPLReceiverAppDelegate.m

+8
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ - (BOOL)application:(UIApplication *)application
4747
return [self.router handleURL:url withCompletion:NULL];
4848
}
4949

50+
51+
- (BOOL)application:(UIApplication *)application
52+
continueUserActivity:(NSUserActivity *)userActivity
53+
restorationHandler:(void (^)(NSArray *))restorationHandler {
54+
55+
return [self.router handleUserActivity:userActivity withCompletion:NULL];
56+
}
57+
5058
@end

Tests/Router/DPLDeepLinkRouterSpec.m

+28
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,34 @@
173173
expect(isHandled).to.beFalsy();
174174
});
175175
});
176+
177+
it(@"handles an incoming user activity that is a web browsing activity type", ^{
178+
waitUntil(^(DoneCallback done) {
179+
180+
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:NSUserActivityTypeBrowsingWeb];
181+
activity.webpageURL = [NSURL URLWithString:@"https://dlc.com/say/hello"];;
182+
183+
router[@"/say/:word"] = ^{};
184+
185+
BOOL isHandled = [router handleUserActivity:activity withCompletion:^(BOOL handled, NSError *error) {
186+
expect(handled).to.beTruthy();
187+
expect(error).to.beNil();
188+
done();
189+
}];
190+
expect(isHandled).to.beTruthy();
191+
});
192+
});
193+
194+
it(@"does NOT handle an incoming user activity that is a NOT web browsing activity type", ^{
195+
196+
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"derpType"];
197+
activity.webpageURL = [NSURL URLWithString:@"https://dlc.com/say/hello"];;
198+
199+
router[@"/say/:word"] = ^{};
200+
201+
BOOL isHandled = [router handleUserActivity:activity withCompletion:NULL];
202+
expect(isHandled).to.beFalsy();
203+
});
176204
});
177205

178206
SpecEnd

0 commit comments

Comments
 (0)