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.
Related
I have an application in the Mac App Store. I'm trying to support users going back to Snow Leopard but this is becoming increasingly difficult.
Recently I've hit a roadblock due to the iTunesLibrary.framework, this framework must be linked to the main executable and yet doing so will always trigger a crash on load when running in Snow Leopard.
To workaround this problem, I want to compile a version of my app that doesn't use features and frameworks from newer versions of OSX. The problem is, how can I launch the compatibility build automatically?
I'm considering trying to make the main executable point to a shell script, but I don't really like that idea. I've also thought of the main executable being a helper that simply launches the full app and then exits. I expect this would work, but I worry about it getting approved by Apple. Finally, I'm wondering if the app bundle format itself can support this kind of setup, maybe via an advanced used of CFBundleExecutable that I'm unaware of.
Has anyone been down this road, what would you suggest?
Try weak linking the frameworks, more information about Weak Linking and Apple Frameworks here. Then also check in your code for the OS version or - (BOOL)respondsToSelector:(SEL)aSelector of any NSObject to determine what you can call and what not.
To have Snow Leopard as Base SDK you'll need an old Xcode and will have troubles submitting to Mac App Store.
I have 10.9/Xcode 5 and I'm trying to write a Cocoa app for Snow Leopard. I deactivated auto layout and set the deployment target to 10.6, but the archived application won't launch on 10.6 because it can't load the nib (console output). From what I've read, I need to use garbage collection instead of ARC. If this is true, how to I modify my project to build and run for 10.6? Thanks for your advice.
First, make sure the XIB itself is configured to build for 10.6. In the right-hand pane of Interface Builder, you should see this:
If you're targeting 64-bit 10.6, then you can use ARCLite, which is just fine and I strongly recommend it. The only thing you really give up is auto-zeroing weak references. You only have to give up ARC if you go 32-bit. I recommend sicking to 64-bit if you can possibly help it. You give up a lot if you target 32-bit. To use ARCLite, you don't have to change anything. It's automatically selected when you compile an ARC program for 10.6.
As a note: yes, what you're doing is totally possible. I still target 10.5 with a 10.9/Xcode5 setup.
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
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.
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.