有人能在Cocoa Mac上给我一个简单的sqlite示例吗?我想在我的Mac桌面应用程序中使用它。我不知道如何在mac应用程序中使用sqllite。
答案 0 :(得分:7)
答案 1 :(得分:2)
将字符串传递给Mac应用程序中的远程PHP文件。这就是你如何做到的。
// form text fields and values NSArray *formfields = [NSArray arrayWithObjects:@"email", @"password", @"confirm_password", nil]; NSArray *formvalues = [NSArray arrayWithObjects:[nameField stringValue], [passwordField stringValue],[confirmField stringValue], nil]; NSDictionary *textParams = [NSDictionary dictionaryWithObjects:formvalues forKeys:formfields]; // submit the form [self doPostWithText:textParams]; - (void) doPostWithText:(NSDictionary *)textParams { NSString *urlString = @"Your Remote PHP Url goes here!"; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"]; NSMutableData *body = [NSMutableData data]; NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"]; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; [request addValue:contentType forHTTPHeaderField:@"Content-Type"]; // add the text form fields for (id key in textParams) { [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; //[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:[textParams objectForKey:key]] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; } // close form [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; // set request body [request setHTTPBody:body]; //return and test NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSLog(@"%@", returnString); }