gpt4 book ai didi

ios - 如何根据选定的目标加载基本 url

转载 作者:行者123 更新时间:2023-11-28 05:53:21 24 4
gpt4 key购买 nike

我如何根据为 Xcode 选择的目标加载 URL。

我为 iPhone 项目准备了四个环境。

1) Development [Base Url https://DemoDevelopmentURL.com/]
2) Testing (QA) [Base Url https://DemoTestURL.com/]
3) Staging (PreProduction) [Base Url https://DemoPreProductionURL.com/]
4) Production (Live) [Base Url https://DemoProductionURL.com/]

根据选择的目标,我们如何加载相关的 Base url

最佳答案

通过检查目标包 id:

let baseUrl: String!

switch Bundle.main.bundleIdentifier{
case "Development bundle id":
baseUrl = "https://DemoDevelopmentURL.com/"
case "Testing bundle id":
baseUrl = "https://DemoTestURL.com/"
case "Staging bundle id":
baseUrl = "https://DemoPreProductionURL.com/"
default:
baseUrl = "https://DemoProductionURL.com/"
}

或者将基本 url 放在每个目标 info.plist 上,然后从文件中加载它:

 var baseUrl: String {
guard let value = Bundle.main.object(forInfoDictionaryKey: "BaseURL") as? String else {
print("Could not find BaseURL variable in info.plist")
return "https://DemoProductionURL.com/"
}
return value
}

关于ios - 如何根据选定的目标加载基本 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52145831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com