2011年10月31日月曜日

TwitterでxAuth認証したい

Twitterではベーシック認証は去年の6月で廃止されたので、使えません。
(そもそもセキュリティ的に危ないし)

その他の方法、となると、oauthか、xauth認証となるようです。
oauthは以下のアドレスから登録できます。

https://dev.twitter.com/apps

しかし、xauthの場合はtwitterに英語でメールして認証してもらわないといけません。
これはめんどくさそう。。
なので、oauthでできないものかと調べてみると、以下のライブラリがあるみたい。

Twitter-OAuth-iPhone
参考:
TwitterのOAuth認証を使う - 強火で進め

ダウンロードしてみて、demoフォルダ内のもので試してみたのだけれど、xCode4.3だと、
warninigがでまくり。
また、いちいち、twitterページを開いて、認証させる作業が必要な模様。

それに比べて、xauthの場合は、アプリ内にIDとパスワードを保存させておいて、それを使ってログインしたままにできるよう。
(セキュリティ的な意味ではaouthの方がいいみたいだけど)

なので、xauthを申請してみることにした。

申請を行っている方はたくさんいて、その内容の例を示してくれている。
それらを大いに参考にさせていただいて、メールを送ってみた。

タイトル : xauth request - iPhone Application
内容:
----

Hello.

I'm developing  'アプリ名', アプリの説明
for iPhone application.
Please look at screenshot images here.
スクリーンショットのURL

Please apply this app to use xAuth.
My account is @twitterユーザー名.
https://dev.twitter.com/apps/アプリID

Application: アプリ名

I want to add a tweet function to the iPhone application.

Best regards.
----

スクリーンショット画像はメールで添付できない、とのことで
自分のサーバにアップして、そのURLをはりつけました。

すると、以下のようなメールが帰ってきました。
たぶん、自動返信かと思われます。


Hello,
We've received your email regarding xAuth access and someone from our
team will review your request as soon as possible.
Our review will proceed much more quickly if you were to reply to this
ticket with the following information:
• Your App ID number (or consumer key) from https://dev.twitter.com/apps/
• A link to your application’s website
• Links to screenshots of your application's user-facing Twitter functionality
• Links to screenshots of your application in use
Please note that our ticketing system does not accept attachments, so
please upload your screenshots to your server or an image host. If
you have already provided the required information in your initial
request, please respond to this ticket to affirm that the required
information is present.
For your application to qualify for xAuth access, it must be
production-ready and only accessible via standalone desktop
application or via mobile. We do not grant xAuth for testing purposes,
single-user applications, or for applications that are in the early
stages of development.
If you are not requesting xAuth access and have received this response
in error, please let us know by responding to this ticket. If you have
a technical question about the API, please check out our
documentation: http://dev.twitter.com/doc
This ticket will automatically close if we do not receive a response
from you within one week.
Thanks,
Twitter API Policy

つたない英語力と自動翻訳に頼って読んでみると、
・アプリIDもしくは、コンシュマーIDを書いてね
・アプリのURLを書いてね
・twitterに投稿する時のスクリーンショットを送ってね
・アプリのスクリーンショットを送ってね
みたいな内容。
さらに、これに1週間以内に返信してくれないと、この件はなかったことにするからね、とも。
けど、最初に送った内容でほぼカバーしてる。
なので、最初に送った内容とほぼ同じことを返信しといた。

結果はここに追記で書きたいと思います。

メールの参考にさせてもらった記事(多謝!)
Twitter社へのxAuth利用申請 - CaptainShadowの日記


追記 11/11/01
さっそく次の日にメールが返ってきた。内容は以下。。。

Hello,
Thank you for your interest in xAuth. Unfortunately, we are not granting xAuth for development purposes. Instead, we recommend that you set up a one-time OAuth workflow to obtain the access token for a single account, and then store that token to authorize your API calls during this initial development stage. We even provide a tool on our developer site to make this process easy:https://dev.twitter.com/docs/auth/oauth/single-user-with-examples . Twitter does not expire access tokens unless the user revokes access to the application, or the application is suspended for violating policy. We apologize for any inconvenience that this causes to you and your project. Please let us know when you have a more production-ready version of your application, or if you have any other questions.
Thanks,
Twitter API Policy
内容は、開発段階ではxAuthの許可はできないよ。oauthあるし、そっち使ってね、みたいな。
また、xauth用に準備できたら再申請してね、みたいな。

んー。。
ググってみると同じメールで拒否されてる人が結構いる。
とりあえず、oauthでやってみますか。。

それかこの辺を参考にもっかい申請してみるか。
とりあえず、先にアプリ作るのが先決ですかね。

2011年10月28日金曜日

UITableViewCellStyle

tableViewのセルを作る際に、initWithFrameを使用していたら、非推奨(deprecated)って怒られた。
どうやら、iOS3.0から変更になったららしく、initWithFrameではなく、initWithStyleを使うそう。

・非推奨

[[[UITableViewCell alloc] initWithFrame:(CGRect) reuseIdentifier:(NSString *)] autorelease];

これを以下に
[[[UITableViewCell alloc] initWithStyle:(UITableViewCellStyle) reuseIdentifier:(NSString *)] autorelease];


で、UITableViewCellStyleに何を指定すればいいのか、を調べていると、以下のパターンがある事が判明。

UITableViewCellStyleDefault
UITableViewCellStyleValue1
UITableViewCellStyleValue2
UITableViewCellStyleSubtitle


けど、それぞれが何を表してるのかがわからない。
ってことで調べてみた。

すると、公式のリファレンスで説明されてた。
17ページからの「Table View Cellの標準スタイル」。

画像は転載できないので詳しくは上記PDFをみてもらうことにして、簡単に説明すると、、
Default は、画像とその横にテキスト、のスタイル。
Subtitle は、defaultのテキストの下にキャプションのようにテキストをつけるスタイル
Value1 は、右側のテキスト(メインタイトル)は左揃え、左側のテキスト(サブタイトル)は、右揃え、にするスタイル
Value2 は、1の逆で、メインタイトルは右揃え、サブタイトルは左揃えにするスタイル

value2は電話アプリの連絡先の表示と同じ、って書いてあったけど、実際はValue1のスタイルのような気が、、。



あと、こんなつぶやきを見つけた。
確かに…。まぁ、もう3.0以下とかは非対応でも大丈夫??

2011年10月27日木曜日

iPadでカメラロールはpopOverViewで表示する


UIImagePickerControllerでsourceTypeをPhotoLibraryにして、
カメラロールを表示させる場合、iPhoneの場合はモーダルビューで表示させる。

[self presentModalViewController:imagePickerController animated:YES];


だが、これだと、iPadではエラーとなる。 
iPadの場合は、全面にモーダルビューを表示する事は非推奨となっているため、
popOverViewなどで画面の一部だけを使って表示させる。

- (void)albumAction:(id)sender

{
imagePickerController[[UIImagePickerController alloc] init];

imagePickerController.delegate = self;

    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    
UIButton *btn = sender;
    
    imagePopController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
    [imagePopController presentPopoverFromRect:btn.bounds inView:btn permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; 
}


presentPopoverFromRectにある、btn.bounds、は、
UIButtonがタップされたらその場所を基準にpopOverviewを出す、ってことで、
そのボタンの場所を指定している。

もうひとつ、presentPopoverFromBarButtonItemでも出せる。

これはその名の通り、barButtonを基準に出す場合に便利。



delegateはiPhoneと同じで、

・選択された時

imagePickerController
・キャンセルされた時
imagePickerControllerDidCancel
と、なる。


・参考



2011年10月26日水曜日

iPadかiPhoneかをコードで判別する

これで大丈夫そう。

SDK3.2未満の場合はiPhoneとみなす


#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
    // sdk3.2以上の時
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        // iPad
    }
    else {
        //iPhone
    }
#else
    // sdk3.2未満
#endif


・参考