You should be weak linking against the new frameworks. Alongside that you should be checking the availability of new APIs using methods like NSClassFromString
, respondsToSelector
, instancesRespondToSelector
etc.
Eg. Weak linking against MessageUI.framework (an old example, but still relevant)
First check if the MFMailComposerController
class exists:
Class mailComposerClass = NSClassFromString(@"MFMailComposerController");
if (mailComposerClass != nil)
{
// class exists, you can use it
}
else
{
// class doesn't exist, work around for older OS
}
If you need to use new constants, types or functions, you can do something like:
if (&UIApplicationWillEnterBackgroundNotification != nil)
{
// go ahead and use it
}
If you need to know if you can use anew methods on an already existing class, you can do:
if ([existingInstance respondsToSelector:@selector(someSelector)])
{
// method exists
}
And so on. Hope this helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…