菜鸟教程小白 发表于 2022-12-13 15:55:06

ios - 我可以在 info.plist 中定义用户定义的 key 吗


                                            <p><p>我可以用给定名称“SomeKey”定义一个用户定义的键,我可以使用 <code>[ objectForInfoDictionaryKey:@"SomeKey"]</code></p> 访问</p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>当然! </p>

<p><strong>Apple 文档</strong>:</p>

<blockquote>
<p><strong>Custom Keys</strong></p>

<p>iOS and macOS ignore custom keys you include in an Info.plist file. If
you want to include app-specific configuration information in your
Info.plist file, you can do so freely as long as your key names do not
conflict with the ones Apple uses. When defining custom key names,
prefix them with a unique prefix, such as your app’s bundle ID or your
company’s domain name, to prevent conflicts.</p>
</blockquote>

<p>您可以通过执行以下操作来获得值(value):</p>

<p><strong>Objective-C</strong></p>

<pre><code>[.infoDictionary objectForKey:@&#34;SomeKey&#34;];
</code></pre>

<p>或</p>

<pre><code>[ objectForInfoDictionaryKey:@&#34;SomeKey&#34;];
</code></pre>

<p><strong> swift </strong></p>

<pre><code>Bundle.main.infoDictionary?[&#34;SomeKey&#34;]
</code></pre>

<p><strong>引用:</strong></p>

<p> <a href="https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html#//apple_ref/doc/uid/TP40009254-SW1" rel="noreferrer noopener nofollow">Info Plist Docs</a> </p>

<p> <a href="https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html#//apple_ref/doc/uid/TP40009254-SW10" rel="noreferrer noopener nofollow">Reserved Keys</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 我可以在 info.plist 中定义用户定义的 key 吗,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/48819534/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/48819534/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 我可以在 info.plist 中定义用户定义的 key 吗