Making operation calls

This is an example about how we can perform API operation callsĀ in our app by using topoos iOS SDK.

Add import of class we need to use

To make calls to the operations we will need import the corresponding classes in our project.

#import "ViewController.h"
#import <SDKtopoos/TOS_POIOps.h>
#import <SDKtopoos/TOS_PositionsOps.h>
#import <SDKtopoos/TOS_TrackOps.h>
#import <SDKtopoos/TOS_RulesOps.h>
#import <SDKtopoos/TOS_UsersOps.h>
#import <SDKtopoos/TOS_CheckinOps.h>

#import <SDKtopoos/TOS_POICategoriesOps.h>
#import <SDKtopoos/TOS_POIWarningOps.h>
#import <SDKtopoos/TOS_WebmapOps.h>
#import <SDKtopoos/TOS_ResourcesOps.h>
#import <SDKtopoos/TOS_ImagesOps.h>

Get a Access Token

To use several operations we will need to get the Access Token for the application or generate one.

//AcessToken (after login or after create a valid token)

TOS_AccessTokenOAuth* accesstoken=[TOS_AccessTokenOAuth GetAccessToken];
NSLog(@"Token: %@", [accesstoken getAccessToken]);

Make the operation calls

Finally, we will check the token and execute the operation.

  • Synchronous.
//Use synchronous
if([accesstoken isValid]){
    TOS_User * user=[TOS_UsersOps Get:accesstoken andUserID:@"me"];
    if(user!=nil){
        NSLog(@"User: %@",[user getName]);
    }
}
  • Asynchronous.
//Use asynchronous
dispatch_queue_t queue = dispatch_queue_create("com.yourdomain.yourappname",NULL)
dispatch_async(queue, ^{
    //code to executed in the background
    TOS_User * user2=nil;
    if([accesstoken isValid]){
        user2=[TOS_UsersOps Get:accesstoken andUserID:@"me"];
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        //code to be executed on the main thread when background task is finished
        if (user2!=nil){
            NSLog(@"User: %@", [user2 getName]);
        }
    });
}