Maxim Kholyavkin
Maxim Kholyavkin

Reputation: 4573

is there an easy way to disallow some method from framework?

I want to disallow some method. For example

+ (MPMusicPlayerController*)iPodMusicPlayer

so i tried to do so:

@interface MPMusicPlayerController (Disallowed)
// do never this method cause issues #957 #632 #1463
// read #632 description to detail analysis why code should never use this method while
// applicationMusicPlayer is used
+ (MPMusicPlayerController*)iPodMusicPlayer __attribute__((unavailable));
+ (MPMusicPlayerController*)iPodMusicPlayer __attribute__((deprecated));
@end

but code below compiled anyway without any warning

MPMusicPlayerController * curPlayer = [MPMusicPlayerController iPodMusicPlayer];

Any thoughts?

Upvotes: 1

Views: 188

Answers (2)

Maxim Kholyavkin
Maxim Kholyavkin

Reputation: 4573

Compile time solutions:

One way, just use next code:

#pragma GCC poison iPodMusicPlayer

I should mention SDK61 and SDK7 can not 'poison' selector which contains ':' cause llvm bug :(

another way:

#import <MediaPlayer/MediaPlayer.h> // import original methods at first
@interface MPMusicPlayerController (Disallowed)
+ (MPMusicPlayerController*)disallowedMethod_iPodMusicPlayer __attribute__((unavailable));
@end

#define iPodMusicPlayer disallowedMethod_iPodMusicPlayer

Upvotes: 2

Damien Del Russo
Damien Del Russo

Reputation: 1048

I think you can create a category on MPMusicPlayerController, e.g. Override (MPMusicPlayerController+Override), then override the iPodMusicPlayer class method to return nil. Be sure to #include MPMusicPlayerController+Override.h.

You can add a warning mark to your method to remind anyone not to use it:

#warning Disabled method - do not use.

Please let me know if that works for you.

Damien

Upvotes: 1

Related Questions