I working on a project where I will use these services combined:
- AFNetworking
- Google Places API web service
- Parse
Trying to follow the best practices mentioned in the AFNetworking Docs :
Developers targeting iOS 7 or Mac OS X 10.9 or later that deal extensively with a web service are encouraged to subclass AFHTTPSessionManager, providing a class method that returns a shared singleton object on which authentication and other configuration can be shared across the application.
So, I have created a singleton networking manager like :
MyAppAPI.h
#import <Foundation/Foundation.h>
#import "AFHTTPSessionManager.h"
#import "AFNetworking.h"
@interface MyAppAPI : AFHTTPSessionManager
+(MyAppAPI *)sharedInstance;
@end
MyAppAPI.m
#import "MyAppAPI.h"
@implementation MyAppAPI
+(MyAppAPI*)sharedInstance
{
static MyAppAPI* sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[MyAppAPI alloc] initWithBaseURL:[NSURL URLWithString:kROOT_URL]];
});
return sharedInstance;
}
@end
where kROOT_URL
is "https://maps.googleapis.com/maps/api/place/nearbysearch"
Usage:
NSDictionary *params = @{@"some_param":@"some_value" };
[[MyAppAPI sharedInstance] GET: @"/json"
parameters:params
success:^(NSURLSessionDataTask *task, id responseObject){
} failure:^(NSURLSessionDataTask *task, NSError *error)
{
}];
Now, it works only for Google Places API we service calls.
- What if I want to use another web service, how to change the
baseURL
, if it's not possible what is the best practice to deal with this situation ? - How to use the manager to work with Parse ? any good practice.
I need best practices advises to combine Parse, AFNetworking and Google Places API web service.
Already found : changing AFNetworking baseURL but not helping