RyJ
RyJ

Reputation: 4025

Apple and private APIs

Now that it's public knowledge that App Store submissions are being tested for use of private APIs, I need to ask the question... what exactly is a private API so that I may avoid them?

Upvotes: 8

Views: 14506

Answers (7)

mengxiangjian
mengxiangjian

Reputation: 562

My app was rejected by apple because of using private API.Here is code,

    Class UIKeyboardImpl = NSClassFromString(@"UIKeyboardImpl");

    id activeInstance = [UIKeyboardImpl performSelector:@selector(activeInstance)];

    [activeInstance performSelector:@selector(dismissKeyboard)];

Upvotes: 1

Andrew
Andrew

Reputation: 2710

A great tool to use before you submit your app is App Scanner. It scans your .app file for private API usage and shows you what method signatures match up and what classes those methods are in.

link --> http://www.chimpstudios.com/appscanner/

Upvotes: 1

lyonanderson
lyonanderson

Reputation: 2035

It's not just private APIs that can cause your application to get rejected. Using undocumented members of a public API can cause your application to get rejected. For example, the three20 library (since fixed) accessed _phase and other members of UITouch within a category.

They can also detect calls to private members via performSelector, as the following also flagged a rejection:

UIWindow* window = [UIApplication sharedApplication].keyWindow]
return !![window performSelector:@selector(firstResponder)];

More disturbing, if you make your application work under 3.1 and 3.0 and at runtime in 3.0 you don't use any of 3.1 stuff your application can still get rejected. An example might be the cameraOverlayView of UIImagePickerController (see here). This is kind of puzzling.

Upvotes: 3

koyeung
koyeung

Reputation: 132

It is not difficult to get rejected by so called "using private API". Try to use the following as Core Data attribute and it would be rejected:

  • colorIndex
  • occurrence
  • id

It shows how the robot scans the API.

Upvotes: 0

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422172

A private API is an API that is not documented in the SDK. For instance, a framework class might declare a method that is not intended to be used by outside developers. The behavior of a private API is not guaranteed. You can't even be sure that the method will be there in the future updates of the platform. Its declaration is probably not available in publicly distributed SDK header files. If you stick to things publicly defined in the SDK documentation, you'll be OK.

Upvotes: 18

mmc
mmc

Reputation: 17414

You will find it difficult to use a private API by accident. They are not documented within the SDK docs, and they don't show up in XCode's code completion suggestions.

The reason this has become news recently is the creator of a framework used by several apps used a private API, so when developers who included his framework updated their apps, they were rejected (even though THOSE developers didn't use a private API, the framework they added to their application did).

That's about the only way you could possibly use a private API accidentally.

Upvotes: 6

justin
justin

Reputation: 104708

Generally by their absence from SDK headers. One of apple's conventions is to lead ObjC method names with underscores.

Upvotes: 1

Related Questions