ios - Facebook SLRequest 搞乱 NSURLConnection

标签 ios objective-c nsurlconnection social-framework slrequest

我正在尝试使用 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];

哪个 POST 数据正常(从服务器日志验证),但我没有得到任何 HTTP 响应

connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response

这过去在没有 SLRequest POST 的情况下工作正常,我能够评论该部分并再次开始工作。

我在这里错过了什么?

最佳答案

你如何创建一个对你的 NSURLConnection 的强引用,我猜 iOS 正在释放那个对象,所以这就是你的委托(delegate)永远不会被调用的原因。

所以,而不是:

NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];

使用:

self.connection=[[NSURLConnection alloc]initWithRequest:request delegate:self];

地点:

@property(nonatomic, strong)NSURLConnection * connection;

让我知道进展如何,干杯。

亲切的问候

关于ios - Facebook SLRequest 搞乱 NSURLConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19626665/

相关文章:

iphone - UIDocumentInteractionController - 我们自己的应用出现在列表中

iphone - 控制 NSURLConnection 中接收数据的顺序?

concurrency - 异步 NSURLConnection,并发 NSOperation,什么时候使用 NSRunLoop?

ios - UICollectionView 在刷新时重复和重新排序单元格内容

javascript - 如何将包含 JSON 的 JSON NSString 从 Objective C 方法传递给 Javascript 方法

ios - UIBezierPath 内存问题

iphone - 如何使用 nsurlconnection 发送 post 请求

ios - 下拉并按住时 UIRefreshcontrol 抖动

ios - 重新创建或更新配置文件后是否需要更新?

ios - 如何在屏幕键盘上给按钮 iPhone 返回键行为?