日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

app把信息添加到mysql_如何将数据从iphone app上传到mysql数据库

發(fā)布時(shí)間:2023/12/15 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 app把信息添加到mysql_如何将数据从iphone app上传到mysql数据库 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在這種情況下,您可以采取以下兩種方式:

1.如果你非常喜歡使用POST(我喜歡),你可以使用cocoahttpserver項(xiàng)目:

https://github.com/robbiehanson/CocoaHTTPServer

在iphone應(yīng)用程序中,您可以執(zhí)行此代碼來發(fā)送POST請(qǐng)求:

-(NSDictionary *) getJSONAnswerForFunctionVersionTwo:(NSString *)function

withJSONRequest:(NSMutableDictionary *)request;

{

[self updateUIwithMessage:@"server download is started" withObjectID:nil withLatestMessage:NO error:NO];

NSDictionary *finalResultAlloc = [[NSMutableDictionary alloc] init];

@autoreleasepool {

NSError *error = nil;

NSString *jsonStringForReturn = [request JSONStringWithOptions:JKSerializeOptionNone serializeUnsupportedClassesUsingBlock:nil error:&error];

if (error) NSLog(@"CLIENT CONTROLLER: json decoding error:%@ in function:%@",[error localizedDescription],function);

NSData *bodyData = [jsonStringForReturn dataUsingEncoding:NSUTF8StringEncoding];

NSData *dataForBody = [[[NSData alloc] initWithData:bodyData] autorelease];

//NSLog(@"CLIENT CONTROLLER: string lenght is:%@ bytes",[NSNumber numberWithUnsignedInteger:[dataForBody length]]);

NSString *functionString = [NSString stringWithFormat:@"/%@",function];

NSURL *urlForRequest = [NSURL URLWithString:functionString relativeToURL:mainServer];

NSMutableURLRequest *requestToServer = [NSMutableURLRequest requestWithURL:urlForRequest];

[requestToServer setHTTPMethod:@"POST"];

[requestToServer setHTTPBody:dataForBody];

[requestToServer setTimeoutInterval:600];

[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[urlForRequest host]];

NSData *receivedResult = [NSURLConnection sendSynchronousRequest:requestToServer returningResponse:nil error:&error];

if (error) {

NSLog(@"CLIENT CONTROLLER: getJSON answer error download:%@",[error localizedDescription]);

[self updateUIwithMessage:[error localizedDescription] withObjectID:nil withLatestMessage:YES error:NO];

[finalResultAlloc release];

return nil;

}

NSString *answer = [[NSString alloc] initWithData:receivedResult encoding:NSUTF8StringEncoding];

JSONDecoder *jkitDecoder = [JSONDecoder decoder];

NSDictionary *finalResult = [jkitDecoder objectWithUTF8String:(const unsigned char *)[answer UTF8String] length:[answer length] error:&error];

[finalResultAlloc setValuesForKeysWithDictionary:finalResult];

[answer release];

[self updateUIwithMessage:@"server download is finished" withObjectID:nil withLatestMessage:NO error:NO];

if (error) NSLog(@"CLIENT CONTROLLER: getJSON answer failed to decode answer with error:%@",[error localizedDescription]);

}

NSDictionary *finalResultToReturn = [NSDictionary dictionaryWithDictionary:finalResultAlloc];

[finalResultAlloc release];

return finalResultToReturn;

}不要忘記將帶有圖像的屬性打包到base64。

最后,如果你不喜歡保存你在mac app中發(fā)送的數(shù)據(jù),你可以使用任何數(shù)據(jù)庫C api發(fā)送到你的數(shù)據(jù)庫。我建議使用核心數(shù)據(jù)來保存接收數(shù)據(jù)。

總結(jié)

以上是生活随笔為你收集整理的app把信息添加到mysql_如何将数据从iphone app上传到mysql数据库的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。