Skip to content

Instead of storing the completion handler, we forward it instead. #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions DeepLinkSDK/Router/DPLDeepLinkRouter.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@interface DPLDeepLinkRouter ()

@property (nonatomic, copy) DPLApplicationCanHandleDeepLinksBlock applicationCanHandleDeepLinksBlock;
@property (nonatomic, copy) DPLRouteCompletionBlock routeCompletionHandler;

@property (nonatomic, strong) NSMutableOrderedSet *routes;
@property (nonatomic, strong) NSMutableDictionary *classesByRoute;
Expand Down Expand Up @@ -105,14 +104,13 @@ - (void)setObject:(id)obj forKeyedSubscript:(NSString *)key {

#pragma mark - Routing Deep Links

- (void)handleURL:(NSURL *)url withCompletion:(DPLRouteCompletionBlock)completionHandler; {
self.routeCompletionHandler = completionHandler;
- (void)handleURL:(NSURL *)url withCompletion:(DPLRouteCompletionBlock)completionHandler {
if (!url) {
return;
}

if (![self applicationCanHandleDeepLinks]) {
[self completeRouteWithSuccess:NO error:nil];
[self completeRouteWithSuccess:NO error:nil completionHandler:completionHandler];
return;
}

Expand All @@ -133,7 +131,7 @@ - (void)handleURL:(NSURL *)url withCompletion:(DPLRouteCompletionBlock)completio
error = [NSError errorWithDomain:DPLErrorDomain code:DPLRouteNotFoundError userInfo:userInfo];
}

[self completeRouteWithSuccess:isHandled error:error];
[self completeRouteWithSuccess:isHandled error:error completionHandler:completionHandler];
}


Expand Down Expand Up @@ -175,13 +173,18 @@ - (BOOL)handleRoute:(NSString *)route withDeepLink:(DPLDeepLink *)deepLink error
}


- (void)completeRouteWithSuccess:(BOOL)handled error:(NSError *)error {

dispatch_async(dispatch_get_main_queue(), ^{
if (self.routeCompletionHandler) {
self.routeCompletionHandler(handled, error);
}
});
- (void)completeRouteWithSuccess:(BOOL)handled error:(NSError *)error completionHandler:(DPLRouteCompletionBlock)completionHandler {
if (!completionHandler) {
return;
}
dispatch_block_t block = ^{
completionHandler(handled, error);
};
if ([NSThread isMainThread]) {
block();
} else {
dispatch_async(dispatch_get_main_queue(), block);
}
}

@end