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

emeryccc

macrumors newbie
Original poster
Oct 23, 2012
4
0
I am trying to post some login data but the NSStrings lines are not working... Anyone know why?


For example, these lines work
Code:
NSString *wallPost = @"the super wall post";
        
        NSString *post = [NSString = @”username=%@&password=%@”,usernameField.text, passwordField.text;
But these don't

Code:
      NSString *hostStr = @”THIS IS MY URL/iphonelogin-do.php?”;

Code:
#import "LoginTableViewController.h"

@interface LoginTableViewController ()
@property (weak, nonatomic) IBOutlet UITextField *UIEmailTextField;
@property (weak, nonatomic) IBOutlet UITextField *UIPasswordTextField;

@end

@implementation LoginTableViewController
@synthesize UIEmailTextField;
@synthesize UIPasswordTextField;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [self setUIEmailTextField:nil];
    [self setUIPasswordTextField:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - barButton Outlet

- (IBAction)loginButtonPressed:(UIBarButtonItem *)sender {
    {
        
        NSString *wallPost = @"the super wall post";
        
        NSString *post = [NSString = @”username=%@&password=%@”,usernameField.text, passwordField.text;
                       
        NSString *hostStr = @”THIS IS MY URL/iphonelogin-do.php?”;
        hostStr = [hostStr stringByAppendingString:post];
        NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
        NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
        
        
        
        
        
        
        
        if([serverOutput isEqualToString:@”Yes”]){
            
            
            UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@”Congrats” message:@”You are authorized “
                                                                  delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil, nil];
            
            [alertsuccess show];
            [alertsuccess release];
            
            
        } else {
            UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@”Error” message:@”Username or Password Incorrect”
                                                                  delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil, nil];
            [alertsuccess show];
            [alertsuccess release];
            
        }
        
    }

}

@end

Also, it says this isn't allowed :(


Code:
[alertsuccess release];

Thanks,
Emery
 
For example, these lines work
Code:
NSString *wallPost = @"the super wall post";
        
        NSString *post = [NSString = @”username=%@&password=%@”,usernameField.text, passwordField.text;
But these don't

Code:
      NSString *hostStr = @”THIS IS MY URL/iphonelogin-do.php?”;
Don't work how? Please elaborate.

Also, it says this isn't allowed :(


Code:
[alertsuccess release];
Are you using ARC?
 
For example, these lines work
Code:
NSString *wallPost = @"the super wall post";
        
        NSString *post = [NSString = @”username=%@&password=%@”,usernameField.text, passwordField.text;

The first line seems fine to me, but I find it difficult to believe the second line works.

First, it's not even valid syntax. You aren't allowed to assign a string literal to a class-name. It's just nonsense as given, and I can't even figure out what it's intended to be. If you copied it from somewhere, please post the URL or whatever source you copied it from. Be specific.

Second, you don't have a valid double-quote character in the second line. Somehow you have a "smart quote", which is to say, a typographer's quote, or a curly quote. Here's a valid (neutral) double-quote character, in a big font:
Code:
[SIZE="5"]test = @[COLOR="Red"]"[/COLOR]example";
[/SIZE]
Here's yours, in a big font:
Code:
[SIZE="5"]NSString = @[COLOR="red"]”[/COLOR]username=%@&pas[/SIZE]

I've hilited each character in red. The neutral quote is the only form that Objective-C recognizes.

Curly quotes often occur when blindly copying and pasting from web pages that contain curly quotes, or copying and pasting text from a word-processer that automatically replaces neutral quote-marks with curly quotes. There are other possible causes, but those two are pretty common.

The second line isn't the only use of curly quotes; you have more. Find them by selecting the curly quote, pressing command-E to Use the Selection for Find, then command-G to Find Next.

http://en.wikipedia.org/wiki/Quotation_mark
 

Tumblr has cleverly changed every neutral quote to a curly quote.


This is what I see for the username and password line. It seems correct, except for the curly quotes:
Code:
NSString *post =[NSString stringWithFormat:@”username=%@&password=%@”,usernameField.text, passwordField.text];
I have no idea how you ended up with this:
Code:
NSString *post = [NSString = @”username=%@&password=%@”,usernameField.text, passwordField.text;


There is a link to source files at the bottom of that tumblr post (find "Source is now available"). You could try that instead of copy-pasting from the curly-quoted text.
 
Thank you!!!

That worked, i just had to replace the quotes and it worked! But, now when i run the app, the NSString *post line crashes it, it say Thread1:Breakpoint1 with that line in green, here is the code now

Code:
//

#import "LoginTableViewController.h"

@interface LoginTableViewController ()
@property (weak, nonatomic) IBOutlet UITextField *UIEmailTextField;
@property (weak, nonatomic) IBOutlet UITextField *UIPasswordTextField;

@end

@implementation LoginTableViewController
@synthesize UIEmailTextField;
@synthesize UIPasswordTextField;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [self setUIEmailTextField:nil];
    [self setUIPasswordTextField:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - barButton Outlet

- (IBAction)loginButtonPressed:(UIBarButtonItem *)sender {
    {
        
     
        NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",UIEmailTextField.text, UIPasswordTextField.text];
                       
        NSString *hostStr = @"http://midislandsnoblazers.ca/iphonelogin-do.php?";
        hostStr = [hostStr stringByAppendingString:post];
        NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
        NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
        
        
        
        
        
        
        
        if([serverOutput isEqualToString:@"Yes"]){
            
            
            UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized"
                                                                  delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            
            [alertsuccess show];
          //  [alertsuccess release];
            
            
        } else {
            UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Username or Password Incorrect"
                                                                  delegate:self cancelButtonTitle:@"OK"otherButtonTitles:nil, nil];
            [alertsuccess show];
         //   [alertsuccess release]; Commented out because it doesn't allow this line ...
            
        }
        
    }

}

@end
 
:/

Not really, i just get the thread1 breakpoint thing all in green those lines
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.