我正在尝试使用SLRequest iOS API获取Facebook数据,但似乎工作正常-
NSDictionary *parameters = @{};
NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/home"];
SLRequest *feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:feedURL
parameters:parameters];
feedRequest.account = facebookAccount;
[feedRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
// something
}];
但是,此后,我向其中一台服务器发出了HTTP POST请求,
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData *requestData = [NSData dataWithBytes:[jsonData bytes] length:[jsonData length]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: requestData];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
它可以很好地发布数据(从服务器日志中验证),但是我在其中没有得到任何HTTP响应
connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response
在没有SLRequest POST的情况下,此方法过去工作正常,我可以注释掉该内容,然后重新开始工作。
我在这里想念什么?
最佳答案
您如何创建对NSURLConnection的强引用,我猜想iOS正在释放该对象,所以这就是您的代理从不被调用的原因。
因此,代替:
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
用:
self.connection=[[NSURLConnection alloc]initWithRequest:request delegate:self];
哪里:
@property(nonatomic, strong)NSURLConnection * connection;
让我知道进展如何,欢呼。
亲切的问候