Created
May 25, 2014 07:14
-
-
Save yurrriq/00c88a54ff2df51ec278 to your computer and use it in GitHub Desktop.
iOS Deep Linking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface EWAppDelegate : UIResponder<UIApplicationDelegate> | |
@property(strong, nonatomic) UIWindow *window; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface EWApplication : UIApplication | |
- (BOOL)openInSafari:(NSURL *)url; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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