iOS 10 新特性之openURL

来源:互联网 发布:dota2 a卡优化 编辑:程序博客网 时间:2024/05/22 16:54

一、iOS之前一直使用openURL,来打开设置页面、其他APP应用。

- (BOOL)openURL:(NSURL*)url NS_DEPRECATED_IOS(2_0, 10_0, "Please use openURL:options:completionHandler: instead") NS_EXTENSION_UNAVAILABLE_IOS("");

现如今API改为了一下:

// Options are specified in the section below for openURL options. An empty options dictionary will result in the same// behavior as the older openURL call, aside from the fact that this is asynchronous and calls the completion handler rather// than returning a result.// The completion handler is called on the main queue.- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion NS_AVAILABLE_IOS(10_0) NS_EXTENSION_UNAVAILABLE_IOS("");
  1. 传和不传,结果都是一样的;
  2. block是在主线程的。
    用法:
    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) { //TODO }];

1.2 统对于option的定义

// Option for openURL:options:CompletionHandler: only open URL if it is a valid universal link with an application configured to open it// If there is no application configured, or the user disabled using it to open the link, completion handler called with NOUIKIT_EXTERN NSString *const UIApplicationOpenURLOptionUniversalLinksOnly NS_AVAILABLE_IOS(10_0);

1.参数是用来校验url和applicationConfigure是否配置正确,是否可用。如果不满足则返回NO;

用法:

[[UIApplication sharedApplication] openURL:url options:@{UIApplicationOpenURLOptionUniversalLinksOnly:@YES} completionHandler:^(BOOL success) {                    //TODO                }];
0 0