I am attempting to write an app for iOS that will take advantage of iOS 4.0 features, but also work on an earlier version of the OS (3.1.3). I have set the deployment target to 3.1.3 and the Base SDK to 4.3 (latest)
Specifically, I am trying to take advantage of the ability to intercept commands from the remote control.
The document linked below is very useful in explaining how to (at run-time) check for the presence of classes and methods, but I still get a compiler error when attempting to reference an enum from the UIEvent class which only appears in iOS 4.0 and later.
Here is the section of code which causes the compilation to fail:
- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
[self playPauseAction:nil];
break;
case UIEventSubtypeRemoteControlPreviousTrack:
[self previousChapter:nil];
break;
case UIEventSubtypeRemoteControlNextTrack:
[self nextChapter:nil];
break;
default:
break;
}
}
}
The compiler complains that:
error: 'UIEventTypeRemoteControl' undeclared (first use in this function)
UIEventTypeRemoteControl is an enum that isn't defined until 4.0 (from UIEvent.h)
typedef enum {
UIEventTypeTouches,
UIEventTypeMotion,
UIEventTypeRemoteControl,
} UIEventType;
typedef enum {
// available in iPhone OS 3.0
UIEventSubtypeNone = 0,
// for UIEventTypeMotion, available in iPhone OS 3.0
UIEventSubtypeMotionShake = 1,
// for UIEventTypeRemoteControl, available in iOS 4.0
UIEventSubtypeRemoteControlPlay = 100,
UIEventSubtypeRemoteControlPause = 101,
UIEventSubtypeRemoteControlStop = 102,
UIEventSubtypeRemoteControlTogglePlayPause = 103,
UIEventSubtypeRemoteControlNextTrack = 104,
UIEventSubtypeRemoteControlPreviousTrack = 105,
UIEventSubtypeRemoteControlBeginSeekingBackward = 106,
UIEventSubtypeRemoteControlEndSeekingBackward = 107,
UIEventSubtypeRemoteControlBeginSeekingForward = 108,
UIEventSubtypeRemoteControlEndSeekingForward = 109,
} UIEventSubtype;
So how do I stop the compiler complaining about it?
Also - how do i stop the compiler warnings that someClass may not respond to someMethod (where I check at runtime if that class does actually respond to the method, before calling it.) I suppose I could turn off that warning in the compiler settings - but it's a useful warning in other cases.
OK - Here's what I have discovered:
Switching the deployment_target to 4.3 then 3.1.3 causes the compilation errors and warnings to appear.
Once they appear you can get rid of them by compiling using a simulator scheme.
Once you have done that, you can compile using a real device scheme and the errors and warnings are gone.