. . .

iOS Quickstart

    In this Tutorial you will learn to:

    • set up a backend with a custom class “Task”.

    • deploy the backend

    • create a simple iOS project with the generated SDK

    • set up the connection to the backend and create a User

    • view the data in your backend

    • create Task objects in Objective-C and store it in the backend

    • query data from the backend

    1. Sign Up or log in with your existing account here to start using ApiOmat.

    images/download/attachments/12649002/gettingStarted_login.png

    2. Enter a unique name for your app's backend (e.g. “YourNameTaskManager”).

    Since we plan to give developers the opportunity to share projects application names must be unique in the system. You do not need any of the predefined modules in this tutorial.

    images/download/attachments/12649002/taskManager_newBackend.png

    3. Create a new module by going to the Module Market and clicking on "New Module" in the submenu. Give it a name and description and click "CREATE".

    images/download/attachments/12649002/newNmModule.png

    4. Go to the "Class Editor"- Tab to create a class in our backend. You will be asked for a class name after entering the tab. Just call the first class "Task". Scroll down to the attributes and add a String “description”, a Number “done” and a Date “untilDate”.

    images/download/attachments/12649002/task_addClassAttributes.png

    5. Deploy your Backend by pressing the “Deploy”-Button.

    6. Go to the SDK Tab and download the Objective-C library by pressing "Download SDK" button. You will get a zip file with your generated classes and all necessary libraries.

    images/download/attachments/12649002/task_downloadSDK.png

    7. Go to your Xcode and start a new Project under File->New->Project. Choose “Single View Application”, click next and enter a “Product Name”, e.g.: "TestTaskManager" (In older versions of Xcode: Make sure that “Use Automatic Reference Counting” is checked). Then click next, select a folder for your project and create it.

    images/download/attachments/12649002/SetupXcode.png

    8.Now move the downloaded and unzipped library files to your project by dragging the directory “apiomat” to your “Project Navigator”.

    images/download/attachments/12649002/Copylib1.png

    9. Select "Copy items if needed" and tick the radio-button for "Create groups" at the "Added folders"-Option

    images/download/attachments/12649002/Copylib2.png

    10.Open “Build Settings”, switch to “All” on the left side and add at “Other Linker Flags” “-all_load” and if you targeting iOS version less than 5.0 also add “-fobjc-arc”

    images/download/attachments/12649002/addLinkerFlags.png

    11. Now you are ready to go. In the class “AppDelegate.h” add the import:

    #import "User.h"
    #import "Datastore.h"

    and a new property:

    @property (strong, nonatomic) AOMUser *user;

    12. We configure Datastore and user in “AppDelegate.m” file.

    Add user credentials by replacing the text with your own and configure DataStore in method application:didFinishLaunchingWithOptions. Don’t forget to synthesize user property.

    @synthesize user;
     
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    user = [[AOMUser alloc] init];
    [user setUserName:@"<username>"];
    [user setPassword:@"<password>"];
     
    //Configure Datastore with user credentials
    [AOMDatastore configureWithUser:user];
     
    @try {
    [user loadMe];
    }
    @catch (NSException *exception) {
    //There is no User with this name on server so add one
    [user save];
    }
     
    return YES;
    }

    13. Congratulations! Your backend and your connection are working now. Have a look at the Data-Tab of your Dashboard to see that the created user in your Backend.

    images/download/attachments/12649002/task_newUserCreated.png

    14. Now let’s play around with the Task-Class. Add the following code to some of your view controllers (e.g. ViewController.m). The best place is the viewDidLoad method. We will create 2 objects of class “Task” (Be sure that you imported the “Task.h” header file).

    - (void)viewDidLoad
    {
    [super viewDidLoad];
    Task *firstTask = [[Task alloc] init];
    [firstTask setDescription:@"Drink coffee"];
    //Set task to "done"
    [firstTask setDone:1];
    //Save in backend
    [firstTask save];
     
    //Add another task
    Task *secondTask = [[Task alloc] init];
    [secondTask setDescription:@"Eat to lunch"];
    //Task is already undone
    [secondTask setDone:0];
    [secondTask save];
    }

    15. Now let’s request all tasks from the ApiOmat backend. We add this after the save statement of the second task.

    We use a common method to request list of tasks and get back an array.

    NSMutableArray *tasks = [Task getWithQuery:@""];

    16. Finally, we will use a query to get back all non-done tasks.

    NSMutableArray *undoneTasks = [Task getWithQuery:@"done==0"];
     
    for (Task *t in undoneTasks) {
    NSLog(@"Description: %@", [t description]);
    }

    * link only available in Enterprise Documentation