Tag: Evernote EvernoteAPI iPhoneSDK
#define EVERNOTE_HOST @"sandbox.evernote.com" #define CONSUMER_KEY @"XXXXX" // Consumer key #define CONSUMER_SECRET @"YYYYY" // Consumer secret - (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] autorelease]; if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } } NSString *text = nil; if (indexPath.row == 0) { text = @"OAuth認証でログイン"; } else if (indexPath.row == 1) { text = @"ログアウト"; } else if (indexPath.row == 2) { text = @"ノート書き込み"; } cell.textLabel.text = text; return cell; } - (void)login { [EvernoteSession setSharedSessionHost:EVERNOTE_HOST consumerKey:CONSUMER_KEY consumerSecret:CONSUMER_SECRET]; EvernoteSession *session = [EvernoteSession sharedSession]; [session authenticateWithViewController:self completionHandler:^(NSError *error) { if (error || !session.isAuthenticated) { NSLog(@"Error: Could not authenticate"); } else { NSLog(@"Authenticated!"); } }]; } -(void)logout { [[EvernoteSession sharedSession] logout]; } -(void)createNote { EDAMNote *note = [[[EDAMNote alloc] init] autorelease];; note.title = @"note.title"; note.content = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n<en-note>note.content</en-note>"; EvernoteNoteStore *noteStore = [EvernoteNoteStore noteStore]; @try { [noteStore createNote:note success:^(EDAMNote *note) {} failure:^(NSError *error) { NSLog(@"Error: %@", error); }]; } @catch (EDAMUserException *e) { return; } NSLog(@"Note was saved."); } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { [self login]; } else if (indexPath.row == 1) { [self logout]; } else if (indexPath.row == 2) { [self createNote]; } }