iOS Universal link注意事项

当用户安装APP时,系统会检查存储在服务器上的apple文件,以验证网站是否允许app代表其打开URL

  1. 首先配置好apple-app-site-association

  2. 将其放入yourdomain.well-known下

  3. 通过网址打开https://yourdomain/.well-known/apple-app-site-association 检查apple-app-site-association是否已经配置

  4. 检查Apple cdn: app-site-association.cdn-apple.com/a/v1/yourdo... 必须等apple cdn与文件一致时,才是真正的生效,apple cdn一般在24小时内更新

  5. 在项目中添加Associated Domains,配置好applinks:yourdomain

  6. 在notes 中长按相应link,如一切正常,会出现打开app的选项

  7. open app之后的处理

当你的app没有使用Scene时,可以在AppDelete.swift文件中处理

swift 复制代码
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) {
    // Get URL components from the incoming user activity. 
    guard userActivity.activityType == NSUserActivityTypeBrowsingWeb, 
    let incomingURL = userActivity.webpageURL, 
    let components = NSURLComponents(url: incomingURL, resolvingAgainstBaseURL: true) else { 
    return false 
    } 
    // Check for specific URL components that you need. 
    guard let path = components.path, 
    let params = components.queryItems else { 
    return false 
    } 
    print("path = \(path)")
}

当你的app使用Scene时,可以在SceneDelegate.swift文件中处理

swift 复制代码
//app没有运行,系统会在启动后将Universal link传递到Scene
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Get URL components from the incoming user activity. 
    guard let userActivity = connectionOptions.userActivities.first, 
        userActivity.activityType == NSUserActivityTypeBrowsingWeb, 
        let incomingURL = userActivity.webpageURL, 
        let components = NSURLComponents(url: incomingURL, resolvingAgainstBaseURL: true) else { 
        return 
        } 
        // Check for specific URL components that you need. 
        guard let path = components.path, 
        let params = components.queryItems else { 
        return 
        } 
        print("path = \(path)")
}

//当app在内存中运行或暂停时点击Universal link时,将链接传递到Scene
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    // Get URL components from the incoming user activity. 
    guard userActivity.activityType == NSUserActivityTypeBrowsingWeb, 
    let incomingURL = userActivity.webpageURL, 
    let components = NSURLComponents(url: incomingURL, resolvingAgainstBaseURL: true) else { 
    return false 
    } 
    // Check for specific URL components that you need. 
    guard let path = components.path, 
    let params = components.queryItems else { 
    return false 
    } 
    print("path = \(path)")
}

参考资料

1.developer.apple.com/videos/play... 2.developer.apple.com/documentati...

相关推荐
奇客软件1 天前
如何从相机的记忆棒(存储卡)中恢复丢失照片
深度学习·数码相机·ios·智能手机·电脑·笔记本电脑·iphone
GEEKVIP1 天前
如何修复变砖的手机并恢复丢失的数据
macos·ios·智能手机·word·手机·笔记本电脑·iphone
一丝晨光1 天前
继承、Lambda、Objective-C和Swift
开发语言·macos·ios·objective-c·swift·继承·lambda
GEEKVIP2 天前
iPhone/iPad技巧:如何解锁锁定的 iPhone 或 iPad
windows·macos·ios·智能手机·笔记本电脑·iphone·ipad
KWMax2 天前
RxSwift系列(二)操作符
ios·swift·rxswift
Mamong2 天前
Swift并发笔记
开发语言·ios·swift
GEEKVIP2 天前
手机使用指南:如何在没有备份的情况下从 Android 设备恢复已删除的联系人
android·macos·ios·智能手机·手机·笔记本电脑·iphone
奇客软件3 天前
如何使用工具删除 iPhone 上的图片背景
windows·ios·智能手机·excel·音视频·cocoa·iphone
安和昂3 天前
【iOS】计算器的仿写
ios
SchneeDuan3 天前
iOS--App启动过程及优化
ios