The Alfresco iOS SDK_rev

advertisement
The Alfresco iOS SDK
Gi Lee (Zia Consulting)
Peter Schmidt (Alfresco)
Alfresco iOS SDK – Intro
Who we are
Gi Lee
Peter Schmidt
Zia Consulting
Alfresco Software
(Technical Architect)
(Senior iOS Engineer)
gi.lee@ziaconsulting.com
peter.schmidt@alfresco.com
Objective-C CMIS library
Alfresco SDK library & samples apps
Alfresco iOS SDK – Intro
What we will talk about
Gi Lee
Peter Schmidt
CMIS library (Apache)
Alfresco SDK
• Part of iOS Alfresco SDK
• How to get and install it
• Architecture & Design
• Architecture & Design
• Code examples
• Code examples
• Demo of Sample app
• How to get support
ObjectiveCMIS – The Basics
Introducing the library
• Low level API for CMIS
• Static Cocoa Touch Library
• No third-party API’s
• Asynchronous
• AtomPub binding support
ObjectiveCMIS – The Basics
The Xcode project
CMIS API Library
Cocoa Touch Static Library
Documentation
AppleDoc DocSet
ObjectiveCMIS – The Basics
An open source project
• Open source Objective-C implementation of CMIS
• Apache 2.0 license
• Collaborative project
• Recently accepted by Apache Chemistry
ObjectiveCMIS – The Basics
iOS specifics
Naming Convention
• ObjectiveCMIS code prefixed with CMIS
Error Handling
• No exceptions in iOS, use NSError
• As per Apple standard:
“NSError object remains nil if method call is successful.”
Always check!
Automated Reference Counting
• No more retain, release, autorelease on object
Blocks
• Used to handle asynchronous
requests & callbacks
ObjectiveCMIS – The Basics
What are blocks?
• Closures for Objective-C, C, C++
• Introduced in iOS 4
• Ad hoc functionality that can be passed like
parameters
• Good for callbacks!
ObjectiveCMIS – The Basics
Asynchronous handling
// Completion Block
If(nil != session)
{
self.session = session;
…
}
else
{
/* error handling */
}
CMIS API
Repository
ObjectiveCMIS – Design & Architecture
The API layers
Client Object API
• Object Oriented
• Easy to Use
• Built-In LinkCache
Client Binding API
• Low-Level API
• Follows the CMIS
Domain Model
• More Control
• Clunky to Implement
ObjectiveCMIS – Design & Architecture
Client API common interface
ObjectiveCMIS - Getting Started
How do I use it?
Added as a binary + Headers
•
•
Simple
Need to generate binary
Added to a Xcode Workspace
•
•
Extends workflow scope
Provides full access to source code
ObjectiveCMIS – Getting Started
… as a Generated Binary + Headers
1. Execute the script build_universal_lib.sh
2. Add generated build output folder to your project
3. Configure the build target dependency
•
Link  libObjectiveCMIS.a
4. Configure the Target Build Settings
•
•
User Header Search Paths =
“$(BUILT_PRODUCTS_DIR)” [recursive]
Other Linker Flags = “-ObjC –all_load”
ObjectiveCMIS – Getting Started
… added to an Xcode workspace
1. Open/Create Xcode Workspace
1. Add the ObjectiveCMIS project to the workspace
1. Configure the build target dependency
•
Link  libObjectiveCMIS.a
1. Configure the target Build Settings
•
•
User Header Search Paths =
“$(BUILT_PRODUCTS_DIR)” [recursive]
Other Linker Flags = “-ObjC –all_load”
2. Configure the project build scheme
(optional)
ObjectiveCMIS – Getting Started
In a nutshell
1. Add ObjectiveCMIS to your project
2. Link the library libObjectiveCMIS.a
3. Configure the target Build Settings
•
•
User Header Search Paths =
“$(BUILT_PRODUCTS_DIR)” [recursive]
Other Linker Flags = “-ObjC –all_load”
ObjectiveCMIS – Documentation
http://gentlebytes.com/appledoc
ObjectiveCMIS – Documentation
Generating the documentation
Setup AppleDoc
• Clone the source from Github
•
https://github.com/tomaz/appledoc
• Install Appledoc using the script install-appledoc.sh
install-appledoc.sh –b /usr/bin/ -t ~/Library/Application\ Support/appledoc
Generate Documentation
• Open the ObjectiveCMIS Xcode project
• Run the target “Documentation”
ObjectiveCMIS – Code Example
Setup a CMIS session
// Define session parameters
CMISSessionParameters *params = [[CMISSessionParameters alloc]
initWithBindingType:CMISBindingTypeAtomPub];
params.atomPubUrl = [NSURL URLWithString:cmisAtompubLocation];
params.username = @”devconUser";
params.password = @”devconPassword";
params.repositoryId = self.repoId;
// Connect session
[CMISSession connectWithSessionParameters:sessionParams
completionBlock:^(CMISSession *session, NSError *error)
{
if (session == nil)
{
// Error handling code goes here
// Dig into error object to determine cause
}
else {
// CMISSession successfully connected
self.session = session;
}
}];
ObjectiveCMIS – Code Example
Get the root collection
[self.session retrieveRootFolderWithCompletionBlock:
^(CMISFolder *folder, NSError *error)
{
if (nil == folder)
{
// Error handling code goes here
// Dig into error object to determine cause
}
else
{
/* Folder object is the root */
self.rootFolder = folder;
}
}];
Objective CMIS – Code Example
Query
// Create Query Completion Block
void(^queryCompBlock)(CMISPagedResult *pagedResult, NSError *error);
queryCompBlock = ^(CMISPagedResult *pagedResult, NSError *error)
{
if (nil == pagedResult)
{
// Error handling code goes here
// Dig into error object to determine cause
}
else
{
/* Process the Paged Results */
}
};
NSString *queryStr = @"SELECT * FROM cmis:document WHERE CONTAINS('DevCon')";
// Execute Query
[self.session query:queryStr
searchAllVersions:NO
completionBlock:queryCompBlock];
ObjectiveCMIS
How do I get the library?
Alfresco / Objective-CMIS
https://github.com/alfresco/Objective-CMIS
Alfresco iOS SDK – The Basics
What is included?
Sample Apps
Mobile API Library
Including Objective CMIS
library
Documentation
(appledoc docset)
Alfresco iOS SDK – The Basics
How do I get the SDK?
• Download it from our website
• https://developer.alfresco.com/mobile
• From our public github repository
• https://github.com/Alfresco/alfresco-ios-sdk
• Online documentation/tutorial
• https://developer.alfresco.com/resources/alfresco/pdf/iO
S-SDK-1.0.pdf
Alfresco iOS SDK – The Basics
How do I install it?
1. Unzip alfresco-ios-sdk.zip file
2. Open XCode
3. File menu
4. Add files to…
DONE ✔
Alfresco iOS SDK - Architecture & Design
Design Principles
• Session-Service-Model
• Session for
connections
• Services for requests
between app & server
• Model to handle data
Asynchronous calls
• Blocks
• To handle
asynchronous
behaviour
Alfresco in
the Cloud
Repository
Alfresco iOS SDK - Architecture & Design
Overall Structure
Alfresco iOS SDK - Architecture & Design
Session
Alfresco iOS SDK - Architecture & Design
Services
Alfresco iOS SDK – Coding
Create a Session
#import “AlfrescoRepositorySession.h”
…
@property (nonatomic, strong) id<AlfrescoSession> session;
…
[AlfrescoRepositorySession
connectWithUrl:url
username:username
password:password
parameters:nil
completionBlock:^(id<AlfrescoSession>session, NSError *error){
if(nil == session)
 FAILURE  error handling
else
weakSelf.session = session;
}];
Alfresco iOS SDK – Coding
Blocks Everywhere
•Used in most methods of Alfresco SDK
•Used to encapsulate asynchronous REST API/CMIS calls
EXAMPLE
•Get the children in the root folder
#import “AlfrescoDocumentFolderService.h”
…
AlfrescoDocumentFolderService *folderService =
[[AlfrescoDocumentFolderService alloc] initWithSession:self.session];
[folderService retrieveChildrenInFolder:self.session.rootFolder
completionBlock:^(NSArray *children, NSError *error){
if(nil != children)
{
…<put your code handling folder children here>
}
}];
Alfresco iOS SDK – Coding
What about connecting to Cloud?
Alfresco Cloud uses OAuth 2 for authenticating
1. Register with Cloud to get an API key and Secret key
2. Provide both in your APP
3. Alfresco iOS SDK provides a set of helper classes
•
AlfrescoOAuthLoginViewController
• Connects to login page
• Handles the OAuth dance
• Returns access/refresh token as part of
AlfrescoOAuthData
Alfresco iOS SDK – Coding
Cloud OAuth Dance
Alfresco iOS SDK – Coding
Connecting to Alfresco in the Cloud
#import “AlfrescoCloudSession.h”
#import “AlfrescoOAuthData.h”
#import “AlfrescoOAuthDataLoginViewController.h”
…
AlfrescoOAuthCompletionBlock completionBlock =
^void(AlfrescoOAuthData *oauthData, NSError *error){
if(nil != oauthData)
{
[AlfrescoCloudSession connectWithOAuthData:oauthData parameters:nil
completionBlock:(id<AlfrescoSession>session, NSError *error{
<your session handling goes here>
}];
}
};
AlfrescoOAuthLoginViewController *controller = [[AlfrescoOAuthLoginViewController alloc]
initWithAPIKey:apiKey secretKey:secretKey completionBlock:completionBlock];
[self.navigationController pushViewController:controller animated:YES];
Alfresco iOS SDK – Coding
Demo time
Alfresco iOS SDK – The Rest
What about support – CMIS library?
• Apache mailing list
• dev@chemistry.apache.org
• Subscribe & archive:
•
http://mail-archives.apache.org/mod_mbox/chemistry-dev/
• Raise tickets in JIRA
• https://issues.apache.org/jira/browse/CMIS
• Component: objectivecmis
• (you’d need an account for that)
• Apache Chemistry website
• http://chemistry.apache.org
Alfresco iOS SDK – The Rest
What about support – Alfresco SDK?
• Alfresco Forums
• https://forums.alfresco.com
• Look for Alfresco Mobile
• Raise tickets in JIRA
• https://issues.alfresco.com/jira/browse/MOBSDK
• (you need a JIRA account for this)
•
•
•
•
Project: Mobile SDK
Components: API
Affects Version: iOS x.x
Assignee: Mobile Team unassigned
• Have Support Agreement?
• Contact Support
Alfresco iOS SDK – The Rest
Feedback, Q&A?
• Feedback
• Regarding SDK
• Regarding tutorials
• Your Questions answered
Download