Tag: 联网

使用AFNetworking 3将当前位置发送到服务器以及在后台运行应用程序

我试图search很多,但我没有得到确切的答案,我想要的。 我的问题是 当应用程序在运行时以及在后台运行时,我可以将用户的当前位置发送到服务器吗? 例如:在我的应用程序中,我想每2分钟存储一次用户的当前位置,然后将其当前位置发送到server.as以及如果用户在2分钟内移动50米,那么也是如此。 我怎样才能做到这一点 ? 我可以发送位置更新到服务器在后台模式以及前台模式? 如果是的话那怎么样? 我尝试如下方式: self.locations = [[NSMutableArray alloc] init]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.distanceFilter = 10; self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; self.locationManager.delegate = self; [self.locationManager requestAlwaysAuthorization]; [self.locationManager startUpdatingLocation]; … – (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { // Add another annotation to the map. MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; annotation.coordinate […]

与AFNetworking一起发送图像和其他参数

我正在更新与AFNetworking一起使用ASIHTTPRequest的旧应用程序代码。 就我而言,我正在向API发送数据,这些数据是不同的types:Image和其他。 下面是我目前采用的代码,实现一个API客户端,请求共享实例,准备params字典并将其发送到远程API: NSMutableDictionary *params = [NSMutableDictionary dictionary]; [params setValue:@"Some value" forKey:aKey]; [[APIClient sharedInstance] postPath:@"/post" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { //some logic } failure:^(AFHTTPRequestOperation *operation, NSError *error) { //handle error }]; 当我想要添加一个图像到params字典会是什么情况? 有了ASIHTTPRequest ,我曾经做了以下工作: NSData *imgData = UIImagePNGRepresentation(anImage); NSString *newStr = [anImageName stringByReplacingOccurrencesOfString:@"/" withString:@"_"]; [request addData:imgData withFileName:[NSString stringWithFormat:@"%@.png",newStr] andContentType:@"image/png" forKey:anOtherKey]; 我深入到AFNetworking文档,发现他们在一个NSMutableRequest像这样附加图像: AFHTTPClient *httpClient = […]

AFNetworking和POST请求

在从AFNetworking发出POST请求时,我在error.userInfo中得到了这个响应。 任何人都可以告诉我缺less任何明显的东西或需要修复我的服务器端? 请求失败,错误:错误域= AFNetworkingErrorDomain代码= -1016“预期的内容types{(”文本/ JSON“,”应用程序/ JSON“,”文本/ JavaScript“)),得到文本/ HTML”UserInfo = 0x6d7a730 {NSLocalizedRecoverySuggestion = AFNetworkingOperationFailingURLRequestErrorKey = NSErrorFailingURLKey = http://54.245.14.201/,NSLocalizedDescription =预期内容types{(“text / json”,“application / json”,“text / javascript”)},获取文本/ html,AFNetworkingOperationFailingURLRequestErrorKey = http://54.245.14.201/>},{AFNetworkingOperationFailingURLRequestErrorKey =“http://54.245.14.201/”“; AFNetworkingOperationFailingURLResponseErrorKey =“”; NSErrorFailingURLKey =“http://54.245.14.201/”; NSLocalizedDescription =“期望的内容types{(\ n \”text / json \“,\ n \”application / json \“,\ n \“text / javascript \”\ n)},得到text / html“; NSLocalizedRecoverySuggestion =”index […]

AFNetworking上传文件

是否有任何人使用AFNetworking上传文件的完整实现? 我在网上find了一些代码,但并不完整。 我find的代码在这里: AFHTTPClient *client= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://my.client.server.com"]]; NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [parameters setObject:[fieldName text] forKey:@"field01_nome"]; [parameters setObject:[fieldSurname text] forKey:@"field02_cognome"]; NSMutableURLRequest *myRequest = [client multipartFormRequestWithMethod:@"POST" path:@"/Contents/mail/sendToForm.jsp" parameters:parameters constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) { [formData appendPartWithFileData:myNSDataToSend mimeType:@"image/jpeg" name:@"alleagto"]; }]; AFHTTPRequestOperation *operation = [AFHTTPRequestOperation HTTPRequestOperationWithRequest:myRequest success:^(id object) { NSLog(@"Success"); } failure:^(NSHTTPURLResponse *response, NSError *error) { NSLog(@"Fail"); }]; [operation […]

如何禁用AFNetworkingcaching

是否可以禁用AFNetworking的所有cachingfunction? 我正在构build自己的自定义caching系统,不希望它占用磁盘空间。 谢谢,阿什利