简体   繁体   English

文档目录是否有Xcode构建设置参考?

[英]Is there a Xcode build setting reference for document directory?

I'm looking to see if any XCode build setting reference such as ${PROJECT_NAME} exists for the document directory. 我正在查看文档目录是否存在任何XCode build setting reference例如${PROJECT_NAME} I have some files saved to the document directory and I would like to run a script that would target that file. 我有一些文件保存到文档目录,我想运行一个以该文件为目标的脚本。 The document directory is from: 文档目录来自:

NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentDirectory = documentDirectories[0];

I searched through Apple's docs but maybe I missed it. 我搜索了Apple的文档,但也许错过了。

For example, if there is a "MyNotes.txt" in the iOS App document directory, I would like to run a script targeting that file (copy and pasting it to another folder). 例如,如果iOS App文档目录中有一个“ MyNotes.txt”,我想针对该文件运行脚本(将其复制并粘贴到另一个文件夹中)。

Thanks. 谢谢。

No, there's no Xcode build setting for the document directory. 不,文档目录没有Xcode构建设置。 You can add a empty Run Script to your build phases and check “Show environment variables in build log” to verify. 您可以在构建阶段添加一个空的运行脚本,然后选中“在构建日志中显示环境变量”进行验证。

You can figure out the document directory by using the simctl command and then checking a bunch of plists. 您可以使用simctl命令找出文档目录,然后检查一大堆文件。 It's a bit roundabout. 有点回旋处。 For example, this script finds the directory for an app with bundle identifier com.dqd.test , in the currently-booted simulated device: 例如,以下脚本在当前启动的模拟设备中找到捆绑标识符为com.dqd.test的应用程序的目录:

#!/bin/bash

bundle=com.dqd.test

appdir=$(xcrun simctl get_app_container booted "$bundle")
appdataparentdir="${appdir%%/data/Containers/Bundle/*}"/data/Containers/Data/Application
for dir in "$appdataparentdir"/*; do
    if plutil -extract MCMMetadataIdentifier xml1 -o - "$dir/.com.apple.mobile_container_manager.metadata.plist" | grep ">$bundle<" >/dev/null; then
        break
    fi
    dir=
done

if [ "$dir" != "" ]; then
    echo "$dir/Documents"
fi

Result: 结果:

:; ./getdocdir
/Users/mayoff/Library/Developer/CoreSimulator/Devices/3699C4CE-D6F3-4E6E-B1AC-0B35D78BFD80/data/Containers/Data/Application/32068FBC-6191-4F5E-B18F-D47D8778D3BE/Documents

Note that each simulated device has its own UUID, its own subdirectory in the under CoreSimulator/Devices , and its set of containers, so the output will change if you boot a different simulated device. 请注意,每个模拟设备都有其自己的UUID, CoreSimulator/Devices下的其子目录以及其容器集,因此,如果您启动其他模拟设备,则输出将更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM