开发者

Usage of private API properties in older iOS, public in newer iOS

I know it is forbidden to use private API functions or classes, because they can change in a future version of iOS. So I wondering if it is allowed if a private function is now public in a new iOS.

My example is MPMoviePlayerController which 开发者_开发百科has a private property called currentTime in iOS before 3.2. Starting version 3.2, it is called currentPlaybackTime and can be used. If it can be used in newer versions, can it be used in older ?

Thanks


No, on older version of iOS the property is still private, we can only guess at reasons why.

In cases like this, you should take the same approach as you would when looking to support new features that aren't available in a previous OS: use them conditionally based on availability.

If you want to use the currentPlaybackTime property, you should weak-link against the framework in which it is declared and do a runtime check for its availability.

Something like this:

if ([playerController respondsToSelector:@selector(currentPlaybackTime)])
{
    // do something with currentPlaybackTime
}
else
{
    // fail-over to something supported and not private.
}

Remember: when compiling your iOS app, you should be compiling against the lastest-and-greatest iOS SDK version and setting your Deployment Target setting to the oldest version of iOS that you're willing to support.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜