Create a new project
- From the Xcode main menu select .
- Choose a suitable template for your application. For the purposes of this example select Single View Application. Click the Next button.
- Enter a Product Name for the project. In this example enter MyFirstAlfrescoApp.
- Enter a suitable Company Identifier (if prompted to do so), for example com.SkyVault.
- Select Universal from the Devices list box.
- Ensure that the Use Core Data checkbox is cleared.
- Click Next.
- Select a suitable directory in which to store your project files and then click Create to create the new project.
-
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.
Add the Mobile Core Services Framework
- In the Project Navigator select MyFirstAlfrescoApp. Click on the Build Phases tab.
- Expand the Link Binary With Libraries panel click the + button.
- From the list select MobileCoreServices.framework and click on Add.
- In the Project Navigator move MobileCoreServices.framework into the Frameworks folder, if it is not already displayed there.
Add the header files and static library
-
Change into the following directory:
~/mobile_sdk/iOS/AlfrescoSDK
- Run the script ./scripts/build_package.sh.
- In the directory ./build/Package you will find SkyVault-ios-sdk-library-1.4.x.zip. Unzip this to say ~/ios_sdk_package.
- In the Xcode Project Navigator right-click on MyFirstAlfrescoApp at the root of the project (blue icon) and select Add files to MyFirstAlfrescoApp.
- Using the file explorer, navigate to the following directory: ~/ios_sdk_package.
- Ensure that the Copy items into destination group's folder checkbox is checked.
-
Click Add.
This step adds the header files and static library to your project.
-
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.
Add SkyVault functionality to your code
-
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.
-
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.
-
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.
-
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
- Test your changes by building the code. To do this select from the main menu. Check for any build errors and correct as required.
- Run your application by clicking the Run button in Xcode.
- 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.