RespondsToSelector returning a false-negative?
I'm currently using -respondsToSelector:
like so:
i开发者_运维知识库f (![moviePlayer respondsToSelector:@selector(currentPlaybackTime)]) {
NSLog(@"Cannot get current playbackTime on %@", moviePlayer);
return;
}
where moviePlayer is an instantiated MPMoviePlayerController object. I do a lot of other similar selector checks, so I know that pretty much everything else is working fine, but for some reason, this respondsToSelector check returns false, even though if I do something like time = [moviePlayer currentPlaybackTime]
, it works fine. This is on 4.0+ iOS, so there's no reason for it to return false.
Any reasons why this would happen?
According to the iOS class reference, currentPlaybackTime
is a property of MPMusicPlayerController
, not MPMoviePlayerController
.
MPMusicPlayerController: http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMusicPlayerController_ClassReference/Reference/Reference.html
MPMoviePlayerController: http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html
It may be a private property of MPMoviePlayerController
that does not have an accessor.
EDIT (see comments)
Determine OS version:
float iPhoneOSVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if ( iPhoneOSVersion < 3.2 )
{
}
else
{
}
精彩评论