我需要在后台模式ios中从服务器获取数据。但是当我在后台运行app时,didReceiveData方法从未调用过。在前台它工作正常。 当app在后台运行时,app会从applicationDidEnterBackground方法请求数据。我不能为什么didReceiveData方法不能调用。
请帮助我!
答案 0 :(得分:0)
我用这种方式可以帮助你..
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^ {
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic setObject:string forKey:@"data"];
[dic setObject:ADDD_DATA_UPGRADE forKey:@"cn"];
[dic setObject:@"true" forKey:@"mode"];
[self login:dic];
dispatch_async(dispatch_get_main_queue(), ^(void)
{
});
});
}
- (无效)的登录:(的NSDictionary *)DIC {
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:UPDATION_ON_SERVER_TIME];
SAAPIClient *manager = [SAAPIClient sharedClient];
[[manager responseSerializer] setAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];
[manager postPath:@"" parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject)
{
if([[responseObject objectForKey:@"status"] boolValue])
{
NSLog(@"Success: %@ ***** %@", operation.responseString, responseObject);
[self parseResponseFromJson:responseObject];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:UPDATION_ON_SERVER_TIME];
NSLog(@"Success: %@ ***** %@", operation.responseString, error);
}];