Evernote iOS SDK
introduction
GoLater Developer MaoYang
Twitter @GoLaterApp E-Mail my@esast.com
About Me
• 5 years Mac Device Driver/Application developer
• 10 years Enterprise grade software development
tools consulta...
Today’s Goal
• iOS App development setup -> Xcode 5.x +
Cocoapods
• Evernote iOS SDK introduction
• 5 Evernote iOS SDK pra...
Evernote SDK
• https://github.com/evernote/evernote-sdk-ios
• Evernote Cloud SDK detail spec ->http://
dev.evernote.com
EasyShare for Evernote
• Practice-1 : Development environment setup and
using Evernote OAuth API
• Practice-2 : List all o...
Practice-1 SDK setup &
OAuth
• Xcode 5.x +
• cocoapods installation—> sudo gem install
cocoapods
• Create an iOS project n...
Evernote SDK setup
• create a file named Podfile in your root of project 

plateform :iOS , ‘7.0’

pod ‘Evernote-SDK-iOS’, ‘...
Setup URL Scheme
Initialize SDK -1
#import "EvernoteSDK.h"!
!
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOption...
Initialize SDK -2
(BOOL)application:(UIApplication *)application openURL:(NSURL
*)url sourceApplication:(NSString *)source...
Initialize SDK-3
- (void)applicationDidBecomeActive:(UIApplication
*)application!
{!
// Restart any tasks that were paused...
SingleTon need to know in
this practice
• [EvernoteSession sharedSession], responsible
for login/logout, login status
UI would look like
OAuth
• if(![[EvernoteSession sharedSession]
isAuthenticated){}
• [[EvernoteSession sharedSession]
authenticateWithViewCon...
Sample code
• http://goo.gl/KzUK8W
Practice-2 List all of your
own notebooks
SingleTon & Class need to
know in this practice
!
• [EvernoteStore noteStore] -> For ever note
related operation
• EDAMNot...
Query Notebook
• [[EvernoteNotesStore noteStore]
listNotebooksWithSuccess:^(NSArray *notebooks){
for(EDAMNotebook *noteboo...
Sample code
• http://goo.gl/I9fNpb
Practice-3 List all of notes in
a notebook
Classes need to know in this
practice
• EDAMNoteFilter -> setup filter condition for query
notes
• EDAMNotesMetadataResultS...
Filter
• EDAMNoteFilter *filter = [[EDAMNoteFilter alloc]
initWithOrder:NoteSortOrder_UPDATED
ascending:NO words:nil notebo...
Metadata fields
• EDAMNotesMetadataResultSpec *resultSpec =
[[EDAMNotesMetadataResultSpec alloc]
initWithIncludeTitle:YES
i...
Query
• [[EvernoteNoteStore noteStore]
findNotesMetadataWithFilter:filter offset:0
maxNotes:10 resultSpec:resultSpec
success...
Sample code
• http://goo.gl/D2G3G6
Practice-4 Render note
content in UIWebView
Classes need to know in this
practice
• ENMLUtility->Convert ENML to HTML
• EDAMNote -> Class of note object
Download note content
• [[EDAMNoteStore noteStore]
getNoteWithGuid:note.guid withContent:YES
withResourcesData:YES
withRes...
ENML->HTML
• ENMLUtility *utility = [[ENMLUtility alloc] init]
• [utilty convertENMLToHTML:note.content
withResources:note...
Sample code
• http://goo.gl/tUzfQH
Practice-5 Share note to Social network
setup pod would use in this
practice
• pod ‘LINEActivity’, ‘~>0.2’
• pod update
Classes need to know in this
practice
• [EvernoteUserStore userStore], For fetching user
related information like shardid
...
Sharing note URL
generated by Evernote
• http://www.evernote.com/shard/{shardid}/sh/
{noteguid}/{notekey}
How to get user’s shard id?
• [[EvernoteUserStore userStore]
getUserWithSuccess:^(EDAMUser *user){}
failure:^(NSError *err...
Share note then get note’s
sharing key
• [[EvernoteNoteStore noteStore]
shareNoteWithGuid:note.guid success:^(NSString
*ke...
iOS Share Activity for note
sharing url
• NSURL *shareURL = [NSURL
URLWithString:shareurlstr]
• NSArray *activityItems = @...
Sample code
• http://goo.gl/wGXMrb
Share some of My
experience …
To Sync or not to ?
• Evernote Sync API is another topic, Sync API like
Mail IMAP protocol which sync all of cloud changes...
Rate Limit
• Limit for API calling for each hours
• Implement Cache in your App for reducing Rate
Limit exception
• Detail...
Note thumbnails
• Note include in Evernote iOS SDK, Need to use
HTTP request to fetch each note’s thumb image
• Please ref...
Notebook
• User’s own Notebook->EDAMNotebook
• Notebook shared by friend ->EDAMLinkbook
• Business Notebook
• Take care ab...
Limitations for Writing to
Evernote
• Note content body need to be ENML format,
EDAMWriter class could help you
• EDAMLimi...
Q & A
EverNote iOS SDK introduction & practices
Upcoming SlideShare
Loading in …5
×

EverNote iOS SDK introduction & practices

2,180 views

Published on

Evernote iOS SDK introduction and provide 5 simple practices for using Evernote SDK

Published in: Technology

EverNote iOS SDK introduction & practices

  1. 1. Evernote iOS SDK introduction GoLater Developer MaoYang Twitter @GoLaterApp E-Mail my@esast.com
  2. 2. About Me • 5 years Mac Device Driver/Application developer • 10 years Enterprise grade software development tools consultant • Now -> iOS/Android app developer
  3. 3. Today’s Goal • iOS App development setup -> Xcode 5.x + Cocoapods • Evernote iOS SDK introduction • 5 Evernote iOS SDK practices
  4. 4. Evernote SDK • https://github.com/evernote/evernote-sdk-ios • Evernote Cloud SDK detail spec ->http:// dev.evernote.com
  5. 5. EasyShare for Evernote • Practice-1 : Development environment setup and using Evernote OAuth API • Practice-2 : List all of notebooks in your Evernote account • Practice-3 : List all of notes in a notebook • Practice-4 : Render note content in UIWebView • Practice-5 : Share your note to social network
  6. 6. Practice-1 SDK setup & OAuth • Xcode 5.x + • cocoapods installation—> sudo gem install cocoapods • Create an iOS project named EasyShare by Xcode
  7. 7. Evernote SDK setup • create a file named Podfile in your root of project 
 plateform :iOS , ‘7.0’
 pod ‘Evernote-SDK-iOS’, ‘1.3.1’ • pod install • Open EasyShare.xcworkspace in Xcode
  8. 8. Setup URL Scheme
  9. 9. Initialize SDK -1 #import "EvernoteSDK.h"! ! - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions! {! // Initial development is done on the sandbox service! // Change this to BootstrapServerBaseURLStringUS to use the production Evernote service! // Change this to BootstrapServerBaseURLStringCN to use the Yinxiang Biji production service! // Bootstrapping is supported by default with either BootstrapServerBaseURLStringUS or BootstrapServerBaseURLStringCN! // BootstrapServerBaseURLStringSandbox does not support the Yinxiang Biji service! NSString *EVERNOTE_HOST = BootstrapServerBaseURLStringUS; //使⽤用Production Server! ! // Fill in the consumer key and secret with the values that you received from Evernote! // To get an API key, visit http://dev.evernote.com/documentation/cloud/! NSString *CONSUMER_KEY = @"your key";! NSString *CONSUMER_SECRET = @"your secret";! ! // set up Evernote session singleton! [EvernoteSession setSharedSessionHost:EVERNOTE_HOST! consumerKey:CONSUMER_KEY ! consumerSecret:CONSUMER_SECRET];! }
  10. 10. Initialize SDK -2 (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation: (id)annotation {! BOOL canHandle = NO;! if ([[NSString stringWithFormat:@"en-%@", [[EvernoteSession sharedSession] consumerKey]] isEqualToString:[url scheme]] == YES) {! canHandle = [[EvernoteSession sharedSession] canHandleOpenURL:url];! }! return canHandle;! }
  11. 11. Initialize SDK-3 - (void)applicationDidBecomeActive:(UIApplication *)application! {! // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.! [[EvernoteSession sharedSession] handleDidBecomeActive];! }
  12. 12. SingleTon need to know in this practice • [EvernoteSession sharedSession], responsible for login/logout, login status
  13. 13. UI would look like
  14. 14. OAuth • if(![[EvernoteSession sharedSession] isAuthenticated){} • [[EvernoteSession sharedSession] authenticateWithViewController:self completionHandler:^(NSError *error){}]
  15. 15. Sample code • http://goo.gl/KzUK8W
  16. 16. Practice-2 List all of your own notebooks
  17. 17. SingleTon & Class need to know in this practice ! • [EvernoteStore noteStore] -> For ever note related operation • EDAMNotebook -> Class of Notebook object
  18. 18. Query Notebook • [[EvernoteNotesStore noteStore] listNotebooksWithSuccess:^(NSArray *notebooks){ for(EDAMNotebook *notebook in notebooks){} } failure:^(NSError *error){}];
  19. 19. Sample code • http://goo.gl/I9fNpb
  20. 20. Practice-3 List all of notes in a notebook
  21. 21. Classes need to know in this practice • EDAMNoteFilter -> setup filter condition for query notes • EDAMNotesMetadataResultSpec -> Setup which note metadata fields would return from cloud • EDAMNoteMetadata -> Class of note metadata! • EDAMNotesMetadataList , Container for notes object array
  22. 22. Filter • EDAMNoteFilter *filter = [[EDAMNoteFilter alloc] initWithOrder:NoteSortOrder_UPDATED ascending:NO words:nil notebookGuid:nil tagGuid:nil timeZone:nil inActive:NO emphasized:NO] • Filter full api spec doucment—>http:// dev.evernote.com/doc/reference/ NoteStore.html#Struct_NoteFilter
  23. 23. Metadata fields • EDAMNotesMetadataResultSpec *resultSpec = [[EDAMNotesMetadataResultSpec alloc] initWithIncludeTitle:YES includeContentLength:YES includeCreated:YES includeUpdated:YES includeDeleted:YES includeUpdateSequenceNum:YES includeNotebookGuid:YES includeTagGuids:YES includeAttributes:YES includeLargestResourceMime:NO includeLargestResourceSize:YES];
  24. 24. Query • [[EvernoteNoteStore noteStore] findNotesMetadataWithFilter:filter offset:0 maxNotes:10 resultSpec:resultSpec success:^(EDAMNotesMetadataList *metalist) {if(metalist.notes.count > 0)….}failure:^(NSError *error){ } ];
  25. 25. Sample code • http://goo.gl/D2G3G6
  26. 26. Practice-4 Render note content in UIWebView
  27. 27. Classes need to know in this practice • ENMLUtility->Convert ENML to HTML • EDAMNote -> Class of note object
  28. 28. Download note content • [[EDAMNoteStore noteStore] getNoteWithGuid:note.guid withContent:YES withResourcesData:YES withResourceRecognition:NO withResourceAlternateData:NO success:^(EDAMNote *note){} failure:^(NSError *error{}]
  29. 29. ENML->HTML • ENMLUtility *utility = [[ENMLUtility alloc] init] • [utilty convertENMLToHTML:note.content withResources:note.resources completion:^(NSString *html,NSError *error){}
  30. 30. Sample code • http://goo.gl/tUzfQH
  31. 31. Practice-5 Share note to Social network
  32. 32. setup pod would use in this practice • pod ‘LINEActivity’, ‘~>0.2’ • pod update
  33. 33. Classes need to know in this practice • [EvernoteUserStore userStore], For fetching user related information like shardid • EDAMUser Class of user object
  34. 34. Sharing note URL generated by Evernote • http://www.evernote.com/shard/{shardid}/sh/ {noteguid}/{notekey}
  35. 35. How to get user’s shard id? • [[EvernoteUserStore userStore] getUserWithSuccess:^(EDAMUser *user){} failure:^(NSError *error){ NSString *shardId = user.shardId}];
  36. 36. Share note then get note’s sharing key • [[EvernoteNoteStore noteStore] shareNoteWithGuid:note.guid success:^(NSString *key){} failure:^(NSError *error){}]
  37. 37. iOS Share Activity for note sharing url • NSURL *shareURL = [NSURL URLWithString:shareurlstr] • NSArray *activityItems = @[shareurlstr,shareURL] • NSArray *applicationActivities = @[[LINEActivity alloc] init] • UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities]
  38. 38. Sample code • http://goo.gl/wGXMrb
  39. 39. Share some of My experience …
  40. 40. To Sync or not to ? • Evernote Sync API is another topic, Sync API like Mail IMAP protocol which sync all of cloud changes set to your App • Do you need all of notebook/notes in your App?
  41. 41. Rate Limit • Limit for API calling for each hours • Implement Cache in your App for reducing Rate Limit exception • Detail-> http://dev.evernote.com/doc/articles/ rate_limits.php
  42. 42. Note thumbnails • Note include in Evernote iOS SDK, Need to use HTTP request to fetch each note’s thumb image • Please refer to http://dev.evernote.com/doc/articles/ thumbnails.php
  43. 43. Notebook • User’s own Notebook->EDAMNotebook • Notebook shared by friend ->EDAMLinkbook • Business Notebook • Take care about differences between each notebook interface
  44. 44. Limitations for Writing to Evernote • Note content body need to be ENML format, EDAMWriter class could help you • EDAMLimits.h & EDAMLimits.m has a lot of Regular express for checking your input data
  45. 45. Q & A

×