6

I am using a custom UIAlertView with UITextField to get password from the user.

I have been told that this custom view may cause my App to get reject by Apple; is that correct? If so, what is the appropriate replacement for my custom control?

Ahmad Kayyali
  • 8,233
  • 13
  • 49
  • 83
  • Why should your app get rejected by apple? – Nick Weaver Apr 19 '11 at 13:43
  • @Nick Weaver: Back in the first stages of my project, I was looking for a Custom UIAlertView With Password UITextField, the forum submitter pointed that this may be against APPLE policy because the user might think this is the Wifi dialog for network password. – Ahmad Kayyali Apr 19 '11 at 13:59
  • Ah I see, interesting. Anyway, why don't you present a modal view which does differ from the look and feel of those UIAlertViews used by Apple. – Nick Weaver Apr 19 '11 at 14:03
  • @Nick Weaver: thanks for the suggestion,I will try those Custom views that has been tested and working on real applications now. – Ahmad Kayyali Apr 20 '11 at 06:14

8 Answers8

11

You can add a textfield to your UIAlertView

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"msg" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[alertView addSubview:txtField];
[alertView show];
[alertView release];
saadnib
  • 11,145
  • 2
  • 33
  • 54
  • Thank you very much for the post, i am having ZERO problems doing that, my concerns are is that against apple policy for posting iPhone Application. – Ahmad Kayyali Apr 19 '11 at 13:56
4

See my blog post of doing this and its perfectly accepted code by apple. I added this in some of my apps and they all got accepted. So use it without fear!!

Here is the code you can use :

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here!" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:myTextField];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 130.0);
[myAlertView setTransform:myTransform];
[myAlertView show];
[myAlertView release];
JOM
  • 8,139
  • 6
  • 78
  • 111
Saurabh
  • 22,743
  • 12
  • 84
  • 133
2

Check below blog tutorial for the complete solution.

http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html?cmd=success#comment3870

Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
1

Quoting from the class reference

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.

The last sentence appears to me that they don't want developers modifying the views.

Marc
  • 1,541
  • 2
  • 19
  • 29
1

I think there is a better way to solve this. Here is the code snippet

UIAlertView *passwordAlert = [[UIAlertView alloc]                                       
                              initWithTitle:@"Enter Password" message:@""
                              delegate:self 
                              cancelButtonTitle:nil                    
                              otherButtonTitles:@"Submit", nil];

passwordAlert.alertViewStyle = UIAlertViewStyleSecureTextInput;

(You can find related implementations in prodeveloper blog)

But this works fine on iOS 5.0 and above only. Please make a note of it. And Apple will certainly approve it.

voromax
  • 3,369
  • 2
  • 30
  • 53
prodeveloper
  • 943
  • 14
  • 22
1

If you're concerned about rejection, you can always roll your own view that has animations similar to a UIAlertView. Check this question out here:

How can I customize an iOS alert view?

Community
  • 1
  • 1
sudo rm -rf
  • 29,408
  • 19
  • 102
  • 161
1

iOS 5 now supports this natively. Check out UIAlertView's alertViewStyle property.

Danra
  • 9,546
  • 5
  • 59
  • 117
0

Ya Apple approve the customization of UIAlertview. From iOS 5.0 apple gives alertview type to take credential input.

Here I listed a custom alertview which is able to work on older ios version and orientation custom alertview

thanks,

Naveen Shan

Naveen Shan
  • 9,192
  • 3
  • 29
  • 43