动态更改应用程序 CFBundleURLScheme plist 条目(编译后)

发布于 2024-11-14 12:07:01 字数 208 浏览 1 评论 0原文

我正在尝试创建一个 iPhone 应用程序来处理各种 URL 方案,我将通过查询服务器动态确定这些方案。

是否可以通过编程方式注册自定义 url 方案?换句话说,您可以在编译/部署应用程序后更新 CFBundleURLScheme plist 条目吗?

我在其他地方找不到任何这样做的例子,但我也找不到任何明确的理由来说明为什么这是不可能的。

非常感谢。

I'm trying to create an iPhone application that will handle a variety of URL Schemes that I will determine dynamically by querying a server.

Is it possible to register for a custom url scheme programmatically? In other words, can you update the CFBundleURLScheme plist entry after the application has been compiled / deployed?

I haven't been able to find any examples of this being done elsewhere, but nor can I find any definitive reasons why this isn't possible.

Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

短叹 2024-11-21 12:07:01

对不起,没有办法了。您无法以编程方式注册自定义 url 方案。您也无法编辑 Info.plist,应用程序包在 iPhone 上是只读的。

I'm sorry, there is no way. You cannot register custom url schemes programmatically. You also cannot edit your Info.plist, application bundles are read-only on the iPhone.

黯然 2024-11-21 12:07:01

以下是我为 Swift 解决这个问题的方法:

var plistPath = NSBundle.mainBundle().pathForResource("Info", ofType: "plist")

var urlStuff = NSMutableDictionary(contentsOfFile: plistPath!)
var urlType = NSDictionary(objectsAndKeys: "com.appprefix.AppName", "CFBundleURLName", NSArray(object: "idofobject"), "CFBundleURLSchemes")
urlStuff?.setObject(NSArray(object: urlType), forKey: "CFBundleURLTypes")
urlStuff?.writeToFile(plistPath!, atomically: true)

Here is how I solved it for Swift:

var plistPath = NSBundle.mainBundle().pathForResource("Info", ofType: "plist")

var urlStuff = NSMutableDictionary(contentsOfFile: plistPath!)
var urlType = NSDictionary(objectsAndKeys: "com.appprefix.AppName", "CFBundleURLName", NSArray(object: "idofobject"), "CFBundleURLSchemes")
urlStuff?.setObject(NSArray(object: urlType), forKey: "CFBundleURLTypes")
urlStuff?.writeToFile(plistPath!, atomically: true)
筱果果 2024-11-21 12:07:01

2021 年的新答案

现在可以在使用某些脚本编译应用程序之前编辑 Info.plist。

您可以参考这篇文章:添加/替换URL方案在 Info.plist 中使用 bash 脚本

NEW ANSWER AS OF 2021

It is now possible to edit your Info.plist before compiling your app using some scripts.

You can refer to this post: Add/Replace URL Scheme in Info.plist using bash script

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文