How do you debug an app for an older version of Mac OS X?

匆匆过客 提交于 2019-12-06 06:08:25

问题


I am developing an app using Xcode 4.6 on an OS X 10.8 machine. The app deployment target is set to 10.6, which is what we need to support. But when I archive the app (compile, link and embed resources+frameworks) and deploy (aka copy) it to the 10.6 test machine, it crashes with a generic Segmentation fault. It works fine on 10.7.

I can't compile the project in Xcode on the older Mac because the app is built using the newer compiler (it uses ARC, implicit property synthesis, the new objective-c literal syntax, etc.). It also wouldn't type check because the base SDK is 10.8 and it references some 10.8 tokens which the compiler on the 10.6 machine doesn't know about.

Any suggestions on how to go about debugging the app?


回答1:


I'm not affiliated with this company/software in any way, but Deploymate is a paid app which can scan your app for SDK usage and tell you when you are calling selectors and APIs that are unavailable on older OS versions. This can help you track down exceptions and crashes relating to API usage.




回答2:


You are very likely using one or more 10.7+ APIs that crash on 10.6. With a 10.8 target SDK you allow all the calls to function that are available in that SDK. However apps are bound late so this doesn't crash when you do not actually call those functions. You need an explicit check similar to this (here for the full screen feature):

#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6
if (runningOnLionOrLater) {
    [mainWindow setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
    [toggleFullscreenItem setHidden: NO];
}
#endif

One way to determine the current version is:

    int macVersion;
    if (Gestalt(gestaltSystemVersion, &macVersion) == noErr) {
        runningOnLionOrLater = macVersion > MAC_OS_X_VERSION_10_6;
    }

For debugging the problematic calls simply set the base SDK to 10.6 and XCode should mark those functions that are not available there.




回答3:


While there is no real good solution to this (I've seen simply different behaviors on different macOS versions) and no way to simply simulate an older macOS version, if you have a machine to spare:

It is possible to use an external HD, partition it and install different macOS versions. They all can be bootable and it's a matter (pain) of restarting the machine for every OS version.



来源:https://stackoverflow.com/questions/15882296/how-do-you-debug-an-app-for-an-older-version-of-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!