You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "shajz (via GitHub)" <gi...@apache.org> on 2024/04/09 10:07:30 UTC
[I] Issue with `` and `cordora prepare ios` [cordova-ios]
shajz opened a new issue, #1418:
URL: https://github.com/apache/cordova-ios/issues/1418
# Bug Report
## Problem
### What is expected to happen?
The `<privacy-manifest>` element must be included in the generated `PrivacyInfo.xcprivacy` file, and the order of its properties must be the same.
### What does actually happen?
When running `cordova prepare ios`, the order of properties is messed up and the mess is exported to the generated `PrivacyInfo.xcprivacy` file.
## Information
<!-- Include all relevant information that might help understand and reproduce the problem -->
`config.xml`, before running `cordova prepare ios`
```xml
<privacy-manifest>
<key>NSPrivacyTracking</key>
<true />
<key>NSPrivacyCollectedDataTypes</key>
<array />
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryDiskSpace</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>E174.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>3B52.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>35F9.1</string>
</array>
</dict>
</array>
<key>NSPrivacyTrackingDomains</key>
<array />
</privacy-manifest>
```
`config.xml`, after running `cordova prepare ios`
```xml
<privacy-manifest>
<key>NSPrivacyTracking</key>
<key>NSPrivacyCollectedDataTypes</key>
<key>NSPrivacyAccessedAPITypes</key>
<key>NSPrivacyTrackingDomains</key>
<true/>
<array/>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<key>NSPrivacyAccessedAPITypeReasons</key>
<string>NSPrivacyAccessedAPICategoryDiskSpace</string>
<array>
<string>E174.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<key>NSPrivacyAccessedAPITypeReasons</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<array>
<string>CA92.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<key>NSPrivacyAccessedAPITypeReasons</key>
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
<array>
<string>3B52.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<key>NSPrivacyAccessedAPITypeReasons</key>
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
<array>
<string>35F9.1</string>
</array>
</dict>
</array>
<array/>
</privacy-manifest>
```
This is then outputed to the `PrivacyInfo.xcprivacy` file :
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict><key>NSPrivacyTracking</key><key>NSPrivacyCollectedDataTypes</key><key>NSPrivacyAccessedAPITypes</key><key>NSPrivacyTrackingDomains</key><true /><array /><array><dict><key>NSPrivacyAccessedAPIType</key><key>NSPrivacyAccessedAPITypeReasons</key><string>NSPrivacyAccessedAPICategoryDiskSpace</string><array><string>E174.1</string></array></dict><dict><key>NSPrivacyAccessedAPIType</key><key>NSPrivacyAccessedAPITypeReasons</key><string>NSPrivacyAccessedAPICategoryUserDefaults</string><array><string>CA92.1</string></array></dict><dict><key>NSPrivacyAccessedAPIType</key><key>NSPrivacyAccessedAPITypeReasons</key><string>NSPrivacyAccessedAPICategoryFileTimestamp</string><array><string>3B52.1</string></array></dict><dict><key>NSPrivacyAccessedAPIType</key><key>NSPrivacyAccessedAPITypeReasons</key><string>NSPrivacyAccessedAPICategorySystemBootTime</string><array><string>35F9.1</string></array></dict></array><array /></dict></plist>
```
The correct output (that works well in XCode) is this one :
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict><key>NSPrivacyTracking</key><true /><key>NSPrivacyCollectedDataTypes</key><array /><key>NSPrivacyAccessedAPITypes</key><array><dict><key>NSPrivacyAccessedAPIType</key><string>NSPrivacyAccessedAPICategoryDiskSpace</string><key>NSPrivacyAccessedAPITypeReasons</key><array><string>E174.1</string></array></dict><dict><key>NSPrivacyAccessedAPIType</key><string>NSPrivacyAccessedAPICategoryUserDefaults</string><key>NSPrivacyAccessedAPITypeReasons</key><array><string>CA92.1</string></array></dict><dict><key>NSPrivacyAccessedAPIType</key><string>NSPrivacyAccessedAPICategoryFileTimestamp</string><key>NSPrivacyAccessedAPITypeReasons</key><array><string>3B52.1</string></array></dict><dict><key>NSPrivacyAccessedAPIType</key><string>NSPrivacyAccessedAPICategorySystemBootTime</string><key>NSPrivacyAccessedAPITypeReasons</key><array><string>35F9.1</string></array></dict></array><key>NSPrivacyTrackingDomains</key><array /></dict></plist>
```
### Command or Code
<!-- What command or code is needed to reproduce the problem? -->
`cordova prepare ios`
### Environment, Platform, Device
<!-- In what environment, on what platform or on which device are you experiencing the issue? -->
Mac OS 14.4.1
### Version information
<!--
What are relevant versions you are using?
For example:
Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins
Other Frameworks: Ionic Framework and CLI version
Operating System, Android Studio, Xcode etc.
-->
"cordova": "^12.0.0"
"cordova-ios": "^7.1.0"
## Checklist
<!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] Issue with `` and `cordora prepare ios` [cordova-ios]
Posted by "Yura13 (via GitHub)" <gi...@apache.org>.
Yura13 commented on issue #1418:
URL: https://github.com/apache/cordova-ios/issues/1418#issuecomment-2108073172
@shajz
I have the same problem. How do you resolve it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] Issue with `` and `cordora prepare ios` [cordova-ios]
Posted by "shajz (via GitHub)" <gi...@apache.org>.
shajz commented on issue #1418:
URL: https://github.com/apache/cordova-ios/issues/1418#issuecomment-2044677806
Oops, I forgot that my app edits the config.xml with a cordova hook and that's the source of my problem. Sorry for the spam
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] Issue with `` and `cordora prepare ios` [cordova-ios]
Posted by "shajz (via GitHub)" <gi...@apache.org>.
shajz closed issue #1418: Issue with `<privacy-manifest>` and `cordora prepare ios`
URL: https://github.com/apache/cordova-ios/issues/1418
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] Issue with `` and `cordora prepare ios` [cordova-ios]
Posted by "shajz (via GitHub)" <gi...@apache.org>.
shajz commented on issue #1418:
URL: https://github.com/apache/cordova-ios/issues/1418#issuecomment-2108621678
@Yura13 I was using xml2js https://www.npmjs.com/package/xml2js which doesn't preserve XML elements order. I switched to https://www.npmjs.com/package/fast-xml-parser.
Here's the code (quick and dirty js) :
```js
// Parse config.xml, edit app & package name and save the changes
import { XMLBuilder, XMLParser } from "fast-xml-parser";
import { readFile, writeFile } from 'fs';
const configFile = "config.xml";
const commonOptions = {
preserveOrder: true,
ignoreAttributes: false,
allowBooleanAttributes: true,
commentPropName: "#comment",
unpairedTags: [
'content',
'access',
'allow-navigation',
'preference',
'allow-intent',
'param',
'hook',
'application',
'custom-preference',
'resource-file',
'icon',
'splash',
'true',
],
}
const parser = new XMLParser({
...commonOptions,
ignoreDeclaration: false,
});
const builder = new XMLBuilder({
...commonOptions,
suppressUnpairedNode: false,
format: true,
});
export function updateConfigFile(overrides) {
readFile(configFile, "utf-8", (err, data) => {
if (err) {
throw err;
}
const result = parser.parse(data);
/** Overrides */
if (overrides?.['android-packageName']) {
result[1][':@']['@_android-packageName'] = overrides['android-packageName'];
}
if (overrides?.['ios-CFBundleIdentifier']) {
result[1][':@']['@_ios-CFBundleIdentifier'] = overrides['ios-CFBundleIdentifier'];
}
if (overrides?.name) {
result[1].widget = result[1].widget.map((obj) => ((obj?.name != null) ? {...obj, name: [ { '#text': overrides.name } ] } : obj));
}
const xml = builder.build(result);
// write updated XML string to a file
writeFile(configFile, xml, { encoding: "utf-8" }, (err) => {
if (err) {
throw err;
}
console.log(`Updated XML is written to a new file.`);
});
});
}
```
You can adapt the overrides part to your usecase, the syntax is weirder than `xml2js` but the order is preserved with the provided options :)
Saved this as a .mjs file so I could use `import` syntax safely but you can use `require` with .js files.
call it like this in your cordova hooks
```js
updateConfigFile({
'android-packageName': 'com.your.package',
'ios-CFBundleIdentifier': 'com.your.package',
name: 'Your app name',
});
```
Sorry I let this up without providing a solution https://xkcd.com/979/ 😅
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org