sql >> Base de Datos >  >> RDS >> Mysql

Xcode:la forma más fácil de enviar datos desde iOS TextField, por ejemplo, a una base de datos remota

Simplemente puede recopilar los datos de un formulario nativo y luego usar NSURLRequest / NSURLConnection para enviar los datos a la página de su servidor php.

//Example form with one php variable only. Use get URL argument notation to add more args.
NSString *rawStr = [NSString stringWithFormat:@"var=%@",textBox.text];
NSData *data = [rawStr dataUsingEncoding:NSUTF8StringEncoding];

NSURL *url = [NSURL URLWithString:@"http://myurl.com/script.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:data];

NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);