0
NSURL *url = [NSURL URLWithString:@"contact.php"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"companyID", constCompanyID,
nil];
NSURLRequest *request = [httpClient requestWithMethod: @"POST" path:@"contact.php" parameters:params];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
for(id entry in JSON)
{
self.strAddr = [entry valueForKeyPath:@"addr"];
CCLOG(@"Address: %@", self.strAddr);
}
} failure:nil];
[operation start];
CCLOG(@"Address: %@", strAddr);
ログには、アドレスはnullです。 PHPは問題ありません。ブラウザでは、私が望むものを返します。AFJsonRequestとAFHttpClientは連携して動作しますか?
このコードは、変数に渡すためにAFHTTPClientを追加するまで機能しました。私は間違ったことをしているに違いないか、そうしていないのだろうか?