Codename One:如何在构建提示中添加换行符?
Got it, let's break this down—getting that multi-line location usage description into your info.plist via ios.plistInject while preserving those critical line breaks is totally manageable, but you need to handle the newline characters the right way.
The Core Issue
If you try to write a multi-line string directly in your plistInject command or config, most shells or parsers will treat the line break as the end of the value, not part of the actual string content. So you need to explicitly escape the newline using \n instead of hitting enter.
Method 1: Direct Command Line Injection
If you're running ios.plistInject straight from the terminal, pass the multi-line string with \n as the newline marker. Here's the exact command you'll need:
ios.plistInject -i info.plist -o modified_info.plist -k NSLocationWhenInUseUsageDescription -v "第一行\n第二行"
When this runs, plistInject will convert the \n into an actual line break in the resulting info.plist, giving you exactly the XML snippet you want.
Method 2: Using a JSON Config File
For repeatable builds, using a JSON config file is a cleaner approach. Define the value with \n to represent the line break:
{ "inject": [ { "key": "NSLocationWhenInUseUsageDescription", "value": "第一行\n第二行" } ] }
Then run the tool with your config file:
ios.plistInject -i info.plist -o modified_info.plist -c your_config.json
Method 3: Xcode Build Phase Integration
If you're adding this to an Xcode Run Script build phase, wrap the value in single quotes to prevent the shell from interpreting the \n early:
ios.plistInject -i "${INFOPLIST_FILE}" -o "${INFOPLIST_FILE}" -k NSLocationWhenInUseUsageDescription -v '第一行\n第二行'
This ensures the \n gets passed through to plistInject correctly, which then converts it to a real line break in the final plist.
Verify the Result
After running the injection, open your modified info.plist to confirm it matches exactly what you wanted:
<key>NSLocationWhenInUseUsageDescription</key> <string>第一行 第二行</string>
That's all there is to it! The key trick is using \n to represent the line break in your input to plistInject, rather than trying to write a literal multi-line string directly.
内容的提问来源于stack exchange,提问作者Osman

