Skip to content

Instantly share code, notes, and snippets.

@mhmtkrgz
Last active July 1, 2019 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhmtkrgz/b8745aa8d89842043b72c076fa1d0264 to your computer and use it in GitHub Desktop.
Save mhmtkrgz/b8745aa8d89842043b72c076fa1d0264 to your computer and use it in GitHub Desktop.
Deep Link
/*
Place following code in your info.plist file.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>hostApplicationURLScheme</string>
</array>
*/
#import <StoreKit/StoreKit.h>
static NSString *const kCustomURLString = @"hostApplicationURLScheme://?param1=123abct&param2=abcde";
static NSInteger const kAppIdientifier = <YOUR_APP_ID>;
@interface GuestAppViewController () <SKStoreProductViewControllerDelegate>
@implementation GuestAppViewController
- (void)openApp {
NSURL *customURL = [NSURL URLWithString:kCustomURLString];
if ([[UIApplication sharedApplication] canOpenURL:customURL]) {
[[UIApplication sharedApplication] openURL:customURL];
} else {
[self openAppStore];
}
}
- (void)openAppStore {
SKStoreProductViewController *storeViewController = [SKStoreProductViewController new];
storeViewController.delegate = self;
NSNumber *identifier = [NSNumber numberWithInteger:kAppIdientifier];
NSDictionary *parameters = @{ SKStoreProductParameterITunesItemIdentifier:identifier };
[storeViewController loadProductWithParameters:parameters
completionBlock:^(BOOL result, NSError *error) {
if (result)
[self presentViewController:storeViewController
animated:YES
completion:nil];
else {
NSLog(@"SKStoreProductViewController error: %@", error);
}
}];
}
#pragma mark - <SKStoreProductViewControllerDelegate>
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[viewController dismissViewControllerAnimated:YES completion:nil];
}
@end
/*
Place following code in your info.plist file.
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.hostApplication.bundle</string>
<key>CFBundleURLSchemes</key>
<array>
<string>hostApplicationURLScheme</string>
</array>
</dict>
</array>
*/
@implementation HostApplicationAppDelegate
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
NSLog(@"Source application: %@", options[UIApplicationOpenURLOptionsSourceApplicationKey]); //com.questApp.bundle
NSLog(@"URL scheme: %@", [url scheme]); //hostApplicationURLScheme
NSLog(@"URL query: %@", [url query]); //param1=123&param2=abc
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment