You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift实现APP链接跳转及视频分享带跳转链接方案咨询

iOS Video Sharing with App Deep Linking Solutions

Hey there! Let’s tackle your three questions step by step to get your app’s deep link sharing up and running alongside your video content.


You have two reliable options for deep linking in iOS: Custom URL Schemes and Universal Links. Here’s how to set up both:

Option 1: Custom URL Scheme (Quick Setup)

  • Head to your Xcode project settings → Info tab → expand URL Types
  • Add a new URL type: set Identifier to something like com.yourcompany.yourapp, and URL Schemes to a unique value (e.g., myapp)
  • Your dynamic jump link will look like: myapp://post?postId=1980 (replace 1980 with your actual post ID)

This uses standard HTTPS URLs that open your app directly if installed, or fall back to a web page if not:

  1. Enable Associated Domains in your Xcode project capabilities (requires an Apple Developer account)
  2. Add a domain entry like applinks:yourapp.com
  3. Host an apple-app-site-association file on your server at https://yourapp.com/.well-known/apple-app-site-association with content like:
    {
        "applinks": {
            "apps": [],
            "details": [
                {
                    "appID": "YOUR_TEAM_ID.com.yourcompany.yourapp",
                    "paths": ["/post/*"]
                }
            ]
        }
    }
    
  4. Your jump link will be a web URL like: https://yourapp.com/post/1980

2. Should You Add the URL to the Share Items Array?

Absolutely! To share both the video and your app link together, just append the URL (as a URL object) to your existing items array. Most social platforms (like Facebook) will handle both assets, displaying the video alongside a link preview or attachment.

Modify your existing code to include the link:

func launchShareActivityController(with items: [Any], of player: AVPlayer, postID: Int, canDownload: Int) {
    // Generate your deep link URL (use either Custom Scheme or Universal Link)
    guard let appLinkURL = URL(string: "myapp://post?postId=\(postID)") else {
        print("Failed to create app link URL")
        return
    }
    
    // Combine original items with the app link
    let shareItems: [Any] = items + [appLinkURL]
    
    let activityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
    activityViewController.popoverPresentationController?.sourceView = self.view
    activityViewController.completionWithItemsHandler = { activity, success, items, error in
        player.play()
        if success {
            print("successfully shared")
            self.postShare(postID: postID, completion: { (isSuccess, results) in
                if results.count > 0 {
                    // Add post-share logic here if needed
                }
            })
        }
    }
}

Note: Some platforms (like Instagram) may only support sharing a single media item. For these, you can add the link as plain text (e.g., "Check out this post in MyApp: myapp://post?postId=1980") instead of a URL object.


3. How to Detect Link Clicks & Route to the Specified Post

For Custom URL Schemes

Add this method to your AppDelegate (or SceneDelegate if using Scenes):

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    // Parse the URL to extract the post ID
    if url.scheme == "myapp", url.host == "post" {
        let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
        if let postIdString = components?.queryItems?.first(where: { $0.name == "postId" })?.value,
           let postId = Int(postIdString) {
            // Navigate to your post detail view controller
            let postVC = PostDetailViewController(postID: postId)
            if let window = app.windows.first, let rootVC = window.rootViewController {
                if let navVC = rootVC as? UINavigationController {
                    navVC.pushViewController(postVC, animated: true)
                } else {
                    rootVC.present(UINavigationController(rootViewController: postVC), animated: true)
                }
            }
            return true
        }
    }
    return false
}

Add this method to your AppDelegate or SceneDelegate:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb, let url = userActivity.webpageURL {
        // Parse the URL path to get the post ID (e.g., https://yourapp.com/post/1980)
        let pathComponents = url.pathComponents
        if pathComponents.count >= 3, pathComponents[1] == "post", let postId = Int(pathComponents[2]) {
            // Navigate to post detail view controller
            let postVC = PostDetailViewController(postID: postId)
            // Same navigation logic as above...
            return true
        }
    }
    return false
}

内容的提问来源于stack exchange,提问作者Aqib Javed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 11:02:30