我想在我的应用程序处于后台时运行一些请求。我的应用程序支持后台模式-> 后台获取。
但是当我的应用程序在后台时,下面的代码总是返回失败!有没有办法运行请求?我也试过 NSURLConnection 它有时会收到响应有时不会收到响应!
[[AFHTTPRequestOperationManager manager]POST:@"http://app.xxxx.com/message_delivery.php" parameters:@{@"message_id":MsgID} constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
} success:^(AFHTTPRequestOperation *operation, id response) {
NSLog(@"succesfuly tik");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
}];
这些代码有时工作有时不
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://app.xxxx.com/message_delivery.php?message_id=%@",MsgID]];
NSURLRequest *request = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:2];
[[[NSURLConnection alloc] initWithRequest:request delegate:self]start];