在自定义.plist文件中使用用户定义的构建设置 [英] Use User-Defined build settings in custom .plist file
问题描述
我为我的应用程序定义了不同的构建配置(Debug,Stage,Prod),我使用用户定义的构建设置:
I have different build configurations (Debug, Stage, Prod) defined for my app and I use User-Defined build settings:
在 Info.plist中设置Facebook登录和其他内容
文件:
在此方案中 $(USER_DEFINED_SETTINGS)
表示法 有效。
In this scenario the $(USER_DEFINED_SETTINGS)
notation does work.
当我尝试设置 Google SignIn 时,需要使用额外的 .plist
文件( GoogleService-Info.plist
),我使用用户定义的设置,就像我在中一样Info.plist
文件,它不起作用。
When I tried to set up Google SignIn, which requires using additional .plist
file (GoogleService-Info.plist
), and I used User-Defined settings in the same way I do in the Info.plist
file, it doesn't work.
如何在自定义中使用用户定义的设置 .plist
文件?如果我不能,我该如何解决这个问题?
How can I use User-Defined settings in custom .plist
files? If I can't, how can I workaround this?
推荐答案
不可以使用< 自定义 .plist文件中的strong>用户定义的设置,因此您必须以其他方式处理此问题。
It's NOT possible to use User-Defined settings in custom .plist file, so you have to handle this in the other way.
虽然,您可以将自定义.plist文件复制到正确的位置:
Although, you can copy your custom .plist file to the right place:
- 创建一个新文件夹(例如: GoogleServiceInfoPlists )。
- 复制每个环境的所有.plist文件(例如: GoogleService-Info-Debug.plist, GoogleService-Info- Stage.plist 和 GoogleService-Info-Prod.plist )。
- 添加新
运行脚本阶段
(Xcode:目标 - >构建阶段 - >+按钮)。 -
使用下面的脚本复制(替换).plist给定环境的文件到主目录(在我的情况下是
src
):
- Create a new folder (for example: GoogleServiceInfoPlists).
- Copy there all .plist files for each environment (for example: GoogleService-Info-Debug.plist, GoogleService-Info-Stage.plist and GoogleService-Info-Prod.plist).
- Add new
Run Script Phase
(Xcode: Target->Build Phases->"+" button). Use script below to copy (replace) .plist file for given environment to the main directory (it's
src
in my case):
cp "${SRCROOT}/src/Resources/GoogleServiceInfoPlists/GoogleService-Info-$CONFIGURATION.plist" "${SRCROOT}/src/GoogleService-Info.plist"
$ {SRCROOT}
- 预定义,它指向您的项目位置。
${SRCROOT}
- predefined, it points to your project location.
$ CONFIGURATION
- 预定义,这是你的构建配置,在我的情况下: Debug
, Stage
, Prod
。您可以在Xcode中更改此项:项目(不是目标!) - > 信息。
$CONFIGURATION
- predefined, it's your build configuration, in my case: Debug
, Stage
, Prod
. You can change this in Xcode: Project (not target!)->Info.
请注意 src / GoogleService-Info.plist
文件必须添加到Xcode项目( Build Phases-> Copy Bundle Resource s )而 / src / Resources / GoogleServiceInfoPlists / GoogleService-Info - *
文件不一定。
Please note that src/GoogleService-Info.plist
file must be added to the Xcode project (Build Phases->Copy Bundle Resources) while /src/Resources/GoogleServiceInfoPlists/GoogleService-Info-*
files not necessarily.
UPDATE :
请记住,您的新运行脚本必须放在复制捆绑资源构建阶段之前。否则,它将无法工作,因为它将被复制得太晚,并且将使用默认版本的.plist文件。
Remember that your new Run Script must be placed before Copy Bundle Resources build phase. Otherwise, it won't work because it would be copied too late and the default version of the .plist file would be used.
这篇关于在自定义.plist文件中使用用户定义的构建设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!