Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

webznz

macrumors member
Original poster
Mar 8, 2011
82
0
Hobbitin
I am currently setting up a little security feature on this app I'm making,
whats happening as soon as my app is launched it sends its cookie to the database in return for a new cookie. If the user starts the app for the first time, or has a cookie that is out of sync because of various reasons (for instance they have given heir registration code to someone else to use) they will be given an Alert View error msg...

Code:
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please Register Device"
														message:@"click OK to register"
													   delegate:nil
											  cancelButtonTitle:@"OK"
											  otherButtonTitles:nil];
		[alert autorelease];
		[alert show];

I am wondering how I would go about sending the user to a new view (that will allow them to enter their registration code) with the
Code:
cancelButtonTitle
button when it is pressed on the alert view
 
Last edited:
Code:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
	NSString *buttonTitle=[actionSheet buttonTitleAtIndex:buttonIndex];
	if ([buttonTitle isEqualToString:@"Start driving"]) {
		success = [DriverService moveToNextState];
	} else if ([buttonTitle isEqualToString:@"Start job"]) {
		success = [DriverService moveToNextState];
	} else if ([buttonTitle isEqualToString:@"Finish job"]){
		success = [DriverService moveToNextState];
		if (success){
			[self.navigationController popViewControllerAnimated:YES];
			return;
		}
	}
	if (success){
		self.driver = success;
		[self updateMap];
	}
	
}
something like this. but then with the alertView instead of actionsheet ;)
 
cheers dude :) will try it out now.

EDIT:

Im not sure if im using this correctly or not. I figure if my cancelButtonTitle:mad:"OK" is pressed it should initiate my alertView:didDismissWithButtonIndex: method... is that right? sorry just having abit of a moment with this.

Code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
	//we are just checking to make sure we are getting the SML
	NSString *cookieCheck = [[[NSString alloc] initWithData:cookieData encoding:NSUTF8StringEncoding] autorelease];
	NSLog(@"yum yum feed me more cookie!! %@",cookieCheck);
	
	//Put cookie check stuff here.. 
	
	//CODE=1
	if([cookieCheck rangeOfString:@"Code=1"].location != NSNotFound) {
		//found it Send error prompt (OK loads new view for fucnt Reg) 
		NSLog(@"cookieCode = code1");
		
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please Register Device"
														message:@"click OK to register"
													   delegate:nil
											  cancelButtonTitle:@"OK"
											  otherButtonTitles:nil];
		
		[alert autorelease];
		[alert show];
		
	}else {
		NSLog(@"cookieCode = code?");
	}

}

- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex {
	//Test
        NSLog(@"msg from alertView method");
    

	
}
 
Last edited by a moderator:
it just clicked... made me mad as hell that i didnt think of this right away.... set delegate of the alertView to self..

Solution.
Code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
	//..................
	//CODE=1
	if([cookieCheck rangeOfString:@"Code=1"].location != NSNotFound) {
		//found it Send error prompt (OK loads new view for fucnt Reg) 
		NSLog(@"cookieCode = code1");
		
		
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please Register Device"
														message:@"click OK to register"
													   delegate:[B][COLOR="Red"]self[/COLOR][/B]
											  cancelButtonTitle:@"OK"
											  otherButtonTitles:nil];
		
		// If i want to add text field to alert use this code....
		
		UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
		[myTextField setBackgroundColor:[UIColor whiteColor]];
		[alert addSubview:myTextField];
		
		[alert autorelease];
		[alert show];
		
	}else {
		//cant find appropriate response...
		NSLog(@"cookieCode = code?");
	}

}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
	
        NSLog(@"msg from alertView method");
    

	
}
 
But now the log is triggering on all the buttons or not?!
U need to create a buttonindex, or like in my example, compare the titles.
Greetings.

Yea, I didn't do a button index because I only have the one button option. :eek:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.