URL Scheme设置网页跳转打开App

1、设置
在这里插入图片描述
2、代理方法

/// 打开App
static NSString *const identifierScheme = @"UrlSchemeControl://";

/// 打开App 并跳转到指定页面
static NSString *const identifierSecond = @"UrlSchemeControl://second";

/// 代理方法
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
    NSString *scheme = url.absoluteString.lowercaseString;
    if ([@[identifierScheme.lowercaseString, identifierSecond.lowercaseString] containsObject:scheme]) {
        NSComparisonResult compareResult = [scheme compare:identifierSecond.lowercaseString];
        if (compareResult == NSOrderedSame) {
             // 打开App后发通知要打开哪个页面
            [NSNotificationCenter.defaultCenter postNotificationName:@"NextClick" object:nil userInfo:nil];
        }
        // 打开App
        return YES;
    }
    
    return NO;
}

/// 需要跳转的行为页面接收通知
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(nextClick) name:@"NextClick" object:nil];

发布了804 篇原创文章 · 获赞 135 · 访问量 142万+

猜你喜欢

转载自blog.csdn.net/potato512/article/details/103205604