Search code examples
ios9uiapplicationdelegate

UIApplicationDelegate 3 similar openURL methods


@protocol UIApplicationDelegate<NSObject>

...
- (BOOL)application:(UIApplication *)application 
handleOpenURL:(NSURL *)url 
NS_DEPRECATED_IOS(2_0, 9_0, "Please use application:openURL:options:") __TVOS_PROHIBITED;

- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation 
NS_DEPRECATED_IOS(4_2, 9_0, "Please use application:openURL:options:") __TVOS_PROHIBITED;

- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options 
NS_AVAILABLE_IOS(9_0); // no equiv. notification. return NO if the application can't open for some reason
...

In UIApplicationDelegate protocol,there exists 3 similar openURL callback methods,how to use them in your app for best compatibility?


Solution

  • The first two are the old delegates to handle URL-schemes in iOS < 9. In iOS 9, they have been combined to the last one to unify both delegates and also make the options more configurable for the future using the UIApplicationOpenURLOptionsKey type.

    Note: They can also coexist to retain backwards compatibility in case you still target iOS < 9. iOS will detect the correct delegate for each iOS version as long as you implement them.