我想运行一些请求,而我的应用程序在background.My应用程序支持背景模式 - >后台提取。在后台运行请求IOS
但下面的代码总是返回失败,而我的应用程序在后台! 有没有办法运行请求?我也试过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];
顺便说一句,当使用'NSURLConnection'时,不要将'start'与'initWithRequest:delegate:'结合使用。这已经开始为你。如果你使用'initWithRequest:delegate:startImmediately:'''NO' /'FALSE'作为最后一个参数,那么只能使用'start'方法。 – Rob