0

我有一个通过 php 连接到数据库的应用程序,我试图将一些大数据发送到数据库,例如坐标列表

"37.351701,-122.105898",
"37.351945,-122.106109",
"37.352183,-122.106338",
"37.352409,-122.106568"

添加这样的 4 行字符串没问题,还添加了 150 行字符串,但大约 200 行标记它没有,我试图用它发布的其余数据也丢失了。我通过创建 .txt 并将数据添加到其中并使用 php 对此进行了测试,如果它超过 200 行,它不会到达 php 文件,但 150 又可以了。

我获取坐标并将它们放入数组中,

if ((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) &&
    (oldLocation.coordinate.longitude != newLocation.coordinate.longitude))

    self.trackCoord = [NSString stringWithFormat:@"%f,%f",newLocation.coordinate.latitude, newLocation.coordinate.longitude];

        if (!self.trackArray) {
        self.trackArray = [[NSMutableArray alloc] init];
    }
    [self.trackArray addObject:self.trackCoord];

数组被传递到另一个数组trackArrayList等中,并在这个方法中我发布到 php 文件中。

-(void) shareRoute:(NSString*) to withName:(NSString *) from withName:(NSString *) name withName:(NSString *) type withName:(NSString *) duration withName:(NSMutableArray *) trackArrayList{

if (from != nil && to != nil && name != nil){

    NSMutableString *postString = [NSMutableString stringWithString:shareURL];

    [postString appendString:[NSString stringWithFormat:@"?%@=%@", Sfrom, from]];
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", Sto, to]];
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", Sname, name]];
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", Stype, type]];
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", Sduration, duration]];
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", StrackArray, trackArrayList]];

    [postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
    [request setHTTPMethod:@"POST"];

    postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];        
    }

}

我尝试过写[postString appendString:[NSString stringWithFormat:@"&%@=%@", StrackArray, trackArrayList]];不同的变体NSMutableString stringWithFormat等,但结果相同。

字符串是否不够大,无法容纳这么多行,或者应用程序在发布之前内存不足。

关于可能导致此问题的任何建议,或任何其他编写appendString.

4

2 回答 2

1

Ernie,如果您准备好要使用的数据,POST您可以PHP使用$_POST['name']...

NSURL *url = [NSURL URLWithString:@"Your php scripts URL"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];


[request setHTTPMethod:@"POST"];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];

postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];        
于 2014-03-11T21:26:35.940 回答
-1

让它正常工作

NSURL *url = [NSURL URLWithString:shareURL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

NSMutableData *body = [NSMutableData data];

[body appendData:[[NSString stringWithFormat:@"%@=%@", Sfrom, from] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"&%@=%@", Sto, to] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"&%@=%@", Sname, name] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"&%@=%@", Stype, type] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"&%@=%@", Sduration, duration] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"&%@=%@", StrackArray, trackArrayList] dataUsingEncoding:NSUTF8StringEncoding]];

[request setHTTPBody:body];
[request setHTTPMethod:@"POST"];
postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
于 2014-03-20T20:11:47.453 回答