Skip to content

Instantly share code, notes, and snippets.

@yurrriq
Created May 25, 2014 07:14
Show Gist options
  • Save yurrriq/00c88a54ff2df51ec278 to your computer and use it in GitHub Desktop.
Save yurrriq/00c88a54ff2df51ec278 to your computer and use it in GitHub Desktop.
iOS Deep Linking
#import <UIKit/UIKit.h>
@interface EWAppDelegate : UIResponder<UIApplicationDelegate>
@property(strong, nonatomic) UIWindow *window;
@end
// See also: https://developer.apple.com/library/ios/documentation/uikit/reference/uiapplicationdelegate_protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:openURL:sourceApplication:annotation:
#import "EWAppDelegate.h"
#import "SVWebViewController.h"
@implementation EWAppDelegate
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
if ([[url scheme] isEqualToString:@"ewapp"]) {
//TODO: parse custom URL and take action
} else {
// open url in an in-app browser
UINavigationController *rootViewController = self.window.rootViewController;
SVModalWebViewController *webViewController =
[[SVModalWebViewController alloc] initWithURL:url];
[rootViewController presentViewController:webViewController
animated:YES
completion:NULL];
}
return YES; // if the request was handled successfully, otherwise NO
}
@end
#import <UIKit/UIKit.h>
@interface EWApplication : UIApplication
- (BOOL)openInSafari:(NSURL *)url;
@end
#import "EWApplication.h"
@implementation EWApplication
- (BOOL)openInSafari:(NSURL *)url {
[super openURL:url];
return YES;
}
- (BOOL)openURL:(NSURL *)url {
[[self delegate]
application:self
openURL:url
sourceApplication:[[NSBundle mainBundle]
objectForInfoDictionaryKey:@"CFBundleDisplayName"]
annotation:nil];
return YES;
}
@end
Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- ... -->
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>ewapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>ewapp</string>
</array>
</dict>
<!-- ... -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment