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

如何通过URL Scheme唤起App并保留其原有页面状态?

解决方案

要唤起Instagram并保留其当前页面状态,按以下步骤操作:

  • 更换URL Scheme:放弃使用instagram://app(该Scheme会强制跳转至Instagram首页),改用instagram://。这个基础Scheme会直接将Instagram唤至前台,完全保留用户之前停留的页面和操作状态。
  • 配置App查询权限:在你的App的Info.plist文件中添加LSApplicationQueriesSchemes数组,将instagram加入数组,确保App有权查询并打开Instagram。
  • 示例代码:
    @IBAction func openInstagram(_ sender: UIButton) {
        guard let instagramURL = URL(string: "instagram://") else { return }
        if UIApplication.shared.canOpenURL(instagramURL) {
            UIApplication.shared.open(instagramURL, options: [:], completionHandler: nil)
        } else {
            // 处理Instagram未安装的场景,比如提示用户安装
            print("Instagram未安装")
        }
    }
    

原因很简单:instagram://是Instagram的通用唤起Scheme,不会指定目标页面,系统会直接恢复App的当前活跃状态;而instagram://app是官方定义的定向跳转首页的Scheme,这就是之前页面被重置的核心原因。

内容的提问来源于stack exchange,提问作者Adi Shah

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 03:44:57