Compiling App for older OS X versions - xcode

I recently submitted (my first) app to the AppStore. It works on OS X 10.8 and uses some of the 10.8 features like ShareKit. I wanted to support OS X 10.7 also, to make it available for 10.7 users. Of course, this would mean that the 10.7 version will not have the ShareKit features. But I'm not sure what compile settings to use to make it available for both, so that 10.8 users will be able to make use of the features and 10.7 users will not see them.
I tried changing the Base SDK to 10.7, but it won't compile on that.
I tried changing the deployment target to 10.7 keeping the Base SDK 10.8. It compiled, but I'm not sure if that is the right thing to do. Don't have a 10.7 machine to test it, either.
If case 2 is correct, how do I check the in the code and make the menu items disabled?

number 2 is the correct thing to do, but being able change sdk to 10.7 is very nice, because in general if it won't compile because a class or method is missing it won't run.
you will need to re-write code to dynamically detect if things are available for use...
Class Some108Class = NSClassFromString(#"The10_8Class"); //will be Nil in 10.7
or
[var respondsToSelector:#selector(someMethod)]; // returns no if someMethod isn't available
[SomeClass instancesRespondToSelector:#selector(someMethod)];//same

Related

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

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?
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.
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.
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.

How do I add Leopard and Snow Leopard support to a Lion Cocoa App?

I have developed a Cocoa App on Lion and now I would like to add compatibility with Leopard and Snow Leopard.
I tried to set the development target to 10.5 but it still has crash problems on Leopard and Snow Leopard.
I tried also to open the project with old versions of Xcode, but I get hundreds of compile errors (I guess it's because I can't compile the program with the old Mac OS SDK)
Do you have any advice about solving the retro-compatibility problems of Cocoa Apps?
I think it's generally not a very good idea to develop for the latest OS then try to support older OSes at the last minute. If you've used any APIs that were introduced in an OS later than the oldest you're trying to support, you'll have to rewrite code to avoid using those APIs. It's generally not worth the trouble.
That said, there's no secret to supporting older OSes. You just need to make sure that you only use APIs (classes, methods, functions) that are available on the oldest OS you're trying to support. You'll notice when looking at the documentation that for each method, under "Availability", it will tell you which versions of the OS include that method. Something like:
Availability
Available in Mac OS X v10.6 and later.
Assuming you don't use any APIs not available on an OS version you're targeting, all you need to do is set the deployment target to the lowest OS you're targeting, and build. You will of course also want to test thoroughly on each OS version you're supporting.
Your question would be easier to answer in more detail if you elaborated on the "crash problems" you're seeing on Leopard and Snow Leopard.
First, install the 10.5 SDK on your Mac. This may not be necessary, but do it anyway. You can find instructions on the Internet. Keep in mind that compiling with the 10.5 SDK will ensure compatibility, but you won't be able to use newer OS X features unless you load them dynamically.
Second, go into your .xib files and on the File Properties tab (first notch in the Inspector pane) disable auto layout and set the deployment target to 10.5.

NSWindowController window?

I have a menu-bar based application, which displays a window, when the icon is clicked.
It all works fine on Mac OS X Lion, but for some reason, an error occurs on Snow Leopard an sooner versions of Mac OS X. Anytime [TheWindowController window] is called the method stops, but the app keeps running. Because of this, I don't think that the window is just nil, it's corrupt, in some way.
I have no Idea why this happens, and like I said, it only happens in Mac OS X Snow Leopard.
Btw. I use ARC, if that matters at all.
You're loading a NIB that uses a 10.7-specific feature, Cocoa Autolayout, on 10.6, which doesn't understand it. If you wish to support running on 10.6, you need to avoid using such features. You should be able to set the deployment target on the NIB, which will then cause warnings to show up for features which aren't supported by that deployment target.
Also, if you haven't already done so, you need to do something similar for your target's build settings. Set the deployment target. Unfortunately, that won't necessarily cause warnings for code which uses features that were introduced in 10.7. You can set up an alternative build configuration which builds against the 10.6 SDK and compile against that to learn where you're using post-10.6 features. See Apple's SDK Compatibility Guide for more info.

XCode Mac OS X compatibility setting

I just created a small program in XCode 4 for Mac OS X. I want it to run on 10.4, 10.5 and 10.6. How can I do that? I am currently running Snow Leopard. In XCode 4, if I click my project, there's a settings for deployment Target, which is a drop down list and I can only select 1 of : 10.4, 10.5 or 10.6. How can I make sure it is compatible with all of them? Thanks.
The deployment target is the minimum version you want to be compatible with. Set it to 10.4.
Since you have to use the 10.6 SDK with Xcode 4, you’re responsible for making sure you don’t use any APIs that aren’t available in 10.4 without testing for them first. You also can’t build PowerPC-compatible apps with Xcode 4.
build with 10.4
You will also want to build it in 10.6 also to make sure that you aren't using anything that has or will become deprecated... warnings will be thing that will become deprecated, errors will already be deprecated, you may have to do some conditional compilation. to keep things straight.
#if MAC_OS_X_VERSION_MIN_REQUIRED == MAC_OS_X_VERSION_10_4
//do something using 10.4 code
#elsif MAC_OS_X_VERSION_MIN_REQUIRED == MAC_OS_X_VERSION_10_5
//do something using 10.5 code
#else
//do something using 10.6+ code
#endif

Xcode built app on 10.6 wont run on 10.5.8

I am new here and new in Xcode world.
I made a simple app with Xcode 3.2 on Snow Leopard.
The resulting built app works on snow leopard, however it will not even start on leopard (10.5.8) - I get message "You cannot use this version of application with this version of Mac OS X". Is it normal?
Or is there a way to make app that will work both on Snow Leopard and Leopard? Please advise, as I have no way to find out myself
Thanks for any input
You need to change the deployment target in your Build Settings. You should set it to the lowest version of OS X that you're willing to provide support for. You should set your base SDK to the latest available public SDK.
If you do this, you must ensure that you only use new 10.6-only APIs after doing runtime checks for their existence. To do this, you can use functions like NSClassFromString and respondsToSelector:.
Any Frameworks or libraries that are new to 10.6 should be weak-linked. This will prevent the app from trying to load those frameworks on 10.5 and thus cause the program to crash when it doesn't find the frameworks.
All explained in the SDK Compatibility Guide from Apple (Requires (free) login).

Resources