Closed loretoparisi closed 9 years ago
@loretoparisi Not to disagree, but you just suggested replacing a working piece of third party code with a deprecated api. I don't think that is a solid path forward.
If you wanted to eliminate the third party dependency with a built in set of Classes, I might suggest NSURLSession
. Apple has directed developers to use this new set of apis for networking calls in place of the old NSURLConnection
.
Here is a a very rough implementation of what it could look like:
#import <Foundation/Foundation.h>
@interface SonosTask : NSObject
- (NSURLSessionDataTask*)makeApiCallWithData:(NSData *)data andCompletion:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completion;
@end
@implementation SonosTask
- (NSURLSessionDataTask *)makeApiCallWithData:(NSData *)data andCompletion:(void (^)(NSData *data, NSURLResponse *respone, NSError *error))completion {
NSURLSession *session = [NSURLSession sharedSession];
NSMutableRequest *request = [NSMutableRequest new];
request.HTTPMethod = @"POST" // or whatever HTTP method is necessary for the api call
request.HTTPBody = data;
return [session dataTaskWithRequest:request completionHandler:completion];
}
@end
And the use of this object would look something like this:
SonosTask *sonosTask = [SonosTask new];
[[sonosTask makeApiCallWithData:@{} andCompletion:^(NSData *data, NSURLResponse *response, NSError *error) {
if (!error) {
// do something with data returned here
} else {
// handle error case here
}
}] resume];
@endoze thanks that works better, the basic idea was this :)
Since
AFNetworking
is used to execute a simple HTTP GET, I suggest to remove any dependencies of AFNetworking and replacing it withNSURLConnection
:(SonosController.m)
like
where