如何自定义和测试MacOS .app包的可执行路径,主图标和i18n

问题描述 投票:1回答:1

我有一个MacOS应用程序捆绑裸机工作。也就是说,它运行可执行文件,就是这样。即使我有一个我在Finder中可以直观看到的MyApp.icns文件,图标仍然无法正常工作。并且i18n无法正常工作。

MyApp.app/
  Contents/
    Info.plist
    MacOS/
      MyApp # executable
    Resources/
      MyApp.icns
      en.lproj
        InfoPlist.strings
      jp.lproj
        InfoPlist.strings

我从.icns生成的here

mkdir MyIcon.iconset
sips -z 16 16     foo.png --out MyIcon.iconset/icon_16x16.png
sips -z 32 32     foo.png --out MyIcon.iconset/[email protected]
sips -z 32 32     foo.png --out MyIcon.iconset/icon_32x32.png
sips -z 64 64     foo.png --out MyIcon.iconset/[email protected]
sips -z 128 128   foo.png --out MyIcon.iconset/icon_128x128.png
sips -z 256 256   foo.png --out MyIcon.iconset/[email protected]
sips -z 256 256   foo.png --out MyIcon.iconset/icon_256x256.png
sips -z 512 512   foo.png --out MyIcon.iconset/[email protected]
sips -z 512 512   foo.png --out MyIcon.iconset/icon_512x512.png
cp Icon1024.png MyIcon.iconset/[email protected]
iconutil -c icns MyIcon.iconset
rm -R MyIcon.iconset

我的Info.plist是这样的:

<?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>CFBundleDevelopmentRegion</key>
  <string>en</string>

  <key>CFBundleName</key>
  <string>MyApp</string>

  <key>CFBundleDisplayName</key>
  <string>MyApp</string>

  <key>CFBundleIdentifier</key>
  <string>MyApp</string>

  <key>CFBundleVersion</key>
  <string>1.0.0</string>

  <key>CFBundleVersion</key>
  <string>APPL</string>

  <key>CFBundleSignature</key>
  <string>MyApp</string>

  <key>CFBundleExecutable</key>
  <string>this/has/no/effect</string>

  <key>CFBundleIconFile</key>
  <string>NeitherDoesThis</string>
</dict>

每种语言的InfoPlist.strings如下所示:

CFBundleDisplayName = "Foo";
NSHumanReadableCopyright = "Copyright © 2019 Me.";

要么:

CFBundleDisplayName = "ふ";
NSHumanReadableCopyright = "著作権法 © 2019 目.";

我遇到的问题是:

  • 我无法指定可执行路径,它只有在命名与MyApp.app相同时才有效,所以MyApp可执行文件。
  • 图标MyApp.icns没有在/ Applications文件夹中呈现(这是我到目前为止唯一放置它的地方)。我不确定我是否可以自定义该路径。
  • 我不知道如何测试i18n的工作原理。

想知道是否可以验证这些东西,并展示如何测试其他东西。特别:

  1. 确认您无法实际自定义可执行文件的路径,它必须与MacOS文件夹中的应用程序命名相同。
  2. 确认您必须将图标命名为与应用程序相同的名称,扩展名为.icns。我不确定这是否属实,因为例如Skypes的主要Icon位于Resources / Skype Blue.icns位置,他们在Info.plist中说Skype Blue。想知道为什么我不能让这个工作。
  3. 如何测试i18n的工作原理。想知道我是否只是change the Mac system language并再次打开应用程序等

这都不使用XCode。

macos plist bundle
1个回答
2
投票

Info.plist缺失/不正确的键/字符串可以影响前两个问题;如果密钥重复,丢失或设置不正确,它肯定会导致功能问题。

  1. 失踪 NSPrincipalClass CFBundleInfoDictionaryVersion CFBundleSupportedPlatforms CFBundlePackageType CFBundleExecutable(这是MacOS文件夹中的二进制文件) CFBundleLocalizations(可选) DTXcode(可选) DTPlatform(可选) DTSDK(可选) DTCompiler(可选)
  2. 不正确 CFBundleIdentifier(应采用反向DNS格式) CFBundleVersion(重复/不正确) CFBundleSignature(不正确)

注意:只要您添加并设置了密钥MyApp.app,应用程序名称MacOS就不需要与CFBundleExecutable文件夹中的可执行文件相同。应用程序图标也可以是您想要的任何名称,使其工作的关键是通过包含上面显示的其他CoreFoundation键正确设置。

一旦你将所有缺失/不正确的密钥排序,你应该得到类似于:

<?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>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleExecutable</key>
    <string>MyApp</string>
    <key>CFBundleIconFile</key>
    <string>MyIcon</string>
    <key>CFBundleIdentifier</key>
    <string>com.company.MyApp</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>MyApp</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSupportedPlatforms</key>
    <array>
        <string>MacOSX</string>
    </array>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>DTCompiler</key>
    <string>com.apple.compilers.llvm.clang.1_0</string>
    <key>DTPlatformBuild</key>
    <string>10B61</string>
    <key>DTPlatformVersion</key>
    <string>GM</string>
    <key>DTSDKBuild</key>
    <string>18B71</string>
    <key>DTSDKName</key>
    <string>macosx10.14</string>
    <key>DTXcode</key>
    <string>1010</string>
    <key>DTXcodeBuild</key>
    <string>10B61</string>
    <key>LSMinimumSystemVersion</key>
    <string>10.13</string>
    <key>NSHumanReadableCopyright</key>
    <string>Copyright © 2019 MyApp. All rights reserved.</string>
    <key>NSMainNibFile</key>
    <string>MainMenu</string>
    <key>NSPrincipalClass</key>
    <string>NSApplication</string>
</dict>
</plist>

*上面的Info.plist应该适用于您的应用,因为值设置为您在问题中显示的值。


关于i18n测试 - Internationalization and Localization Guide部分Testing Your Internationalized AppManaging Strings Files Yourself应该是有帮助的。指南中有大量信息;一种尺寸适合所有测试方法通常都不会这样做,你会想找到最适合你的方法。

Information Property List Key ReferenceAbout Internationalization and Localization

© www.soinside.com 2019 - 2024. All rights reserved.