Check for availability of blocks at runtime on iOS - objective-c

I need to test for the availability of blocks at runtime, so I can handle backwards compatibility with iOS 3. Any tips?
edit:
So far I'm doing if (!NSClassFromString(#"NSBlockOperation")) {...}
Seems to be working...

You will also need to make sure to weak link the libSystem.B.dylib, set your base SDK to 4.0 and deployment target to 3.1.3, as described here.
A good overview on how to deal with iOS versioning issues can also be found in this this Cocoa with Love article: Tips & Tricks for conditional iOS3, iOS3.2 and iOS4 code

Related

ObjC, Swift to WinObjC

I have an iOS app which includes both objective c and swift. Does the winobjc tool support converting the iOS apps which includes both objective c and swift code?
I work on the Windows Bridge for iOS at Microsoft. We're getting more and more questions about Swift support and it's clearly a top priority for the community. Now that Apple has open sourced large parts of Swift, we're considering our options and the technical implications of implementing it.
We regularly update our roadmap on our project wiki with our plans for the next month or two, so there is the best place to check for near-term plans. If you try out the bridge and have any questions, please don't hesitate to get in touch by filing an issue on Github. Thanks for checking out the bridge!
No, WinObjC only supports Objective-C but no Swift at this point.
It also doesn’t seem to be on their roadmap at this point.

How do you get the 'use automatic reference counting' checkbox to show when starting a new mac application in xcode?

I just started learning about mac application development by doing this tutorial https://developer.apple.com/librarY/mac/referencelibrary/GettingStarted/RoadMapOSX/books/RM_YourFirstApp_Mac/Articles/GettingStarted.html
I feel dumb because I am stuck on the very first step. It says to make sure that the "use automatic reference counting" checkbox is checked, but I don't even have that checkbox.
This is a screenshot from the tutorial:
and this is a screenshot from my laptop while following along with the tutorial:
Since I am not even yet sure what automatic reference counting is I feel stuck because I don't know if it is important or not. Does anyone know why this option is not shown in my xcode?
The quick version: automatic reference counting is now the default, so just go to the next step.
The longer version: That tutorial appears to be written using Xcode 4.4 in the examples. The current version of Xcode is 5.1, and Apple has made a bunch of changes between then and now, some cosmetic and some more substantial.
One of those changes is that automatic reference counting (ARC) is now the default choice for new projects. ARC is a method of memory management where the compiler and runtime work together to keep track of which objects are still in use, and release the ones which aren't. When this technology was first introduced, it had some rough spots, and so it made sense to make it optional.
Apple is really pushing everyone to use ARC for all projects, so they removed the checkbox in the create project dialog. I'm not sure when this happened; may have been Xcode 5.0 or 5.1.
All that said: the tutorial you're using was written for an earlier version of Xcode than you're using. The big concepts are all going to still apply, but you'll run into issues from time to time where the screenshots don't look the same or the options are slightly different. So take a deep breath and just go for it. :)

Discover calls to methods not available in earlier iOS versions

I am building my app using iOS 5.0 as base SDK and iOS 3.0 as deployment target.
I know I need to check for existence of methods and classes when I work with features that are not available in the earlier iOS versions, but lately I've lost a few hours on a problem just to discover I was calling a method not available in some iOS versions. I simply did not notice it was a new method and did no check before to call it. The app of course compiled with 0 errors and 0 warnings.
This is a big problem because if I forgot some other check somewhere in the app, I will not know it until I or, worst, some user will activate that specific part of code.
Maybe I am missing something, is there some compiler option I can set to detect the calls I make to methods not available in the iOS deployment target? How do you deal with such a problem?
This link might point you in the right direction. Supporting mutiple ios Versions in your apps. It explains how to deal with taking advantage of the newer ios features while maintaining backwards compatibility. Hope that helps.
The only way to check for compatibility with a prior version of iOS, currently, it to test the app on an old non-updated device running that version of the OS.
If you can't find a device that old, even just to borrow for short time, then there may not be a good buiness reason to set the Deployment target that low.

making app compatible with previous iOS versions

I just released my app but I am only able to make it compatible from 4.3 and up.
When I try to go any lower than 4.3 (xcode), it says I need to add code to make this work.
Does anyone know how to do this or has any suggestions? I would like my app to be compatible with 3.0 and onwards.
Thank you very much
You have to reach the least common code, what I mean by this is that you must find all the methods that are all incompatible within all of these versions of the OS. After that you will have to find each and every of it's functional equivalents. Then you can use conditional statements to check for every version and see what fits better or you can use the respondsToSelector method inherited from the NSObject class. In the end you have to test it on each device you are targeting :P
You can run this checkup list that I have always liked.
Edit:
I think I misunderstood your question though it has already been mentioned, be sure to check your deployment target in your build settings.
Checklist:
In your project's build settings…
Did you set the "iOS Deployment Target" to iOS 3?
Did you include the armv6 architecture in both, the built and the valid architectures?
In general:
Do you link to any framework that is not supported on iOS 3?
Do you use any methods, classes or other features that have been added later?

Android and Objective-C

I'm completing a project for the iPhone entirely written in Objective-C. I'd like to port this for Android too.
While the user interface of the iPhone and the Android OS are very different and will need different code, can I some how import the core of my code (ie. the black box that does the thinking) as is to Android as part of some Java code?
I have no familiarity with bridging between Objective-C and Java even though I have written in both.
You got luck! Phil Hassey has recently ported his own game from iPhone to Android within a week and wrote up what he did steps by steps. Here is his journey: http://www.philhassey.com/blog/2010/08/03/porting-galcon-using-the-android-ndk/
You could have a look at Apportable which allows to generate an Android app from an existing Objective-C code base. See this article too.
there is a fork of the gcc that supports objective-c on the android by patching the NDK on
http://code.google.com/p/android-gcc-objc2-0/. But it's considered beta at the moment and i'm not sure if jni/java bridges are already implemented
I have been doing a lot of work on this front — for example by creating my own C++ base framework that does not depend on STL (called Platform Core) and writing the core of the next version of my iOS app with that, so that I can easily port it to Android and whatever else has a C++ compiler and strikes my fancy.
I suggest having a (ick, I can't believe I'm about to say this, but eh), ahem, having a C++ core (there, I said it!) so it can be easily ported.