samedi 9 mai 2015

Auto login in webview OS X

I am new in OS X development. I try to auto-connect my app to a website. I have try an ios code but it's don't work.

My code :

Appdelegate.m

 NSString *urlAddress = @"http://ift.tt/1DYDZ4T";

NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];


[webview setCustomUserAgent: @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.74.9 (KHTML, like Gecko) Version/7.0.2 Safari/537.74.9"];

[[webview mainFrame] loadRequest:requestObj];

In my ios app, to login to my website I use this :

NSString *urlString = @"http://ift.tt/1eeEnPI";


//NSURL *url = [NSURL URLWithString:urlString];
NSURL *url = [NSURL URLWithString:urlString];


//NSURLRequest *request = [NSURLRequest requestWithURL:url];

//Add some informations POST
NSString *post = [NSString stringWithFormat:@"id=%@&password=%@&user=%@", server_id, server_password, user];;


NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];


NSOperationQueue *queue = [[NSOperationQueue alloc] init];


[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
 {
     if ([data length] > 0 && error == nil) [_seedbox loadRequest:request];
     else if (error != nil) NSLog(@"Error: %@", error);
 }];

But this code isn't work. Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire