views:

280

answers:

3

Hi,

I have taken this code from

http://stackoverflow.com/questions/883208/how-to-change-background-color-of-uialertview

UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Atention"
   message: @"YOUR MESSAGE HERE", nil)
   delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];

   [theAlert show];

   UILabel *theTitle = [theAlert valueForKey:@"_titleLabel"];
   [theTitle setTextColor:[UIColor redColor]];

   UILabel *theBody = [theAlert valueForKey:@"_bodyTextLabel"];
   [theBody setTextColor:[UIColor blueColor]];

   UIImage *theImage = [UIImage imageNamed:@"Background.png"];    
   theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
   CGSize theSize = [theAlert frame].size;

   UIGraphicsBeginImageContext(theSize);    
   [theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];    
   theImage = UIGraphicsGetImageFromCurrentImageContext();    
   UIGraphicsEndImageContext();

   [[theAlert layer] setContents:[theImage CGImage]];

orginally posted by oxigen.

I am not very sure should I use this code in my app. Will apple have any issues regarding this hack (will they reject the app?)

+2  A: 

Only Apple can answer that question. And they won't answer it until you submit it and wait approximately 2 weeks.

If you really want it in and have 2 weeks to kill, try to submit it. But it might get rejected at an update later.

Are you using any undocumented APIs here? If you are, assume it will get rejected. If you aren't but you are doing something different, then the only answer to your question which is correct is "I don't know".

marcc
thanks for the answer and giving your time ;)
Madhup
+6  A: 

The underscores as prefixes of the properties you're accessing (_titleLabel, _bodyTextLabel) clearly indicate that these are private properties and should not be tinkered with. Apple has recently started scanning all submitted binaries for access to private methods and properties, and those values by themselves within your application should be enough to get you rejected. It is never a good idea to use private APIs, rejections or no, because they are typically private for a reason and may break your application with future OS updates.

Additionally, you are violating the iPhone Human Interface Guidelines by changing the alert color:

You can specify the text, the number of buttons, and the button contents in an alert, but you can’t customize the background appearance of the alert itself.

Again, from the iPhone Human Interface Guidelines:

Because users are accustomed to the appearance and behavior of these views, it’s important to use them consistently and correctly in your application.

Brad Larson
Because the code uses "valueForKey", the scanners might not find this (because they would be looking for symbols, not plain strings). But, I would not want to bet on that...
Kendall Helmstetter Gelner
True. It's not hard to imagine that they could also do a sweep for strings. I don't know if they'd be worried about false positives from that, though. Most of the symbols they'd look for would be odd to find in legitimate text somewhere in the application.
Brad Larson
A: 

If you want to know if some programming technique will result in rejection, make a small app with limited functionality and use your questionable technique in it.

It takes 2 weeks to get an answer but at least you won't invest a ton of time upfront.

If they approve your test app, delete it from the store. If it has genuine utility, set the price to $0.99 and leave it.

This method is not foolproof, but it is low cost.

willc2
"This method is not foolproof ...". You said it! There have been well publicized examples where the Apple store folks have changed their minds and rejected something they previously accepted.
Stephen C