2

I need to know the following;

1.) I need to add an image to a UIAlertView programatically (if this is not allowed or permitted by apple, then some other legal way of doing it) ?

2.) What are private APIs ? and how can i distinguish one ?

sharon
  • 580
  • 12
  • 28

2 Answers2

4

1.) Do the Following:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel otherButtonTitles:nil];

UIImageView *imageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: imageName]];

[alert addSubview:imageView];
[alert show];

2.) API not in the Documentation are private API shouldn't be used.

Jorge Cohen
  • 1,512
  • 10
  • 34
  • Ok, then ASIHTTPRequest, MBProgressHUD, and there are loads of these libraries. So aren't they private too ? – sharon Jan 29 '12 at 15:25
  • 1
    well, they are private in the sense they are not made by apple. what I meant was, that if a class/function/method is made by apple but does not appear in the apple provided documentation then it is considered private and shouldn't be used. 3rd party libraries won't show up on apple provided docs but they are usually safe to use. – Jorge Cohen Jan 29 '12 at 15:27
  • ... and unless they are using private APIs you can freely use them (with regards to the software license) – Rok Jarc Jan 29 '12 at 15:42
1

Hezi has a good answer and it might work; but check out the documentation for UIAlertView, specifically this section:

Subclassing Notes The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

(that last sentence is the important thing here).

I recommend creating your own UIView subclass which looks like a UIAlertView and then you can add it (and an image or whatever else you want to put in there) as a subview and you won't have unexpected breakage if Apple does something to the UIAlertView class to make its innards even more private.

As for Apple's private API's (and private frameworks), if you want to sell on the Apple App Store... do not even think of making use of them. Apple rejects apps for trying to do that. Now, if you want to do this as a jailbroken app and not meant to be sold on the Apple Store, you might be able to get away with it. Here is a related StackOverflow question that talks more about them.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • So does that mean i can't use ASIHTTPRequest, MBProgressHUD or any other 3rd party APIs in my project ? How could foursquare made it to the app store, they have something similar to `MBProgressHUD` in it – sharon Jan 29 '12 at 15:41
  • 3rd party APIs are not the same as private APIs. 3rd party APIs are just bits of code that use Apple's existing [public] APIs. – Carlos P Aug 20 '13 at 09:23