- 追加された行はこの色です。
- 削除された行はこの色です。
&tag();
&tag(Evernote, EvernoteAPI, iPhoneSDK);
*目次 [#z25a40bd]
#contents
*iPhone SDKから使う [#d1340d2b]
-[[Evernote API and iPhone SDK Setup « Digital ¶ericope:http://digitalpericope.net/?p=1]]
-[[開発者のための Evernote 入門 - Evernote Developers:http://dev.evernote.com/intl/jp/documentation/]]
*evernote-sdk-iosを使用する [#ydc05f34]
**APIキーを取得する [#a5845c3c]
-[[クラウド API - Evernote Developers:http://dev.evernote.com/intl/jp/documentation/cloud/]]からAPIキーを取得する。
--自動処理らしい。ConsumerKeyとSecretが即時に表示されているのでメモ。
--この段階ではsandbox.evernote.comにしか書き込めない。通常サイトに書き込むにはAPIキーのアクティベーション(後述)が必要。
--OAuth以前にAPIキーを申請していた場合でも新たに申請しないとだめ。以前のキーはOAuthでは使用できない。
--APIの権限としてベーシックアクセスとフルアクセアスがあり、必要もないのにフルアクセスにすると蹴られるらしい。
**SDKのダウンロード [#l97f32c3]
-[[evernote/evernote-sdk-ios:https://github.com/evernote/evernote-sdk-ios]]からzipでダウンロードする。
**サンプルの作成 [#k62cfb7d]
-ログイン、ログアウト、ノートの保存を実行するサンプルを作成する。
-新規プロジェクトでMaster-DetailアプリケーションEvernoteDemoを作成。ARCはオフにしておくのが簡単(理由。SDKがARCに対応してないから)。
-プロジェクトを作成したら、zip内のevernote-sdk-iosフォルダをプロジェクトの下にコピーし、Add File Toでevernote-sdk-iosフォルダを指定し丸ごとプロジェクト内に取り込む。
-Security.frameworkを追加する。TARGETSでEvernoteDemoを選択、Build Phasesを選択、Link Binary With Librariesで+アイコンを押してSecurity.frameworkを追加。
-ソースファイルの変更。EvernoteDemoMasterViewController.mを変更する。
#pre{{
#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];
}
}
}}