Last active
July 1, 2019 11:48
-
-
Save mhmtkrgz/b8745aa8d89842043b72c076fa1d0264 to your computer and use it in GitHub Desktop.
Deep Link
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
/* | |
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¶m2=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 |
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
/* | |
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¶m2=abc | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment