xcode 混淆如何使 osx 应用程序向后兼容以及如何测试它们
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15091105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
confusion of how to make osx app backward compatible & how to test them
提问by Josh
after reading the apple SDK guide https://developer.apple.com/library/mac/#documentation/developertools/conceptual/cross_development/Overview/overview.html
I'm still confused of how to make the mac app backward compatible & how to test them properly
我仍然对如何使 mac 应用程序向后兼容以及如何正确测试它们感到困惑
I have an app, I run it and tested it on Mountain Lion 10.8 without any problem, however I want to make this app backward compatible so that other users can run it on a mac 10.6 - 10.7 machine.
我有一个应用程序,我在 Mountain Lion 10.8 上运行并测试它没有任何问题,但是我想让这个应用程序向后兼容,以便其他用户可以在 mac 10.6 - 10.7 机器上运行它。
I have an apple developer id and I can download the old versions of 10.7 and 10.6, but the problem is, I have a 2011 macbook air which is currently running 10.8, and that's the only apple machine that I have. Can I test the 10.7 and 10.6 by using vmware or parallels?
in my project settings, I set the target deployment to 10.6 (as I want 10.6 users to run my app), but should I set my SDK to 10.8 or 10.7? if I set the SDK to 10.8 but having the target deployment set to 10.6, if I fix all the xcode warnings will it run successfully on 10.6??
from the SDK drop down, I can only set to 10.8 or 10.7, but 10.6 is missing, how do I fix that?
我有一个苹果开发者 ID,我可以下载 10.7 和 10.6 的旧版本,但问题是,我有一台 2011 年的 macbook air,目前运行的是 10.8,这是我唯一的苹果机器。我可以使用 vmware 或 parallels 测试 10.7 和 10.6 吗?
在我的项目设置中,我将目标部署设置为 10.6(因为我希望 10.6 个用户运行我的应用程序),但是我应该将我的 SDK 设置为 10.8 还是 10.7?如果我将 SDK 设置为 10.8 但将目标部署设置为 10.6,如果我修复了所有 xcode 警告,它会在 10.6 上成功运行吗??
从 SDK 下拉菜单中,我只能设置为 10.8 或 10.7,但缺少 10.6,我该如何解决?
thanks in advance
提前致谢
回答by Rob Napier
I develop on a 10.8 box and support back to 10.5. Just a couple of months ago we dropped 10.4 PPC support, and I'm still cleaning out some of the 10.2-specific code. This may get a little rant-y, but I've been doing old versions for a long time. I have some opinions on the matter.
我在 10.8 的盒子上开发并支持回到 10.5。就在几个月前,我们放弃了 10.4 PPC 支持,我仍在清理一些 10.2 特定的代码。这可能会有点咆哮,但我一直在做旧版本很长一段时间。我对此事有一些看法。
- No matter what Apple says in their docs, if you want to support 10.6, then build with the 10.6 SDK. Do not rely on distribution target.
- I have had this discussion with the Xcode engineers, and while they hold to Apple's party line that you should always build with the latest SDK, they also acknowledge that it's generally insane to do so. If you build against the 10.8 SDK and mark your deployment target at 10.6, you will get no warnings for using methods that do not existon 10.6. The only way you will discover that you've used a nonexistent method is that it might give you strange bugs when run on 10.6. That's insane.
- Remember, OS X doesn't crash when you send an unknown selector. It just aborts the current runloop. So the bugs are even harderto track down then on iOS, where it crashes the app.
- Sure, you can do weak linking. Talk about dangerous.... Yes, there are a few times this is useful, but the compiler gives you no warning if you don't do it correctly. If I'm going to do weak linking like this, I go the other way, linking against the old SDK and copying the new function's prototype into my implementation. That way I have documentation of every function I think I'm going to weak-link.
- Download the old SDKs and symlink them into your Xcode distribution.
- Guard them jealously. Apple will try to delete them every time you upgrade Xcode. Make your own copies and stick them in /SDKs or somewhere else away from Xcode. I provide a script called fix-xcodeto manage the symlinks automatically. Am I bitter at Apple for their relentless insistance on deleting my old SDKs? Yes, I am.
- You can run 10.6 Server in a VM legally. You can run 10.7+ Desktop in a VM legally. These are good ways to test your code.
- Or you can do what I do and have a small pile of old MacBooks each with two or three partitions on them that you reboot all the time.
- Now that 10.7 comes from App Store, it's a little harder to make VMs. My strong recommendation is to snapshot your image immediately after install, and make a clean backup copy of it. You'll want to be able to clone that image from time to time when you need to get back to a "raw" machine.
- Get in the habit of squirreling away SDKs as they come out. 10.8 will be old some day. You might as well make a copy now while it's easy.
- Whether you support individual dot-releases or not, it can be very helpful to keep around the upgrade packages for individual dot releases. When you encounter customers running non-current releases, it's nice to be able to check whether an "unreproducible" bug in fact is easily reproducible on their specific version. Whether this is worth it or not depends heavily on your product and customers. It was a life-saver for me when 10.4.11 made major changes to WebKit during a dot release...
- Invest in a small NAS or a big external USB drive (though I've had trouble with those failing when used extensively, so I prefer a RAID). You'll need the space. You want to hold onto lots of VMs and lots of SDKs and sometimes even old versions of Xcode.
- 不管 Apple 在他们的文档中怎么说,如果你想支持 10.6,那就用 10.6 SDK 构建。不要依赖分发目标。
- 我与 Xcode 工程师进行了讨论,虽然他们坚持 Apple 的党派路线,即您应该始终使用最新的 SDK 进行构建,但他们也承认这样做通常是疯狂的。如果您针对 10.8 SDK 进行构建并将您的部署目标标记为 10.6,您将不会收到使用10.6 上不存在的方法的警告。你会发现你使用了一个不存在的方法的唯一方法是它在 10.6 上运行时可能会给你带来奇怪的错误。那太疯狂了。
- 请记住,当您发送未知选择器时,OS X 不会崩溃。它只是中止当前的 runloop。因此,这些错误在 iOS 上更难追踪,因为它会导致应用程序崩溃。
- 当然,你可以做弱链接。谈论危险.... 是的,有几次这很有用,但是如果您没有正确执行,编译器不会给您警告。如果我要像这样进行弱链接,我会走另一条路,链接旧的 SDK 并将新函数的原型复制到我的实现中。这样我就有了我认为我将要进行弱链接的每个功能的文档。
- 下载旧的 SDK 并将它们符号链接到您的 Xcode 发行版中。
- 嫉妒地保护他们。每次升级 Xcode 时,Apple 都会尝试删除它们。制作您自己的副本并将它们粘贴在 /SDKs 或远离 Xcode 的其他地方。我提供了一个名为fix-xcode的脚本来自动管理符号链接。我对 Apple 无情地坚持删除我的旧 SDK 感到不满吗?我是。
- 您可以合法地在 VM 中运行 10.6 Server。您可以合法地在 VM 中运行 10.7+ 桌面。这些是测试代码的好方法。
- 或者你可以按照我的方法做,放一小堆旧的 MacBook,每台都有两到三个分区,你一直在重启。
- 现在 10.7 来自 App Store,制作 VM 有点困难。我强烈建议您在安装后立即对您的映像进行快照,并为其制作干净的备份副本。当您需要返回到“原始”机器时,您将希望能够不时克隆该映像。
- 养成在 SDK 出来时把它们收起来的习惯。10.8 总有一天会老的。您不妨现在就制作一份副本,这很容易。
- 无论您是否支持单个 dot 版本,保留单个 dot 版本的升级包都非常有帮助。当您遇到运行非当前版本的客户时,很高兴能够检查“不可重现”的错误实际上是否可以在他们的特定版本上轻松重现。这是否值得在很大程度上取决于您的产品和客户。当 10.4.11 在 dot 版本期间对 WebKit 进行重大更改时,这对我来说是一个救命稻草......
- 投资一个小型 NAS 或一个大型外部 USB 驱动器(尽管我在广泛使用时遇到了那些失败的问题,所以我更喜欢 RAID)。你需要空间。您想要保留大量 VM 和大量 SDK,有时甚至是旧版本的 Xcode。
回答by Jakob
Adding to Rob Napier's great in-depth answer:
添加到 Rob Napier 的深入回答中:
To use an old SDK, put the SDK (or a symlink) to it here:
要使用旧的 SDK,请将 SDK(或符号链接)放在此处:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
With XCode 7.3 or later, you need you to open this file and change "MinimumSDKVersion" (otherwise XCode will refuse to use the old SDK):
使用 XCode 7.3 或更高版本,您需要打开此文件并更改“MinimumSDKVersion”(否则 XCode 将拒绝使用旧 SDK):
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Info.plist
回答by trojanfoe
- You can install multiple versions of Mac OS on a single machine, booting between each.
- The SDK should be the latest (10.8).
- See 2.
- 您可以在一台机器上安装多个版本的 Mac OS,并在每个版本之间启动。
- SDK 应该是最新的 (10.8)。
- 见 2。
One alternative to 1 that I've considered (I am in the same boat) is to create a Snow Leopard Hackintosh using an old PC and just installing Lion and Mountain Lion on my MBP.
我考虑过的 1 的替代方案(我在同一条船上)是使用旧 PC 创建雪豹 Hackintosh,并在我的 MBP 上安装 Lion 和 Mountain Lion。
回答by Anoop Vaidya
You need to do these settings :
你需要做这些设置:
1.Set the Base SDK to Current version of Mac (ex. 10.7)
1.将基础 SDK 设置为当前版本的 Mac(例如 10.7)
2.Set the Deployment SDK to older version (ex.1.4)
2.将部署SDK设置为旧版本(例如1.4)