gpt4 book ai didi

ios - Facebook SLRequest 搞乱 NSURLConnection

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:50 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com