The method of UIApplication as a singleton object is openURL:
often used in iOS development to implement the need to open external links in the current application, such as jumping to other applications, jumping to the Application privacy settings interface, and the relevant API canOpenURL:
for pre-jump judgment. And this ancient (iOS2) openURL
method will be replaced by the new API that appears today iOS10 openURL:options:completionHandler:
.
While the official documentation on the API complements the full, the information provided is sufficient to give developers a simple idea of the similarities and differences between APIs that open external links using the latest APIs.
Official description of the new API
First look at the official documentation for IOS10 's what's New in IOS Uikit section for a description of the newer API
The new UIApplication method OpenURL:options:completionHandler:, which is executed asynchronously and calls the specified Completion handler on the main queue (this method replaces OpenURL:).
This passage clearly indicates the two features of the new API: the asynchronous execution of the open operation and the main thread execution callback.
Code description for the new API
Then look at the specific interface code, you can see that the way to determine the success of the link is also from the previous openURL
call return from the Boolean value into the query completion success parameters;
Old
-(BOOL) OpenURL: (nsurl
New
-(void) OpenURL: (nsurl*) URL options: (nsdictionary<nsstring *, id> *) options Completionhandler: (void (^ __nullable) (BOOL success)) Completion
Additionally, an options dictionary parameter is provided for URL processing, and an empty dictionary is called without qualifying values, as in the code below.
[[UIApplication Sharedapplication] openurl:url options:@{} completionhandler:nil";
Options currently can pass in Parameter key in the UIApplication header file only one: Uiapplicationopenurloptionuniversallinksonly, its corresponding value is a Boolean value, The default is False.
if the value corresponding to the key is true, then opening the incoming universal link allows only the link to be opened via the iOS app that the link represents, otherwise it will return success to False,
This means that you can open this universal link only if you have installed the app for link, instead of launching safari to open the link's Representative website.
options:@{uiapplicationopenurloptionuniversallinksonlycompletionhandler:nil];
The change of OpenURL method as a method of UIApplication single-instance object