AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@", [[NSUserDefaults standardUserDefaults] objectForKey:TOKEN]] forHTTPHeaderField:@"Authorization"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager POST:@"http:xxxxx" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:profileImage name:@"file" fileName:@"profileImage.jpg" mimeType:@"image/jpeg"];
} success:^(NSURLSessionTask *task, id responseObject) {
completionHandler(responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSData *errorData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
NSDictionary *serializedData = [NSJSONSerialization JSONObjectWithData: errorData options:kNilOptions error:nil];
errorHandler(serializedData);
}];
Questo metodo funziona correttamente, ma constructingBodyWithBlock
è obsoleto. Come posso ottimizzare il codice per conformarsi agli standard AFNetworking 3.0?AF Richiesta multipartite 3.0
Come posso scaricare le immagini con il codice @Stefan? –
sviluppatore @ios, è possibile utilizzare il metodo AFNetworking da AFNetworking + UIImageView setImageWithUrl – Stefan