The change of OpenURL method as a method of UIApplication single-instance object

Source: Internet
Author: User

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) openURLmethod 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.