. . .

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

    • have a look at 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 login with your existing account here to start using backend as a service.

    images/download/attachments/2163089/apiOmat_login.PNG

    2. Now enter a unique name for your application 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/2163089/apiOmat_UsingServerCode_AppName.PNG

    3. 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/2163089/apiOmat_Tutorial_Taskmanager_Class_Editor.PNG

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

    5. Go to 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/2163089/apiOmat_Tutorial_Taskmanager_SDK2.PNG

    6. 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/2163089/SetupXcode.png

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

    images/download/attachments/2163089/Copylib1.png

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

    images/download/attachments/2163089/Copylib2.png

    9.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/2163089/addLinkerFlags.png

    10. 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;

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

    Add user credentials by replacing and 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;
    }

    12. 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/2163089/apiOmat_Tutorial_Taskmanager_Data.PNG

    13. 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];
    }

    14. 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:@""];

    15. At last we want 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