> On Sep 10, 2016, at 4:39 AM, Andreas Falkenhahn <[email protected]>
> wrote:
>
> I want my app to run on 10.6 but use 10.7 features where available. Thus I'm
> compiling on 10.11 using -mmacosx-version-min=10.6. In particular, I want to
> use AVFoundation to play videos on 10.7 and better.
>
> To open a video, I do the following:
>
> AVPlayer *p = [[AVPlayer alloc] initWithURL:url];
>
> I'd expect this code to crash on 10.6 because 10.6 doesn't have AVPlayer.
> To my surprise, however, the code doesn't crash and it just returns NULL.
> This is fine because then my app will just show a message box informing
> the user that the file couldn't be opened and no other AVFoundation APIs
> will be accessed.
>
> However, I'm wondering whether it is ok to execute this code on 10.6 without
> any safeguard. I thought I'd have to do something like this instead:
>
> if(floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_7) {
>
> AVPlayer *p = [[AVPlayer alloc] initWithURL:url];
> ...
>
> } else {
>
> return NULL;
> }
>
> Do I have to do this or can I just rely on alloc/init returning NULL for
> classes unknown on 10.6?
If your deployment target is OS X 10.7 or iOS 3.1 or later
and class SomeClass is declared weak-import (for example, it has an
availability attribute that is newer than your deployment target)
then all of the following are true:
* [SomeClass anyMessage] returns nil.
* [MySubclassOfSomeClass anyMessage] returns nil.
* Subclasses of SomeClass are ignored by the runtime; it acts as if they do
not exist.
* Categories attached to SomeClass or a subclass thereof are ignored by the
runtime.
If your deployment target is OS X 10.7 or iOS 3.0 or earlier
or SomeClass is not declared weak-import (for example, it has no availability
attribute or you didn't set your deployment target correctly)
then it is unsafe to use SomeClass or subclass SomeClass directly. You must not
call [SomeClass anyMessage]. You must use the result of objc_getClass() instead.
Some "unavailable" classes were in fact present as SPI on older OS versions.
That will confuse tests like `if ([SomeClass class]) { … }`. Test your code on
your old deployment targets.
--
Greg Parker [email protected] <mailto:[email protected]> Runtime
Wrangler
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]