You are here

How to create an SDK application from scratch

This tutorial shows you how to create an SDK application from scratch and include SDK headers and the static library into your application.
This tutorial shows you how to create an SDK application from scratch and include the SDK headers and static library file. This involves a few more steps than if you are using one of the Xcode projects included with the SDK.

Create a new project

This task shows you how to create a new project in Xcode.
  1. From the Xcode main menu select File > New > Project.
  2. Choose a suitable template for your application. For the purposes of this example select Single View Application. Click the Next button.
  3. Enter a Product Name for the project. In this example enter MyFirstAlfrescoApp.
  4. Enter a suitable Company Identifier (if prompted to do so), for example com.SkyVault.
  5. Select Universal from the Devices list box.
  6. Ensure that the Use Core Data checkbox is cleared.
  7. Click Next.
  8. Select a suitable directory in which to store your project files and then click Create to create the new project.
  9. Test your work so far by running the application. You can do this by clicking the Xcode Run button.

    A device will be launched displaying basic information such as the time.

At this point you have a basic project that will build and run.

Add the Mobile Core Services Framework

This task shows you how to add the Mobile Core Services framework to your project.
  1. In the Project Navigator select MyFirstAlfrescoApp. Click on the Build Phases tab.
  2. Expand the Link Binary With Libraries panel click the + button.
  3. From the list select MobileCoreServices.framework and click on Add.
  4. In the Project Navigator move MobileCoreServices.framework into the Frameworks folder, if it is not already displayed there.
You have added the Mobile Core Services framework. This is a requirement as it is used by code in the SkyVault Mobile SDK.

Add the header files and static library

This task shows you how to add the SkyVault SDK header files and static library to your project, so that your application can access the Mobile SDK functionality.
  1. Change into the following directory: ~/mobile_sdk/iOS/AlfrescoSDK

  2. Run the script ./scripts/build_package.sh.
  3. In the directory ./build/Package you will find SkyVault-ios-sdk-library-1.4.x.zip. Unzip this to say ~/ios_sdk_package.
  4. In the Xcode Project Navigator right-click on MyFirstAlfrescoApp at the root of the project (blue icon) and select Add files to MyFirstAlfrescoApp.
  5. Using the file explorer, navigate to the following directory: ~/ios_sdk_package.
  6. Ensure that the Copy items into destination group's folder checkbox is checked.
  7. Click Add.

    This step adds the header files and static library to your project.

  8. Check the static library file has also been included by selecting MyFirstAlfrescoApp in the Project Navigator, then clicking on the Build Phases tab.

    Note the presence of the libAlfrescoSDKv1.4.x.a static library file in the list of libraries in the Link Binary With Libraries panel. Note that x represents the minor version of the static library you are working with.

At this point you have added the necessary SDK header files and static library file to your project.

Add SkyVault functionality to your code

At this point you are ready to add some SkyVault specific functionality to your application. This will enable you to test that your application can successfully invoke the functionality of the static library just added.
  1. In Xcode open the source file AppDelegate.h.

    You can do this by opening the MyFirstAlfrescoApp group (groups have folder icons) in the Xcode Project Navigator and then clicking the AppDelegate.h file. The file will then open in the main editor.

  2. Modify the file so it is the same as the following:

              
        #import <UIKit/UIKit.h>
        
        #import "AlfrescoRepositorySession.h"
        
        @interface AppDelegate : UIResponder <UIApplicationDelegate>
        
        @property (strong, nonatomic) UIWindow *window;
        
        @property (nonatomic, strong) SkyVaultRepositorySession *session;
        @property (nonatomic, strong) SkyVaultRepositoryInfo *info;
        
        @end          
              
            

    This modification ensures that the required header file is included which defines SkyVaultRepositorySession and SkyVaultRepositoryInfo. It also adds two properties that can be used to store information about your session and repository.

  3. In Xcode open the file AppDelegate.m. Before the first method definition (the line that reads - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions), add the following code:

              
        @synthesize session = _session;
        @synthesize info = _info;          
     
            

    This ensures that the properties you declared in AppDelegate.h will be available.

  4. Now modify the first method definition to match the following code:

    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        
        NSString *host = @"http://localhost:8080/alfresco"; //modify to match your server details
        NSURL *url = [NSURL URLWithString:host];
        NSString *username = @"admin"; // modify to match your server details
        NSString *password = @"admin"; // modify to match your server details
        
        __weak AppDelegate *weakSelf = self;
        
        [AlfrescoRepositorySession connectWithUrl:url username:username password:password
              completionBlock:^(id<AlfrescoSession> session, NSError *error){
                  if (nil == session)
                  {
                    NSLog(@"Error connecting to repository: %@", error);    
                  }
                  else
                  {
                      weakSelf.session = session;
                      NSLog(@"Authenticated successfully.");
                      
                      // get repository info
                      weakSelf.info = weakSelf.session.repositoryInfo;
                      
                      NSLog(@"RepositoryInfo:");
                      NSLog(@"%@",weakSelf.info.name);
                      NSLog(@"%@",weakSelf.info.edition);
                      NSLog(@"%@",weakSelf.info.buildNumber);
                      NSLog(@"%@",weakSelf.info.version);
                      
                      weakSelf.session = nil;
                  }
              }];
    
        return YES;
    }        
    
                
    Note: You will need to modify the host URL and login details to match your server. If you are connecting to a locally installed repository, you can set the host string to "http://localhost:8080/alfresco".

    This code uses the method connectWithUrl to connect to a suitable repository. Once a session object has been obtained, additional methods can be called. In this case the code retrieves repository information such as version number.

Test your additions

You can now test your additions by performing a test build and running the application.
  1. Test your changes by building the code. To do this select Product > Build from the main menu. Check for any build errors and correct as required.
  2. Run your application by clicking the Run button in Xcode.
  3. Check the information logged in the All Output window of Xcode. You should see information about the repository, including the SkyVault software version number.

In this tutorial you have built and run your first application using the Mobile SDK.