-1

私は問題があります、

これをphpファイルに送信する必要があります。私だけが EXC_BAD_ACCES を取得します。

おそらく、データ オブジェクトを解放する必要があるためです。しかし、私のデータオブジェクトが何であるかわかりません。

これをhttp://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.htmlからコピーしました。

多分あなたは私を助けることができるでしょう、それはおそらくあなたにとって非常に小さな変化ですが、私にはそれがわかりません.

あいさつ

   NSURL *url = [NSURL URLWithString:@"http://www.yourdomain.com/locatie.php"];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url
                                                            cachePolicy:NSURLRequestReloadIgnoringCacheData
                                                      timeoutInterval:60];

[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

NSString *postData = [NSString stringWithFormat:@"longitude=%@&latitude=%@&stringFromDate=%@", longitude, latitude, stringFromDate];

NSString *length = [NSString stringWithFormat:@"%d", [postData length]];
[theRequest setValue:length forHTTPHeaderField:@"Content-Length"];

[theRequest setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]];

NSURLConnection *sConnection = [NSURLConnection connectionWithRequest:theRequest   delegate:self];
[sConnection start];

if (sConnection) {
    // Create the NSMutableData to hold the received data.
    // receivedData is an instance variable declared elsewhere.
    theRequest = [[NSMutableData data] retain];
} else {
    // Inform the user that the connection failed.
}


}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse   *)response
{
// This method is called when the server has determined that it
// has enough information to create the NSURLResponse.

// It can be called multiple times, for example in the case of a
// redirect, so each time we reset the data.

// receivedData is an instance variable declared elsewhere.
}
- (void)connection:(NSURLConnection *)connection
 didFailWithError:(NSError *)error
{
// release the connection, and the data object
[connection release];
// receivedData is declared as a method instance elsewhere

// inform the user
NSLog(@"Connection failed! Error - %@ %@",
      [error localizedDescription],
      [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}

 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
 {
// do something with the data
// receivedData is declared as a method instance elsewhere
NSLog(@"Succeeded! Received bytes of data");

// release the connection, and the data object
[connection release];
}
4

1 に答える 1

0

クラッシュに関する詳細な診断情報を取得するには、NSZombiesを有効にします。これは、オブジェクトの過剰解放に関連している可能性が高いです。

あなたのコードを見ると、問題はここにあると思います:

NSURLConnection *sConnection = [NSURLConnection connectionWithRequest:theRequest   delegate:self];

これは、宣言されている (メソッドの) スコープの最後で消える自動解放オブジェクトです。

retain修正は、クラスのプロパティにNSURLConnection 参照を格納することです。

于 2012-09-03T14:50:06.187 に答える