I have implemented a URL Scheme and use it to pass data to my app by calling method. The entire code is shown as below
- (BOOL)application:(UIApplication *)a
I agree with Kaloyan, "handleOpenURL" is never called at application launch. So you have to check for URL in "launchOptions" in didFinishLaunchingWithOptions.
HOWEVER
I adopted the same solution as Apple example code for QuickActions (3D Touch). I keep the URL at launch in a variable, and I handle it in applicationDidBecomeActive:.
@interface MyAppDelegate ()
@property (nonatomic, strong) NSURL *launchedURL;
@end
@implementation MyAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.launchedURL = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
...
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (self.launchedURL) {
[self openLink:self.launchedURL];
self.launchedURL = nil;
}
}
- (BOOL) application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
NSURL *openUrl = url;
if (!openUrl)
{
return NO;
}
return [self openLink:openUrl];
}
- (BOOL)openLink:(NSURL *)urlLink
{
...
}
@end
Swift 2.x
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
if (url.scheme == "yuvitime") {
print("URL scheme:\(url.scheme)")
let yuvitimeRequestValue = url.query!
let userInfor = [
"YuvitimeRequest" : yuvitimeRequestValue
]
let notificationCentre = NSNotificationCenter.defaultCenter()
notificationCentre.postNotificationName("URLSCHEMEACTIVATEDNOTIFICATION", object: self, userInfo: userInfor)
return true
}
else {
return false
}
}