Cordova config.xml을 통해 iOS .plist 파일에 항목 추가
Cordova CLI를 처음 사용합니다.
Cordova를 통해 프로그래밍 방식으로 다음 단계를 수행해야합니다.
- 프로젝트 .plist에서 새 행 추가
- 새 행에 다음 값을 입력하십시오.
- 키 : GDLibraryMode 유형 : 문자열 (기본값) 값 : GDEnterpriseSimulation
내 프로젝트의 루트 (또는 "platforms"폴더에있는 파일)에있는 config.xml 파일에서이 작업을 수행해야한다고 생각합니다.
누군가가 config.xml을 통해 항목을 추가하는 방법을 설명하여 위 항목이 컴파일 타임에 추가되도록 할 수 있습니까?
Cordova 3.3.1-0.42를 사용하고 있습니다 (최신 버전이 아님). 이미 내 프로젝트를 만들었고 모든 것이 괜찮습니다.이 항목을 pList에 추가하기 만하면됩니다.
나는 당신이 직접적인 config.xml
수정을 통해 이것을 할 수 있다고 생각하지 않습니다 . 적어도 문서에서 이에 대한 언급을 보지 못했습니다. http://cordova.apache.org/docs/en/3.3.0/config_ref_index.md.html
plist 항목을 삽입 할 수 있기 때문에 플러그인을 만들어야한다고 생각합니다. http://docs.phonegap.com/en/3.3.0/plugin_ref_spec.md.html#Plugin%20Specification
'구성 파일 요소'섹션을 참조하십시오. 의 관련 섹션이 어떻게 생겼는지 추측 해 plugin.xml
보겠습니다.
<platform name="ios">
<config-file target="*-Info.plist" parent="CFBundleURLTypes">
<array>
<dict>
<key>GDLibraryMode</key>
<string>GDEnterpriseSimulation</string>
</dict>
</array>
</config-file>
</platform>
그런 다음 플러그인을 설치할 수 있습니다. cordova plugin add <your plugin name or file location>
Cordova 후크를 사용하는 @james의 솔루션 을 정말 좋아 합니다. 그러나 두 가지 문제가 있습니다. 워드 프로세서 상태 :
- " Node.js를 사용하여 후크를 작성하는 것이 좋습니다. "
- "
/hooks
디렉토리는 " 의 후크 요소 대신 사용되지 않는 것으로 간주됩니다config.xml
.
다음은 plist NPM 패키지를 사용하는 Node.js 구현입니다 .
var fs = require('fs'); // nodejs.org/api/fs.html
var plist = require('plist'); // www.npmjs.com/package/plist
var FILEPATH = 'platforms/ios/.../...-Info.plist';
module.exports = function (context) {
var xml = fs.readFileSync(FILEPATH, 'utf8');
var obj = plist.parse(xml);
obj.GDLibraryMode = 'GDEnterpriseSimulation';
xml = plist.build(obj);
fs.writeFileSync(FILEPATH, xml, { encoding: 'utf8' });
};
Cordova에서 제공하는 모든 후크 유형 중에서 상황에 맞는 후크 유형은 다음과 같습니다.
after_prepare
before_compile
후크 유형을 선택한 다음 config.xml
파일에 후크를 추가 합니다.
<platform name="ios">
<hook type="after_prepare" src="scripts/my-hook.js" />
</platform>
Cordova 후크 스크립트 내 에서 PlistBuddy 유틸리티를 사용 하여 * -Info.plist 파일을 수정할 수 있습니다.
예를 들어, <project-root>/hooks/after_prepare/010_modify_plist.sh
사전 속성을 추가하고 해당 사전 내에 항목을 추가하는 다음 스크립트가 있습니다 .
#!/bin/bash
PLIST=platforms/ios/*/*-Info.plist
cat << EOF |
Add :NSAppTransportSecurity dict
Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool YES
EOF
while read line
do
/usr/libexec/PlistBuddy -c "$line" $PLIST
done
true
스크립트를 실행 가능하게 만드십시오 ( chmod +x
).
true
스크립트의 끝이 있기 때문이다 PlistBuddy
오류 종료 코드와 리턴 키 존재가 추가 한 경우 이미 존재하고 키가 이미 존재하는 경우 감지 할 수있는 방법을 제공하지 않습니다. Cordova는 후크 스크립트가 오류 상태로 종료되는 경우 빌드 오류를보고합니다. 더 나은 오류 처리가 가능하지만 구현하기가 어렵습니다.
다음은 내 응용 프로그램이 장치간에 iTunes를 통해 파일을 공유 할 수 있도록하기 위해 수행 한 단계입니다.
1. 애플리케이션에서 config.xml로 이동합니다. 이 부분을 플랫폼 태그 아래의 구성에 입력하십시오 <platform name="ios">
.
<config-file platform="ios" target="*-Info.plist" parent="UIFileSharingEnabled">
<true/>
</config-file>
2. 그런 다음 명령 줄 도구로 이동하여 다음을 입력합니다. cordova prepare
- 장치에서 응용 프로그램을 제거하고 다시 설치하면 장치간에 파일을 공유 할 수 있도록 iTunes에 앱이 표시됩니다.
몇 가지 사항, Cordova가 최신 상태인지 확인하고 iOS 용 플랫폼을 추가했는지 확인하십시오.
npm install -g cordova
이 명령은 cordova를 설치합니다.
cordova platform add ios
이 명령은 iOS 용 플랫폼을 추가합니다.
무슨 일이 일어나고 있는지는 cordova prepare 명령을 실행할 때 platform / ios 폴더에 생성되는 Apple의 Xcode SDK를 사용하는 것입니다. 여기에서 "yourApp-info.plist"로 레이블이 지정된 애플리케이션에 대해 생성 된 plist 파일을 볼 수 있습니다. 다음과 같은 xml 레이아웃에서 생성 된 새 키와 문자열을 볼 수 있습니다.
<key>UIFileSharingEnabled</key>
<true/>
또한 경고의 한마디로, 우리 회사는 몇 주 전에이 이온 프레임 워크 애플리케이션을 제 무릎에 떨어 뜨 렸습니다 (정말 짧은 기한으로). 내가 말하는 모든 것은 2 주간의 학습을 기반으로합니다. 따라서 이것은 모범 사례가 아닐 수도 있지만 누군가에게 도움이되기를 바랍니다.
이것은 이제 config.xml을 사용하여 가능한 것 같습니다. 적어도 일부 핵심 플러그인 작성자는 그렇게 말합니다. 예를 들어 Cordova Camera Plugin 문서 에서 plist에 권한 메시지 문자열을 제공해야하는 iOS 10의 새로운 요구 사항에 대해 설명합니다. 이를 수행하기 위해 인수와 함께 플러그인 add 명령을 실행하는 것이 좋습니다.
cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="My App would like to access your camera, to take photos of your documents."
결과적 <plugin>
으로 config.xml에 새로 추가 될뿐만 아니라 <variable>
자식도 있습니다.
<plugin name="cordova-plugin-camera" spec="~2.3.0">
<variable name="CAMERA_USAGE_DESCRIPTION" value="My App would like to access your camera, to take photos of your documents." />
</plugin>
그러면 내 info.plist의 새 키와 관련이있는 것 같습니다. 아마도 런타임에 값을 전달하는 것 같습니다.
<key>NSCameraUsageDescription</key>
<string/>
<key>NSPhotoLibraryUsageDescription</key>
<string/>
그것이 어떻게 작동하는지 정확히 안다고 말하면 거짓말을하는 것입니다. 그러나 그것이 길을 가리키는 것 같습니다.
업데이트 : 사람들이 iOS> = 10에서 카메라를 사용하고 싶어합니다. 이는 일반적으로 플러그인에서 다음과 같이 구성 할 수 있음을 의미합니다.
<!-- ios -->
<platform name="ios">
<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
<string></string>
</config-file>
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string></string>
</config-file>
<config-file target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
<string></string>
</config-file>
</platform>
하지만 지금, 당신은 할 수 config (설정) NSCameraUsageDescription
및 NSPhotoLibraryUsageDescription
플러그인이다. 플랫폼-> iOS 프로젝트에서 Xcode 또는 *-Info.plist
파일 로 구성해야 합니다.
iOS 10부터 info.plist에 NSCameraUsageDescription 및 NSPhotoLibraryUsageDescription을 추가해야합니다.
자세히 알아보기 : https://www.npmjs.com/package/cordova-plugin-camera
추가 플러그인이나 가져 오기없이 ionic 3 에서 다음을 사용하고 있으며 이것이 다른 사람들에게 도움이 될 수 있다고 생각합니다.
<platform name="ios">
<edit-config file="*-Info.plist" mode="merge" target="NSLocationWhenInUseUsageDescription">
<string>Location is required so we can show you your nearby projects to support.</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSCameraUsageDescription">
<string>Camera accesss required in order to let you select profile picture from camera.</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSPhotoLibraryUsageDescription">
<string>Photo library accesss required in order to let you select profile picture from gallery / library.</string>
</edit-config>
</platform>
plugins 디렉토리에서 ios.json을 직접 편집하여 앱의 plist에서 표시 이름을 설정할 수 있습니다.
ios.json 파일의 config_munge.files 섹션에 다음을 추가하면 트릭이 수행되며 CLI를 사용하는 경우에도 유지됩니다.
"*-Info.plist": {
"parents": {
"CFBundleDisplayName": [
{
"xml": "<string>RevMob Ads Cordova Plugin Demo</string>",
"count": 1
}
]
}
}
여기에 완전한 예가 있습니다.
@TachyonVortex solution seems to be the best option but was crashing down in my case. The issue was caused by an empty NSMainNibFile field that is not right converted by the plist NPM package. In the .plist file
<key>NSMainNibFile</key>
<string></string>
<key>NSMainNibFile~ipad</key>
<string></string>
is converted to:
<key>NSMainNibFile</key>
<string>NSMainNibFile~ipad</string>
I fixed it with by adding to the script:
obj.NSMainNibFile = '';
obj['NSMainNibFile~ipad'] = '';
The script finally looks like (scripts/my-hook.js):
var fs = require('fs'); // nodejs.org/api/fs.html
var plist = require('plist'); // www.npmjs.com/package/plist
var FILEPATH = 'platforms/ios/***/***-Info.plist';
module.exports = function (context) {
var xml = fs.readFileSync(FILEPATH, 'utf8');
var obj = plist.parse(xml);
obj.GDLibraryMode = 'GDEnterpriseSimulation';
obj.NSMainNibFile = '';
obj['NSMainNibFile~ipad'] = '';
xml = plist.build(obj);
fs.writeFileSync(FILEPATH, xml, { encoding: 'utf8' });
};
and config.xml:
<platform name="ios">
<hook type="before_build" src="scripts/my-hook.js" />
</platform>
I have used this plugin to solve the problem, maybe it can help you :
https://www.npmjs.com/package/cordova-plugin-queries-schemes
If you are trying to modify a .plist
in a native iOS plugin with a <config-file>
tag in your plugin.xml
, here is what you need to do:
Make sure your
.plist
is xml, not binary! You can useplutil
to convert a binary.plist
into xml, and commit it to version control.plutil -convert xml1 Info.plist
The instructions for
<config-file>
indicate thattarget=
is relative to the generated xcode project atplatforms/ios/<project>/
, but I found that I needed to prepend a wildcard character to my path to get it to work:target="*/Resources/MyResources.bundle/Info.plist"
If you want to add a key at the top level of the
.plist
, you need to set parent equal to the key name, and then nest a<string>
tag with the value. Using an<array>
or<dict>
as any examples show will cause these keys to be nested underparent
.
Here is a complete example that works for me for adding multiple top level properties:
<platform name="ios">
<config-file target="*/Resources/MyResources.bundle/Info.plist" parent="MyDistribution">
<string>Cordova</string>
</config-file>
<config-file target="*/Resources/MyResources.bundle/Info.plist" parent="MyVersion">
<string>3.2.0</string>
</config-file>
</platform>
I prefer the after_prepare hook for bigger projects or if you have multiple plugins using the same permissions. But you can always go the simple way:
simply: - remove the plugin that requires the desired permission - add it again with --save - in config.xml, the plugin now has a new variable with a blank description that you can fill in - now build ios with -- release and they will be set.
Yes, it is possible!
I am using Cordova 9.0.0 (cordova-lib@9.0.1).
For example this is the configuration file that I used to insert new string value into Info.plist :
<platform name="ios">
<edit-config file="*-Info.plist" mode="merge" target="NSMicrophoneUsageDescription">
<string>My awesome app wish to hear your awesome voice through Microphone. Not for fancy stuff, just want to hear you.</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="---Key configuration---">
<string>---string value---</string>
</edit-config>
</platform>
After that, don't forget to rebuild your staging file by running this two command in your terminal :
cordova platform rm ios
cordova platform add ios
To confirm the change, you can check the newly generated .plist file by opening them with xCode.
-Info.plist file located at :
./platform/ios/[your app name]/[your app name]-Info.plist
you just need following steps 1.
Go to Project navigator Select the target Click on info from tab option other option are build setting build phase you will see key type value When you point on any key name you will find + and - sign click on the + sign write
Key: GDLibraryMode
in key sectionType:String
in tyoe sectionValue:GDEnterpriseSimulation
in value section
참고URL : https://stackoverflow.com/questions/22769111/add-entry-to-ios-plist-file-via-cordova-config-xml
'IT TIP' 카테고리의 다른 글
터미널에서 Python 스크립트를 실행하는 방법 (0) | 2020.10.16 |
---|---|
AngularJS로 옵션 선택에서 빈 옵션 제거 (0) | 2020.10.15 |
필터를 다른 작업으로 리디렉션하는 방법은 무엇입니까? (0) | 2020.10.15 |
Vim 삽입 모드에서 파일 경로 자동 완성을 추가하는 방법이 있습니까? (0) | 2020.10.15 |
Spring MVC 뷰 레이어를위한 JSP의 대안 (0) | 2020.10.15 |