Reputation: 1391
I have built an iPhone app with SDK 4.2 however I know also want to make it compatible with iOS 3.1.3.
First step was to set the Deployment Target to 3.1.3. It runs fine on the 3.2 Simulator but the app crashes at times since I'm using some methods which are not available in this early SDK.
So my qestion is, is there a straight forward way to locate the offending methods/classes I'm using in my project which are not available in 3.1.3 ? (without manually going through each method call and consult with the docs for the SDK availability?)
Thanks.
UPDATE: I have executed the app on 3.1.3 and attempted to manually test each execution path with the hope of locating all exceptions. This was completed with some level of success. However, what if the application is huge? and there are lots of execution paths? There must be some tool for this scenario. Any thoughts are much appreciated.
Upvotes: 3
Views: 716
Reputation: 4963
I had the same problem and just found a solution.
You should add the following definitions at the beginning of your prefix header:
#import <Availability.h>
#define __AVAILABILITY_INTERNAL__IPHONE_3_2 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_0 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_1 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_2 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_3 __AVAILABILITY_INTERNAL_DEPRECATED
Then the next time you compile the app, the methods that are not available in old versions (in this case iOS 3.1) will be marked as deprecated and you will get warnings for each of them.
You can use __AVAILABILITY_INTERNAL_UNAVAILABLE
instead of __AVAILABILITY_INTERNAL_DEPRECATED
if you want to get errors.
These lines redefine the actual definitions in AvailabilityInternal.h so you should remove them from your prefix header when your are done.
Here is how it works:
Apple marks the availability of the methods in the header files with macros like __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0)
.
Since you are compiling for iOS the following definition in Availibility.h
is applied:
#define __OSX_AVAILABLE_STARTING(_mac, _iphone) __AVAILABILITY_INTERNAL##_iphone
So the methods are actually marked with __AVAILABILITY_INTERNAL__IPHONE_4_0
and similar macros. Normally when you are compiling with the new SDK these macros are replaced with __AVAILABILITY_INTERNAL_WEAK_IMPORT
, which does not produce any warning. By adding the lines at the beginning of my answer to your prefix header, you overwrite these definitions with __AVAILABILITY_INTERNAL_DEPRECATED
. Therefore Xcode thinks these methods are deprecated and produces the warnings.
Upvotes: 12