Bien qu'il n'y ait pas besoin d'ajouter Captcha dans certaines applications, comme les applications ne sont pas comme Web, Donc, selon ma pensée, il n'y a pas besoin de joindre le Captcha dans certaines applications pour empêcher les robots. pour l'intégrer ... Oui, voici le chemin possible, vérifier les S'il vous plaît codes suivants:
Prenez ces sorties et variables:
NSArray *arrCapElements;
IBOutlet UILabel *Captcha_label;
IBOutlet UITextField *Captcha_field;
IBOutlet UILabel *Status_label;
et IBActions
comme:
- (IBAction)Reload_Action:(id)sender;
- (IBAction)Submit_Action:(id)sender;
Dans le storyboard, choisissez le nom de la police en tant que Chalkduster 30.0 pour le Captcha_label
.
maintenant attribuer arrCapElements
à viewDidLoad()
comme
arrCapElements = [[NSArray alloc]initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z",@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z", nil];
Code pour charge Captcha:
-(void)load_captcha{
@try {
CGFloat hue = (arc4random() % 256/256.0); // 0.0 to 1.0
CGFloat saturation = (arc4random() % 128/256.0) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = (arc4random() % 128/256.0) + 0.5; // 0.5 to 1.0, away from black
Captcha_label.backgroundColor = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
//Captcha_label.textColor=[UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
NSUInteger elmt1,elmt2,elmt3,elmt4,elmt5,elmt6;
elmt1 = arc4random() % [arrCapElements count];
elmt2= arc4random() % [arrCapElements count];
elmt3 = arc4random() % [arrCapElements count];
elmt4 = arc4random() % [arrCapElements count];
elmt5 = arc4random() % [arrCapElements count];
elmt6 = arc4random() % [arrCapElements count];
NSString *Captcha_string = [NSString stringWithFormat:@"%@%@%@%@%@%@",arrCapElements[elmt1-1],arrCapElements[elmt2-1],arrCapElements[elmt3-1],arrCapElements[elmt4-1],arrCapElements[elmt5-1],arrCapElements[elmt6-1]];
//NSLog(@" Captcha String : %@",Captcha_string);
Captcha_label.text = Captcha_string;
}
@catch (NSException *exception) {
NSLog(@"%@",exception);
}
}
Action Recharger:
- (IBAction)Reload_Action:(id)sender {
[self load_captcha];
}
Vérifiez le captcha correct ou non:
- (IBAction)Submit_Action:(id)sender {
NSLog(@"%@ = %@",Captcha_label.text,Captcha_field.text);
if([Captcha_label.text isEqualToString: Captcha_field.text]){
[self.view endEditing:YES];
Status_label.text [email protected]"Success";
Status_label.textColor = [UIColor greenColor];
}else{
Status_label.text [email protected]"Faild";
Status_label.textColor = [UIColor redColor];
}
}
On montrera comme ceci:
Aide tirée de: Captcha Generator for iOS
Avez-vous remarqué qu'aucun des applications sur l'App Store ont CAPTCHAs soit? Vous êtes-vous déjà demandé pourquoi? – BoltClock
J'ai vu captcha dans 1 application dans iTunes. S'il vous plaît rechercher DealTiem.ie Mobile dans le style de vie. et téléchargez que c'est gratuit. dans cette section envoyer le courrier contient le code captcha. –
captcha est utilisé pour savoir si l'utilisateur est humain ou machine .in iphone vous ne vous inquiétez pas à ce sujet.Parce que iphone sandbox ne permet pas d'autre application pour accéder à d'autres app.and plus Apple rejettera l'application si vous envoyez un email aussi caché. donc pas besoin de captcha ici. –