Accela iOS SDK installer package provides SDK and Xcode templates to quickly create iOS apps. SDK provides mechanism for user login, getting tokens, using tokens to interact with APIs and logging off users. When you create your app using the Xcode template, the code for login function is generated automatically.
To use Accela iOS SDK
1. Initialize SDK
The following code snippet demonstrates how to initialize an Accela iOS instance.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Init window
self.window = AM_AUTORELEASE([[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds ]]);
[self.window makeKeyAndVisible];
//Init AccelaMobile instance with AppID and AppSecret
NSString *appID = [[NSBundle mainBundle] objectForInfoDictionaryKey:@”Accela App ID"];
NSString *appSecret = [[NSBundle mainBundle] objectForInfoDictionaryKey:@”Accela App Secret"];
if (!appID || !appSecret || [appID isEqualToString:@""] || [appSecret isEqualToString:@""]) {
UIAlertView *alertView = AM_AUTORELEASE([[UIAlertView alloc]initWithTitle:nil message:@”You need to set App Id and App Secret in building settings page." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]);
[alertView show];
}
else
{
self.accelaMobile = AM_AUTORELEAE([[AccelaMobile alloc]initWithAppId:appID withAppSecret:appSecret
andDelegate:self withAuthHost:@"https://auth.accela.com" withApiHost:@"https://apis.accela.com"]);
//Set Environment type, default is PROD.
//self.accelaMobile.amEnvironmentType = ENVIRONMENT_TEST;
#ifdef DEBUG
[AMLogger setLogLevel:AMLogVerbose];
#endif
2. Invoke user login dialogs and receive access token
The following code demonstrates how to launch Accela login dialogs. After a user logs in and authorizes the app, the app receives the user access token.
You can replace the following permission scopes with the scopes described in API Reference.
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (![appDelegate.accelaMobile isSessionValid])
{
NSArray *permissions = [NSArray
arrayWithObjects:@"get_records",@"get_record",@"search_records",@"create_record",@"reverse_geocode",@"get_ref_record_types",@"get_record_contacts",@"get_record_documents",@"get_document",@"get_thumbnail",@"create_record_document",@"get_record_documents",@"get_document",@"get_thumbnail",@"create_record_document",@"get_record_comments", nil];
[appDelegate.accelaMobile authorize:permissions withAgency:@"ISLANDTON"];
}
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
[self.accelaMobile handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
return YES;
}
3. Interact with APIs
The following code snippet demonstrates how to call an API to get a list of records, and defines a request delegate to handle the returned response asynchronously.
- (IBAction)getRecords:(id)sender {
NSDictionary *urlParams = [NSDictionary dictionaryWithObjectsAndKeys:
@"0", @"offset",
@"10", @"limit",
nil];
AMRequest *request = [self.accelaMobile requestWithPath:@"/v4/vrecords"
urlParams: urlParams
requestDelegate: self];
request.tag = TAG_GET_RECORDS;
request.amOwnerView = self.view;
}
4. Log off
The following code snippet demonstrates how to log off the current user.
- (IBAction)logout:(id)sender {
[self.accelaMobile logout];
}