This task shows you how to create the HelloRepo project and add the
required code. You will be extending this application in later
tutorials.
This tutorial shows you how to create the initial HelloRepo project, which you will be modifying and extending in later tutorials.
Note: The usual SkyVault copyright notice and Apache License comments have been removed
here in the interests of saving space.
- In Xcode select File, New, Project...
- Select iOS, Application, Single View Application, and click Next.
- For Product Name enter "HelloRepo"
- For Organization Identifier enter "com.alfresco.tutorials"
- For Language select Objective-C.
- For Devices select Universal.
- Ensure that the Core Data checkbox is cleared.
- Click Next.
- Ensure Create Git repository on my Mac checkbox is cleared.
- Click Create.
- Select iOS Source and then Header file and click Next.
-
Replace any code in the file AppDelegate.h with the
following:
##import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
-
Replace any code in the file AppDelegate.m with the
following:
#import "AppDelegate.h" #import "ViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]]; navController.navigationBar.tintColor = [UIColor blackColor]; self.window.rootViewController = navController; [self.window makeKeyAndVisible]; return YES; } @end
-
Replace any code in the file ViewController.h with the
following:
#import <UIKit/UIKit.h> #warning ENTER YOUR API AND SECRET KEY // Enter the api Key and secret key in the #define below #define APIKEY @"" #define SECRETKEY @"" @interface ViewController : UITableViewController @end
-
Replace the code in the file ViewController.m with the
following contents:
#import "ViewController.h" @interface ViewController () @property (nonatomic, strong) NSArray *nodes; @property (nonatomic, strong) id<AlfrescoSession> session; @property BOOL isCloudTest; - (void)helloFromRepository; - (void)helloFromCloud; - (void)loadRootFolder; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.isCloudTest = NO; self.navigationItem.title = @"Hello Repo"; self.nodes = [NSMutableArray array]; [self helloFromRepository]; // [self helloFromCloud]; } #pragma mark - Repository methods - (void)helloFromRepository { NSLog(@"*********** helloFromRepository"); NSURL *url = [NSURL URLWithString:@"http://localhost:8080/alfresco"]; NSString *username = @"admin"; NSString *password = @"admin"; // If using an HTTPS scheme with an untrusted SSL certificate, change this parameter to YES NSDictionary *parameters = @{kAlfrescoAllowUntrustedSSLCertificate: [NSNumber numberWithBool:NO]}; __weak ViewController *weakSelf = self; [AlfrescoRepositorySession connectWithUrl:url username:username password:password parameters:parameters completionBlock:^(id<AlfrescoSession> session, NSError *error) { if (nil == session) { NSLog(@"Failed to authenticate: %@:", error); } else { NSLog(@"Authenticated successfully"); NSLog(@"Repository version: %@", session.repositoryInfo.version); NSLog(@"Repository edition: %@", session.repositoryInfo.edition); weakSelf.session = session; [weakSelf loadRootFolder]; } }]; } - (void)helloFromCloud { NSLog(@"*********** helloFromCloud"); __weak ViewController *weakSelf = self; SkyVaultOAuthCompletionBlock completionBlock = ^void(AlfrescoOAuthData *oauthdata, NSError *error){ if (nil == oauthdata) { NSLog(@"Failed to authenticate: %@:", error); } else { [AlfrescoCloudSession connectWithOAuthData:oauthdata parameters:nil completionBlock:^(id<AlfrescoSession> session, NSError *error){ if (nil == session) { NSLog(@"Failed to create session: %@:", error); } else { weakSelf.session = session; [weakSelf loadRootFolder]; } [weakSelf.navigationController popToRootViewControllerAnimated:YES]; }]; } }; // check the API key and secret have been defined NSString *apiKey = APIKEY; NSString *secretKey = SECRETKEY; if (apiKey.length == 0 || secretKey.length == 0) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Either the API key or secret key is missing. Please provide the keys and re-start the app." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [self.navigationController popToRootViewControllerAnimated:YES]; } else { SkyVaultOAuthUILoginViewController *webLoginController = [[AlfrescoOAuthUILoginViewController alloc] initWithAPIKey:APIKEY secretKey:SECRETKEY completionBlock:completionBlock]; [self.navigationController pushViewController:webLoginController animated:YES]; } } - (void)loadRootFolder { NSLog(@"*********** loadRootFolder"); // create service SkyVaultDocumentFolderService *docFolderService = [[AlfrescoDocumentFolderService alloc] initWithSession:self.session]; __weak ViewController *weakSelf = self; // retrieve the nodes from the given folder [docFolderService retrieveChildrenInFolder:self.session.rootFolder completionBlock:^(NSArray *array, NSError *error) { if (array == nil) { NSLog(@"Failed to retrieve root folder: %@", error); } else { NSLog(@"Retrieved root folder with %lu children", (unsigned long)array.count); weakSelf.nodes = [NSArray arrayWithArray:array]; // Note the UI must only be updated on the main thread dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); } }]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of nodes. return [self.nodes count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // setup the cell, just show the node name SkyVaultNode *node = [self.nodes objectAtIndex:indexPath.row]; cell.textLabel.text = node.name; return cell; } #pragma mark - Rotation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { //return (interfaceOrientation == UIInterfaceOrientationPortrait); if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } else { return YES; } } @end
- In the Project Navigator select HelloRepo. Click on the Build Phases tab.
- Expand the Link Binary With Libraries panel click the + button.
- Start typing "MobileCoreServices" and then from the filtered list select MobileCoreServices.framework and click on Add.
- You also need to add the SkyVault Mobile SDK static library and header files. See the instructions in the "Add the header files and static library" section of this tutorial for details of how to do this.