【问题标题】:Xcode build settings, environment variables for simulator vs deviceXcode 构建设置,模拟器与设备的环境变量
【发布时间】:2015-08-21 10:12:27
【问题描述】:

我正在构建一个 iOS 应用程序(在 Swift 中,并不是说它有什么不同)。它与基本的 REST API 对话。

在为模拟器构建时,我让它在http://localhost:8000 访问我的本地服务器

在为设备构建时,我希望它在http://somedomainorother.com 访问公共测试服务器

我知道有一些方法可以为 debug 和 release 构建环境变量,但是否也有基于构建目标编写的方法?

【问题讨论】:

    标签: ios xcode


    【解决方案1】:

    我做了一个 pod 来处理环境设置,你可以看这里:https://github.com/nebiros/JIMEnvironments

    【讨论】:

      【解决方案2】:

      这似乎有效。如果有一个“更正确”的方式来实现它,我会全神贯注。

          #if  (arch(i386) || arch(x86_64)) && os(iOS)
              static let Path = "http://localhost:8000/api/v1/"
          #else
              static let Path = "http://somedomain.com/api/v1/"
          #endif
      

      【讨论】:

        【解决方案3】:

        我认为 TARGET_IPHONE_SIMULATOR 和 TARGET_OS_IPHONE 更好。

        #if TARGET_IPHONE_SIMULATOR
            static let Path = "http://localhost:8000/api/v1/"
        #elif TARGET_OS_IPHONE
            static let Path = "http://somedomain.com/api/v1/"
        #endif
        

        【讨论】:

          猜你喜欢
          • 2010-11-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-03-09
          • 2019-06-10
          相关资源
          最近更新 更多