2011年3月4日金曜日

MGTwitterSearchYAJLParser 壊れてます



TwitterEngineにて、SearchAPIメソッドを使用する際は、なぜかJSON形式にしか


対応していない模様で、MGTwitter****YAJL*****系のクラスを使用する。


その際の設定手順は以前に書いたけど、


いざこれを使って、パースしてもらおうと思うと、


MGTwitterSearchYAJLParserクラスがぶっ壊れていて、


ちゃんと、すべてのデータをきちんと取得ない。


一番ほしい、text(つぶやき内容)の情報もとれない。


見たところ、Directroyが2重でくる形式でデータがかえってくると、


それ以降のデータは取得不可能。


DEBUGをオンにして試すとよくわかる。


自分で修正して書き換えようと思ったけど、


もうちゃんと動くソースコードがあってそれに書き換えたらきちんと、


データを取得できた。下記から取得して、上書きすれば問題なし。


MGTwitterSearchYAJLParser.h
MGTwitterSearchYAJLParser.m



2011年3月3日木曜日

iphone MGTwitterEngineで、json形式を使用する際の設定など






MGTwitterEngineは、TwitterのAPIをライブラリ化したようなもので


認証から、データの取得、データの更新などの、Twitter連携をする際は使った方が断然便利!


しかし、「Search系のAPI」を使用しようとすると、少々めんどくさい。

普通にXML形式のみを扱う際の手順は、この方々のブログを見てください。
http://d.hatena.ne.jp/tomute/20091029/1256865402
http://d.hatena.ne.jp/yuum3/20100511/1273556702
http://iphone.longearth.net/2010/08/04/%E3%81%BE%E3%81%A0%E9%96%93%E3%81%AB%E5%90%88%E3%81%86iphone%E3%82%A2%E3%83%97%E3%83%AA%E3%81%AExauth%E5%AF%BE%E5%BF%9C/


Search系APIメソッドを使用する際のめんだくさい作業

1. Search系のAPIをMGTwitterEngineライブラリで、使用するためには、なぜかJSON形式でデータを取得することになる
なぜでしょう‥。

2. JSON形式で、取得するには、MGTwitterEngineライブラリの中の、JSON解析用ライブラリ(〜YAJL〜というファイル名のもの)を使用しなければならない。
XML形式のみ扱う場合は、MGTwitterEngineライブラリの中の「yajl」とファイルはコンパイルされないようターゲットから外すか、ファイルごと消した方が良い。


3. このライブラリを使用しようとすると、libyajl.dylibっているライブラリが必要になる。
TwitterEngineYajl*****ファイルが、このライブラリを使用しているため、libyajl.....がないとエラーが出る



4. yajlをインストールする必要がある
僕の場合、mac-portでインストールしたけど、x86_64のみしか対応してないものだったみたいで、ここでも手こずりました。


と、などなどさまざまな問題点があり、ドキュメントも少ないし大変だった‥

手順は、この方の手順通りで行けます。
http://damienh.org/2009/06/20/setting-up-mgtwitterengine-with-yajl-106-for-iphone-development/

で、最後に、,yajl_allocとかのエラーの対応をした後に、エラーが上記4の問題でエラーがでたので、


このかたのブログを参考にさせていただき、 i386にも対応させ、完了した。
http://d.hatena.ne.jp/nakamura001/20101019/1287514329

いじょー!



‥っと思いきや、途中でこけました

どうやらうまくi386用が生成できなかった模様。理由はなぞ。


ってことなので、この方法はあきらめました。。



そこで、このかたのブログを参考に、
http://d.hatena.ne.jp/tomute/20091220/1261372045

libYAJLIPhone-0.2.13.zip」をページ中央らへんのDownloadのiPhoneというところから
ダウンロード


中身↓↓
libYAJLIPhone.a
NSObject+YAJL.h
yajl_common.h
yajl_gen.h
yajl_parse.h
YAJL.h
YAJLDocument.h
YAJLGen.h
YAJLParser.h

これを自分のプロジェクトに追加し、

プロジェクト設定を編集のビルド部分で、「他のリンカフラグ」に

「-ObjC」
「-all_load」

の2つを追加する

そしていざ、ビルド!


‥しかし、まだエラーがでた。

Yajl系のライブラリのシンボルのリンクエラー。。。。


じゃーっと思い、プロジェクトにYJAL.frameworkを追加してみる
ここからダウンロード

追加後、今度こそっと!ビルド!


しかし、エラー。。。。


なんか、
最初に追加した、libYAJLIPhone.aと今追加した、YAJL.frameworkの中身が何かかぶっているっと。


ためしに、libYAJLIPhone.aをプロジェクトから削除。。


すると、エラーがなくなりビルドできました!


長かったですがようやくこれで、TwitterSreach系のAPIがMGTwitterEngineから使用できます!




2011年3月2日水曜日

iPhone tabBarをtweetアプリのようにカスタマイズする方法



TwitterのアプリのようにtabBarのカスタマイズの仕方。


やろうと思えば自作で作ることも可能ですが、画像をつくるのが面倒なので、


もともとのUITabBarControllerをカスタマイズして作ることにした。


まずはアプリケーションdelegateクラスに、uitabBarControllerをOutletで宣言。


MainWindow.xibにインターフェースビルダーでUITabControllerを配置し、


先ほど宣言したOutletをつなぎ、delegateもつないでおく。


そしたら、アプリケーションdelegateクラスの.mファイルに下記を追加



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    CGRect frame = CGRectMake(0, 0, self.tabBarController.view.frame.size.width, self.tabBarController.view.frame.size.height);

self.tabBarController.view.frame = CGRectMake(0, 19, frame.size.width, frame.size.height+9);
self.tabBarController.tabBar.frame = CGRectMake(0, frame.size.height - tabBarHeight-19, frame.size.width, tabBarHeight);
// Change position tabBarItem icon.
tabBarController.selectedIndex = 0;
[self  addTabBarArrow];

        [window addSubview:view];
        [window makeKeyAndVisible];

}

#pragma mark -
#pragma mark Create custom tabBar
- (void) addTabBarArrow {
UIImage* tabBarArrowImage = [UIImage imageNamed:@"control.png"];
tabBarArrow = [[[UIImageView alloc] initWithImage:tabBarArrowImage] autorelease];
// To get the vertical location we start at the bottom of the window, go up by height of the tab bar, go up again by the height of arrow and then come back down 2 pixels so the arrow is slightly on top of the tab bar.
CGFloat verticalLocation = self.window.frame.size.height - tabBarController.tabBar.frame.size.height - tabBarArrowImage.size.height -5;
tabBarArrow.frame = CGRectMake([self horizontalLocationFor:0], verticalLocation, tabBarArrowImage.size.width, tabBarArrowImage.size.height);
[self.tabBarController.view addSubview:tabBarArrow];
}

- (CGFloat) horizontalLocationFor:(NSUInteger)tabIndex {
// A single tab item's width is the entire width of the tab bar divided by number of items
CGFloat tabItemWidth = tabBarController.tabBar.frame.size.width / tabBarController.tabBar.items.count;
// A half width is tabItemWidth divided by 2 minus half the width of the arrow
CGFloat halfTabItemWidth = (tabItemWidth / 2.0) - (tabBarArrow.frame.size.width / 2.0);
// The horizontal location is the index times the width plus a half width
return (tabIndex * tabItemWidth) + halfTabItemWidth;
}

// When change tab, will call.
- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController {

[self.tabBarController.view bringSubviewToFront:tabBarArrow];
 
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
CGRect frame = tabBarArrow.frame;
frame.origin.x = [self horizontalLocationFor:tabBarController.selectedIndex];
tabBarArrow.frame = frame;
[UIView commitAnimations];
 
}



こんな感じで、addTabBarArrowメソッドで、画像を追加し、表示する位置をしていする
最後の
- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController {
このメソッドは、タブが切り替えられたときに、呼ばれるメソッド
これは、先ほどのインターフェースビルダーでdelegateをつないでおかないと、呼ばれないので要注意。

あと、tabBarControllerのサイズを小さくすると、tabBarの中のそれぞれのビューと
タブ自体のビューがずれるので、調整してください。

いじょー