<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hi-farm blog &#187; Cocoa(Objective-C)</title>
	<atom:link href="http://blog.hi-farm.net/category/cocoa/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hi-farm.net</link>
	<description>ActionScript 3.0 , AIR , FLEXからCocoa, OpenGL</description>
	<lastBuildDate>Sat, 07 Jan 2012 14:26:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SA_TwitterEngineでのログアウトについて</title>
		<link>http://blog.hi-farm.net/2012/01/07/sa_twitterengine%e3%81%a7%e3%81%ae%e3%83%ad%e3%82%b0%e3%82%a2%e3%82%a6%e3%83%88%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6/</link>
		<comments>http://blog.hi-farm.net/2012/01/07/sa_twitterengine%e3%81%a7%e3%81%ae%e3%83%ad%e3%82%b0%e3%82%a2%e3%82%a6%e3%83%88%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 14:26:20 +0000</pubDate>
		<dc:creator>hi-farm.net</dc:creator>
				<category><![CDATA[Cocoa(Objective-C)]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://blog.hi-farm.net/?p=591</guid>
		<description><![CDATA[
			
				
			
		
試行錯誤した後のコードをもとに書いているので無駄なコードがあるかもしれません。ご了承ください。。。
iOS5からはOSベースでのTwitter連携のサポートがありますが、2012年1月現 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.hi-farm.net%2F2012%2F01%2F07%2Fsa_twitterengine%25e3%2581%25a7%25e3%2581%25ae%25e3%2583%25ad%25e3%2582%25b0%25e3%2582%25a2%25e3%2582%25a6%25e3%2583%2588%25e3%2581%25ab%25e3%2581%25a4%25e3%2581%2584%25e3%2581%25a6%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.hi-farm.net%2F2012%2F01%2F07%2Fsa_twitterengine%25e3%2581%25a7%25e3%2581%25ae%25e3%2583%25ad%25e3%2582%25b0%25e3%2582%25a2%25e3%2582%25a6%25e3%2583%2588%25e3%2581%25ab%25e3%2581%25a4%25e3%2581%2584%25e3%2581%25a6%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h2>試行錯誤した後のコードをもとに書いているので無駄なコードがあるかもしれません。ご了承ください。。。</h2>
<p>iOS5からはOSベースでのTwitter連携のサポートがありますが、2012年1月現在だとまだiOS4にも対応させたいですよね。</p>
<p>そんな時の便利なライブラリとしてこちらがあります。<br />
<a href="https://github.com/bengottlieb/Twitter-OAuth-iPhone" target="_blank">https://github.com/bengottlieb/Twitter-OAuth-iPhone</a></p>
<p>サンプルコードもついていて、サンプルをビルドするとすぐに挙動が確認できて、テスト投稿なんかも簡単にできてしまいます。<br />
この取っ付きやすさはライブラリを使う際に「簡単なんだ」と思う事ができてやる気をあげてくれます。</p>
<p>ただ、このライブラリはログアウトの事はあまり考えていないようで、ログアウトしてアカウントを切り替えるなどしたい場合は結構大変です。</p>
<p>僕は下記の方法をとりました。あくまで一例ですのでご容赦ください。</p>
<hr />
<h3>SA_OAuthTwitterEngine.m</h3>
<pre class="brush: objc; title: ; notranslate">
- (BOOL) logout
{
	BOOL res = NO;

	NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
	[defaults removeObjectForKey:@&quot;authData&quot;];
	res = [defaults synchronize];
	[self clearAccessToken];
	[_accessToken release];
	_accessToken = [[OAToken alloc] initWithKey: nil secret: nil];

	return res;
}
</pre>
<p> アクセストークンもクリアしてるしこれで問題ないはずなのですが、これだけだとキャッシュデータが残ってしまっているようで、ログアウトして再度認証画面を呼んでもテキストの入力ができません。</p>
<p>なのでSA_OAuthTwitterEngineを保持しているクラスで認証画面を呼ぶ処理でこの用に書きました。</p>
<pre class="brush: objc; title: ; notranslate">
if (_engine){	return;}
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
_engine.consumerKey = kOAuthConsumerKey;
_engine.consumerSecret = kOAuthConsumerSecret;

[_engine setClearsCookies:YES];

_authorizeViewController = [[SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self] retain];

[_engine setClearsCookies:NO];
</pre>
<p>_authorizeViewControllerを初期化する前に</p>
<pre class="brush: objc; title: ; notranslate">
[_engine setClearsCookies:YES];
</pre>
<p>を呼んでキャッシュをクリアできるようにしておき、初期化後に</p>
<pre class="brush: objc; title: ; notranslate">
[_engine setClearsCookies:NO];
</pre>
<p>としてデフォルトのNOに値を戻します。<br />
これでログアウト後に再度ログイン用の認証ダイアログを呼んでも新たにアカウントを入力する画面が表示されたはずです。</p>
<p>ちなみに、iOS5以降は送信先URLがhttpではなく、httpsでないとうまく認証できないのでご注意を。ちなみにhttpsにするとiOS4でも問題ないので修正しておくと良いと思います。</p>
<p>ちなみに「強火で進め」様のサイトが詳しいです。<br />
<a href="http://d.hatena.ne.jp/nakamura001/20100519/1274287901" target="_blank">http://d.hatena.ne.jp/nakamura001/20100519/1274287901</a></p>
<p>ちゃんと精査して書ききれていない記事ですみませんが、同じようにはまる方の助けになればと思います。</p>
<p>何かありましたらコメント欄でも twitterの <a href="http://twitter.com/mmlemon" target="_blank">@mmlemon</a> でもお気軽に突っ込んでください。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hi-farm.net/2012/01/07/sa_twitterengine%e3%81%a7%e3%81%ae%e3%83%ad%e3%82%b0%e3%82%a2%e3%82%a6%e3%83%88%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[iOS] 間違ったバージョンのdylibを追加してはまる</title>
		<link>http://blog.hi-farm.net/2011/11/15/ios-%e9%96%93%e9%81%95%e3%81%a3%e3%81%9f%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e3%81%aedylib%e3%82%92%e8%bf%bd%e5%8a%a0%e3%81%97%e3%81%a6%e3%81%af%e3%81%be%e3%82%8b/</link>
		<comments>http://blog.hi-farm.net/2011/11/15/ios-%e9%96%93%e9%81%95%e3%81%a3%e3%81%9f%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e3%81%aedylib%e3%82%92%e8%bf%bd%e5%8a%a0%e3%81%97%e3%81%a6%e3%81%af%e3%81%be%e3%82%8b/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 19:29:49 +0000</pubDate>
		<dc:creator>hi-farm.net</dc:creator>
				<category><![CDATA[Cocoa(Objective-C)]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[未分類]]></category>
		<category><![CDATA[adlantis]]></category>
		<category><![CDATA[libz.dylib]]></category>

		<guid isPermaLink="false">http://blog.hi-farm.net/?p=502</guid>
		<description><![CDATA[
			
				
			
		
iOSアプリの開発で、adlantisの広告を入れて試すにはlibz.dylibが必要なのですが、プロジェクトにファイルを追加するのを横着して、間違ってsdk4.3のものを追加してしまっ [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F11%2F15%2Fios-%25e9%2596%2593%25e9%2581%2595%25e3%2581%25a3%25e3%2581%259f%25e3%2583%2590%25e3%2583%25bc%25e3%2582%25b8%25e3%2583%25a7%25e3%2583%25b3%25e3%2581%25aedylib%25e3%2582%2592%25e8%25bf%25bd%25e5%258a%25a0%25e3%2581%2597%25e3%2581%25a6%25e3%2581%25af%25e3%2581%25be%25e3%2582%258b%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F11%2F15%2Fios-%25e9%2596%2593%25e9%2581%2595%25e3%2581%25a3%25e3%2581%259f%25e3%2583%2590%25e3%2583%25bc%25e3%2582%25b8%25e3%2583%25a7%25e3%2583%25b3%25e3%2581%25aedylib%25e3%2582%2592%25e8%25bf%25bd%25e5%258a%25a0%25e3%2581%2597%25e3%2581%25a6%25e3%2581%25af%25e3%2581%25be%25e3%2582%258b%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>iOSアプリの開発で、adlantisの広告を入れて試すにはlibz.dylibが必要なのですが、プロジェクトにファイルを追加するのを横着して、間違ってsdk4.3のものを追加してしまった後、ビルドするとわけのわからないエラーが出て、どれだけ戻してもエラーが解消されなかったのですが、下記の画像のように Library Search Pathsに赤枠の&#8221;DeviceSupport/4.3.5&#8243;が追加されていることが原因でした。</p>
<p>これが現行のsdkと衝突して問題を起こしていたのかな？</p>
<p><img src="http://blog.hi-farm.net/wp-content/uploads/2011/11/library_searchpath.png" alt="library_searchpath" title="library_searchpath" width="513" height="297" class="aligncenter size-full wp-image-501" /></p>
<p>この赤枠の参照を外すと無事動作するようになりました。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hi-farm.net/2011/11/15/ios-%e9%96%93%e9%81%95%e3%81%a3%e3%81%9f%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e3%81%aedylib%e3%82%92%e8%bf%bd%e5%8a%a0%e3%81%97%e3%81%a6%e3%81%af%e3%81%be%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GameCenterの機能実装中に見逃していたことの一つ &#8211; iTunesConnect上の設定</title>
		<link>http://blog.hi-farm.net/2011/11/13/gamecenter%e3%81%ae%e6%a9%9f%e8%83%bd%e5%ae%9f%e8%a3%85%e4%b8%ad%e3%81%ab%e8%a6%8b%e9%80%83%e3%81%97%e3%81%a6%e3%81%84%e3%81%9f%e3%81%93%e3%81%a8%e3%81%ae%e4%b8%80%e3%81%a4-itunesconnect%e4%b8%8a/</link>
		<comments>http://blog.hi-farm.net/2011/11/13/gamecenter%e3%81%ae%e6%a9%9f%e8%83%bd%e5%ae%9f%e8%a3%85%e4%b8%ad%e3%81%ab%e8%a6%8b%e9%80%83%e3%81%97%e3%81%a6%e3%81%84%e3%81%9f%e3%81%93%e3%81%a8%e3%81%ae%e4%b8%80%e3%81%a4-itunesconnect%e4%b8%8a/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 08:06:40 +0000</pubDate>
		<dc:creator>hi-farm.net</dc:creator>
				<category><![CDATA[Cocoa(Objective-C)]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Game Center]]></category>

		<guid isPermaLink="false">http://blog.hi-farm.net/?p=495</guid>
		<description><![CDATA[
			
				
			
		
最近iOSのGameCenter、特にLeaderBoard周りに興味があって調べているのですが、はまりまくっている状態なので残しておきます。
iTunes ConnectでLeader [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F11%2F13%2Fgamecenter%25e3%2581%25ae%25e6%25a9%259f%25e8%2583%25bd%25e5%25ae%259f%25e8%25a3%2585%25e4%25b8%25ad%25e3%2581%25ab%25e8%25a6%258b%25e9%2580%2583%25e3%2581%2597%25e3%2581%25a6%25e3%2581%2584%25e3%2581%259f%25e3%2581%2593%25e3%2581%25a8%25e3%2581%25ae%25e4%25b8%2580%25e3%2581%25a4-itunesconnect%25e4%25b8%258a%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F11%2F13%2Fgamecenter%25e3%2581%25ae%25e6%25a9%259f%25e8%2583%25bd%25e5%25ae%259f%25e8%25a3%2585%25e4%25b8%25ad%25e3%2581%25ab%25e8%25a6%258b%25e9%2580%2583%25e3%2581%2597%25e3%2581%25a6%25e3%2581%2584%25e3%2581%259f%25e3%2581%2593%25e3%2581%25a8%25e3%2581%25ae%25e4%25b8%2580%25e3%2581%25a4-itunesconnect%25e4%25b8%258a%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>最近iOSのGameCenter、特にLeaderBoard周りに興味があって調べているのですが、はまりまくっている状態なので残しておきます。<br />
iTunes ConnectでLeaderboardを作ってみて、一応アプリから表示はできるもののなぜかデータが登録できないなどある場合に意外に気づきませんでした。</p>
<p>iTunes ConnectでLeaderboardを作るだけではだめで、Manage Your Appsから対象となるアプリのVersionsにある View Details からGame Centerの横にあるグレーのボタンをクリックして、 ”Enabled for This Version”に変える必要があります。</p>
<p>赤く囲んでいるボタンをクリックします。<br />
<img src="http://blog.hi-farm.net/wp-content/uploads/2011/11/to_view_details.png" alt="to_view_details" title="to_view_details" width="527" height="350" class="aligncenter size-full wp-image-496" /></p>
<p>↓ここの赤枠で囲んでいるところがグレーの場合はクリックして画像の状態にしてください。<br />
<img src="http://blog.hi-farm.net/wp-content/uploads/2011/11/gamecenter_itunesconnect.png" alt="gamecenter_itunesconnect" title="gamecenter_itunesconnect" width="458" height="426" class="aligncenter size-full wp-image-497" /></p>
<p>その他についてはこちらのブログ記事が非常に参考になるのでご紹介します。<br />
iOS Game CenterでLeaderboardのScore送信が反映しない &laquo; istb16 blog<br />
<a href="http://istb16.wordpress.com/2011/09/13/ios-game-center_leaderboard_scoresend/" target="_blank">http://istb16.wordpress.com/2011/09/13/ios-game-center_leaderboard_scoresend/</a></p>
<p>これには気づいたもののまだまだ解決できていないところがあるので解決できたらまた記事あげますね。。。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hi-farm.net/2011/11/13/gamecenter%e3%81%ae%e6%a9%9f%e8%83%bd%e5%ae%9f%e8%a3%85%e4%b8%ad%e3%81%ab%e8%a6%8b%e9%80%83%e3%81%97%e3%81%a6%e3%81%84%e3%81%9f%e3%81%93%e3%81%a8%e3%81%ae%e4%b8%80%e3%81%a4-itunesconnect%e4%b8%8a/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[メモ] UINavigationControllerのviewcontrollerを取得</title>
		<link>http://blog.hi-farm.net/2011/09/08/%e3%83%a1%e3%83%a2-uinavigationcontroller%e3%81%aeviewcontroller%e3%82%92%e5%8f%96%e5%be%97/</link>
		<comments>http://blog.hi-farm.net/2011/09/08/%e3%83%a1%e3%83%a2-uinavigationcontroller%e3%81%aeviewcontroller%e3%82%92%e5%8f%96%e5%be%97/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 17:54:29 +0000</pubDate>
		<dc:creator>hi-farm.net</dc:creator>
				<category><![CDATA[Cocoa(Objective-C)]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[UINavigationController]]></category>
		<category><![CDATA[UITableViewController]]></category>

		<guid isPermaLink="false">http://blog.hi-farm.net/?p=490</guid>
		<description><![CDATA[
			
				
			
		
連投すみません。
UINavigationControllerを使って階層化されたViewを使うときにはUITableViewと組み合わせる事もあると思うのですが、一つ前の画面に戻るとき [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F09%2F08%2F%25e3%2583%25a1%25e3%2583%25a2-uinavigationcontroller%25e3%2581%25aeviewcontroller%25e3%2582%2592%25e5%258f%2596%25e5%25be%2597%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F09%2F08%2F%25e3%2583%25a1%25e3%2583%25a2-uinavigationcontroller%25e3%2581%25aeviewcontroller%25e3%2582%2592%25e5%258f%2596%25e5%25be%2597%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>連投すみません。</p>
<p>UINavigationControllerを使って階層化されたViewを使うときにはUITableViewと組み合わせる事もあると思うのですが、一つ前の画面に戻るときにデータを再読み込みさせたい時の方法が分からなかったのでメモ。</p>
<pre class="brush: cpp; title: ; notranslate">
NSArray* naviary = [self.navigationController viewControllers];
    NSInteger current = [naviary count]-1;
    UITableViewController* prev = (UITableViewController*)[naviary objectAtIndex:current-1];
    [prev.tableView reloadData];
</pre>
<p>navigationControllerがviewControllersという配列で今までのUIViewControllerの参照を保持しているので、一つ前の階層なら最後から一つ前の要素の参照を取得し、reloadDataをすることで現在の画面で変更したデータを反映させた結果を表示する事も可能です。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hi-farm.net/2011/09/08/%e3%83%a1%e3%83%a2-uinavigationcontroller%e3%81%aeviewcontroller%e3%82%92%e5%8f%96%e5%be%97/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[メモ] カスタムUITableViewCellの選択時の文字色を変える</title>
		<link>http://blog.hi-farm.net/2011/09/07/%e3%83%a1%e3%83%a2-%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0uitableviewcell%e3%81%ae%e9%81%b8%e6%8a%9e%e6%99%82%e3%81%ae%e6%96%87%e5%ad%97%e8%89%b2%e3%82%92%e5%a4%89%e3%81%88%e3%82%8b/</link>
		<comments>http://blog.hi-farm.net/2011/09/07/%e3%83%a1%e3%83%a2-%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0uitableviewcell%e3%81%ae%e9%81%b8%e6%8a%9e%e6%99%82%e3%81%ae%e6%96%87%e5%ad%97%e8%89%b2%e3%82%92%e5%a4%89%e3%81%88%e3%82%8b/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 10:02:34 +0000</pubDate>
		<dc:creator>hi-farm.net</dc:creator>
				<category><![CDATA[Cocoa(Objective-C)]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[UITableViewCell]]></category>

		<guid isPermaLink="false">http://blog.hi-farm.net/?p=483</guid>
		<description><![CDATA[
			
				
			
		
今日はメモです。
iOSアプリ開発で、独自に作成したUITableViewCellをタップした時にデフォルトのUITableViewCellと同じように文字色を変えたかったのですが、見つ [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F09%2F07%2F%25e3%2583%25a1%25e3%2583%25a2-%25e3%2582%25ab%25e3%2582%25b9%25e3%2582%25bf%25e3%2583%25a0uitableviewcell%25e3%2581%25ae%25e9%2581%25b8%25e6%258a%259e%25e6%2599%2582%25e3%2581%25ae%25e6%2596%2587%25e5%25ad%2597%25e8%2589%25b2%25e3%2582%2592%25e5%25a4%2589%25e3%2581%2588%25e3%2582%258b%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F09%2F07%2F%25e3%2583%25a1%25e3%2583%25a2-%25e3%2582%25ab%25e3%2582%25b9%25e3%2582%25bf%25e3%2583%25a0uitableviewcell%25e3%2581%25ae%25e9%2581%25b8%25e6%258a%259e%25e6%2599%2582%25e3%2581%25ae%25e6%2596%2587%25e5%25ad%2597%25e8%2589%25b2%25e3%2582%2592%25e5%25a4%2589%25e3%2581%2588%25e3%2582%258b%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>今日はメモです。</p>
<p>iOSアプリ開発で、独自に作成したUITableViewCellをタップした時にデフォルトのUITableViewCellと同じように文字色を変えたかったのですが、見つかるまでに少し時間がかかったのでメモしておきます。</p>
<p>独自で作成したUITableViewCellのサブクラス内に</p>
<pre class="brush: cpp; title: ; notranslate">
-(void)setHightlighted:(BOOL)highlighted animated:(BOOL)animated
</pre>
<p>というメソッドがあるので、それをオーバーライドしてhighlightの値を元に表示を切り替えると画面に触れたときに、文字色を変える事ができます。</p>
<pre class="brush: cpp; title: ; notranslate">
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    if(highlighted){
        [self setWhite];
    }else
    {
        [self setBlack];
    }
    [super setHighlighted:highlighted animated:animated];
}
</pre>
<p>※setWhite, setBlackは文字色を変更するための独自メソッドです。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hi-farm.net/2011/09/07/%e3%83%a1%e3%83%a2-%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0uitableviewcell%e3%81%ae%e9%81%b8%e6%8a%9e%e6%99%82%e3%81%ae%e6%96%87%e5%ad%97%e8%89%b2%e3%82%92%e5%a4%89%e3%81%88%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhoneのSimulatorと実機での違い</title>
		<link>http://blog.hi-farm.net/2011/08/04/iphone%e3%81%aesimulator%e3%81%a8%e5%ae%9f%e6%a9%9f%e3%81%a7%e3%81%ae%e9%81%95%e3%81%84/</link>
		<comments>http://blog.hi-farm.net/2011/08/04/iphone%e3%81%aesimulator%e3%81%a8%e5%ae%9f%e6%a9%9f%e3%81%a7%e3%81%ae%e9%81%95%e3%81%84/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 03:27:28 +0000</pubDate>
		<dc:creator>hi-farm.net</dc:creator>
				<category><![CDATA[Cocoa(Objective-C)]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Simulator]]></category>
		<category><![CDATA[シミュレータ]]></category>

		<guid isPermaLink="false">http://blog.hi-farm.net/?p=460</guid>
		<description><![CDATA[
			
				
			
		
iPhoneアプリの開発をしていてハマった事がまたありましたので残しておきます。
Objective-Cで、
例えばクラスAの@interface部で@protectedとして宣言してい [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F08%2F04%2Fiphone%25e3%2581%25aesimulator%25e3%2581%25a8%25e5%25ae%259f%25e6%25a9%259f%25e3%2581%25a7%25e3%2581%25ae%25e9%2581%2595%25e3%2581%2584%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F08%2F04%2Fiphone%25e3%2581%25aesimulator%25e3%2581%25a8%25e5%25ae%259f%25e6%25a9%259f%25e3%2581%25a7%25e3%2581%25ae%25e9%2581%2595%25e3%2581%2584%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>iPhoneアプリの開発をしていてハマった事がまたありましたので残しておきます。</p>
<p>Objective-Cで、<br />
例えばクラスAの@interface部で@protectedとして宣言していた変数aをサブクラスで呼ぶ場合、通常であればそのまま使えるはずなのですが、実機に向けてビルドするときにはエラーになってしまいました。</p>
<p>これは調べてみるとどうやら、<br />
・シミュレータではデフォルトの設定が@protected<br />
・実機ではデフォルトが@private<br />
と言う事に原因がある様です。（そういった差が生まれないように@で明示的に宣言したつもりだったのですが）</p>
<p>最善の解決策ではないですが、-(id)gethoge;といったメソッドを作成しました。<br />
カプセル化がしっかりできていないとは思うのですが、これでひとまずはエラー出ずにビルドし、問題なく動作するようになりました。</p>
<p>参考URL（StackOverflow：英語）：<br />
<a href="http://stackoverflow.com/questions/5513605/inheritance-working-on-simulator-but-not-on-iphone" target="_blank">http://stackoverflow.com/questions/5513605/inheritance-working-on-simulator-but-not-on-iphone</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hi-farm.net/2011/08/04/iphone%e3%81%aesimulator%e3%81%a8%e5%ae%9f%e6%a9%9f%e3%81%a7%e3%81%ae%e9%81%95%e3%81%84/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DarwiinRemote</title>
		<link>http://blog.hi-farm.net/2011/01/18/darwiinremote/</link>
		<comments>http://blog.hi-farm.net/2011/01/18/darwiinremote/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 21:05:21 +0000</pubDate>
		<dc:creator>hi-farm.net</dc:creator>
				<category><![CDATA[Cocoa(Objective-C)]]></category>
		<category><![CDATA[wii]]></category>
		<category><![CDATA[DarwiinRemote]]></category>
		<category><![CDATA[nui]]></category>
		<category><![CDATA[wiiRemote]]></category>

		<guid isPermaLink="false">http://blog.hi-farm.net/?p=367</guid>
		<description><![CDATA[
			
				
			
		
WiiRemoteでMacを操作するアプリ、DarwiinRemote。
これを使えばマウスになるよ！っていうものです。
だけど、僕はまだまだ使いこなせていません。使いこなせなくて、マウ [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F01%2F18%2Fdarwiinremote%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.hi-farm.net%2F2011%2F01%2F18%2Fdarwiinremote%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>WiiRemoteでMacを操作するアプリ、<a href="http://sourceforge.net/projects/darwiin-remote/" target="_blank">DarwiinRemote</a>。</p>
<p>これを使えばマウスになるよ！っていうものです。<br />
だけど、僕はまだまだ使いこなせていません。使いこなせなくて、マウスポインタがおかしなところに行っているのを停止させるためにまたぎこちない操作でなんとか停止ボタンまでたどり着いては必死にクリック、とまあこれはこれはひどい。。<br />
自分が古い世代の人間だな、と実感したのでした。</p>
<p>ビデオはこれ。<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="385" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/uEx9TMzvtU0?fs=1&amp;hl=ja_JP" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="640" height="385" src="http://www.youtube.com/v/uEx9TMzvtU0?fs=1&amp;hl=ja_JP" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<h2>ペアリング方法：</h2>
<p>とはいってもやはり一度は試してみたいという方もいらっしゃると思いますので、簡単な使い方をご紹介します。</p>
<p>アプリケーションを起動した直後の画面がこれなのですが、「Find Wiimote」ボタンをクリックすると、下のログ表示部に<br />
「Please press 1 button and 2 button simultaneously」と表示されますので、この間に1, 2のボタンを交互に押して下さい。あんまり速度を気にする事なしに操作しているとペアリングに成功します。</p>
<p>その後はウィンドウ左上の場所に傾きが解るようなグラフが表示されますので傾きなどを確認して下さい。</p>
<p>その後、「Mouse Mode Off」と表示されているところを変更すると、マウスとして認識するようになります。Mouse Mode On (motion)を選んで下さい。</p>
<p>これはこれで良いのですが、なんとソースコードまでリンク先のsourceforgeからダウンロードできます。<br />
ってことは、僕がずっと気になって探していたマウスエミュレートやキーボードエミュレートができる訳であり、、、それはわくわくです。<br />
そのあたりについてはまた次の記事にて書かせていただくつもりです。<br />
この仕組みを理解すれば無理にWiiRemoteを使う事なく、任意のデバイスで操作できるようになるので、iPhoneやほかの何かの信号を出す機械を自由にマウスでバイスやキーボードにできるわけですね。例えば流行のkinectとか使って。</p>
<p>やっぱり楽しい。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hi-farm.net/2011/01/18/darwiinremote/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPadのMIDIコントローラーアプリ、iMIDIConをリリースしました。</title>
		<link>http://blog.hi-farm.net/2010/12/18/ipad%e3%81%aemidi%e3%82%b3%e3%83%b3%e3%83%88%e3%83%ad%e3%83%bc%e3%83%a9%e3%83%bc%e3%82%a2%e3%83%97%e3%83%aa%e3%80%81imidicon%e3%82%92%e3%83%aa%e3%83%aa%e3%83%bc%e3%82%b9%e3%81%97%e3%81%be%e3%81%97/</link>
		<comments>http://blog.hi-farm.net/2010/12/18/ipad%e3%81%aemidi%e3%82%b3%e3%83%b3%e3%83%88%e3%83%ad%e3%83%bc%e3%83%a9%e3%83%bc%e3%82%a2%e3%83%97%e3%83%aa%e3%80%81imidicon%e3%82%92%e3%83%aa%e3%83%aa%e3%83%bc%e3%82%b9%e3%81%97%e3%81%be%e3%81%97/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 15:45:36 +0000</pubDate>
		<dc:creator>hi-farm.net</dc:creator>
				<category><![CDATA[Cocoa(Objective-C)]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://blog.hi-farm.net/?p=351</guid>
		<description><![CDATA[
			
				
			
		
いままでずっとiPhoneアプリ作ってる作ってると言うばっかりで作れてなかったですが、やっとリリースできました。
しかもiPadアプリです。
最近VJしているときに自分で使っていて、自分 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.hi-farm.net%2F2010%2F12%2F18%2Fipad%25e3%2581%25aemidi%25e3%2582%25b3%25e3%2583%25b3%25e3%2583%2588%25e3%2583%25ad%25e3%2583%25bc%25e3%2583%25a9%25e3%2583%25bc%25e3%2582%25a2%25e3%2583%2597%25e3%2583%25aa%25e3%2580%2581imidicon%25e3%2582%2592%25e3%2583%25aa%25e3%2583%25aa%25e3%2583%25bc%25e3%2582%25b9%25e3%2581%2597%25e3%2581%25be%25e3%2581%2597%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.hi-farm.net%2F2010%2F12%2F18%2Fipad%25e3%2581%25aemidi%25e3%2582%25b3%25e3%2583%25b3%25e3%2583%2588%25e3%2583%25ad%25e3%2583%25bc%25e3%2583%25a9%25e3%2583%25bc%25e3%2582%25a2%25e3%2583%2597%25e3%2583%25aa%25e3%2580%2581imidicon%25e3%2582%2592%25e3%2583%25aa%25e3%2583%25aa%25e3%2583%25bc%25e3%2582%25b9%25e3%2581%2597%25e3%2581%25be%25e3%2581%2597%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>いままでずっとiPhoneアプリ作ってる作ってると言うばっかりで作れてなかったですが、やっとリリースできました。<br />
しかもiPadアプリです。</p>
<p>最近VJしているときに自分で使っていて、自分自身がユーザーであり続けるので今後も愛情たっぷりで育てて行こうと思います。</p>
<p>何かご指摘等あればコメントいただけるとうれしいです。</p>
<p>後々色々かけるといいなあ。</p>
<p><a href="itms://itunes.apple.com/us/app/imidicon/id408359140?mt=8"><img src="http://www.imidicon.com/wp-content/uploads/2010/12/appstore_badge.png" alt="buy iMIDICon from app store" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hi-farm.net/2010/12/18/ipad%e3%81%aemidi%e3%82%b3%e3%83%b3%e3%83%88%e3%83%ad%e3%83%bc%e3%83%a9%e3%83%bc%e3%82%a2%e3%83%97%e3%83%aa%e3%80%81imidicon%e3%82%92%e3%83%aa%e3%83%aa%e3%83%bc%e3%82%b9%e3%81%97%e3%81%be%e3%81%97/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[iPad] 外部出力方法</title>
		<link>http://blog.hi-farm.net/2010/09/06/ipad-%e5%a4%96%e9%83%a8%e5%87%ba%e5%8a%9b%e6%96%b9%e6%b3%95/</link>
		<comments>http://blog.hi-farm.net/2010/09/06/ipad-%e5%a4%96%e9%83%a8%e5%87%ba%e5%8a%9b%e6%96%b9%e6%b3%95/#comments</comments>
		<pubDate>Sun, 05 Sep 2010 20:05:42 +0000</pubDate>
		<dc:creator>hi-farm.net</dc:creator>
				<category><![CDATA[Cocoa(Objective-C)]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://blog.hi-farm.net/?p=278</guid>
		<description><![CDATA[
			
				
			
		
やっぱり久々なポストです。
iPadでは外部映像出力が可能なので、それを試しているのですが、ちょっと解らずハマっていた事があったのでメモ程度に書いておきますね。デバッグするのも困難ですし。
基本的な実装の手順としては、下記の通りです。
1. つながっているスクリーンを[UIScreen screens]がNSArrayで取得する。
2. 1.で取得したUIScreenからお好みのUIScreenModeを取得する。
3. UIScreenを取得する。
4. 取得したUIScreenのcurrentModeに2.で取得した内容を設定する。
5. 表示させたいコンテンツを作成する。
6. 外部出力させるためにUIWindowを作る。
7. 6.に表示させたいコンテンツをaddSubView: する。
8. window.screen に3.のUIScreenを設定する。
9. windowの基礎的な設定を行う。
以上です。
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;

// ログとして外部モニターに表示する内容
// log message displayed in external monitor.
NSMutableString *str = [[NSMutableString alloc] init];
int screenCount = [[UIScreen screens] count];

// 設定されるスクリーンモード
// used screen mode
UIScreenMode *current = nil;

// checking each screen information
for(int i = 0; i &#60; screenCount; i++)
{
 int modelen = [[[[UIScreen screens] objectAtIndex:i] availableModes] [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.hi-farm.net%2F2010%2F09%2F06%2Fipad-%25e5%25a4%2596%25e9%2583%25a8%25e5%2587%25ba%25e5%258a%259b%25e6%2596%25b9%25e6%25b3%2595%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.hi-farm.net%2F2010%2F09%2F06%2Fipad-%25e5%25a4%2596%25e9%2583%25a8%25e5%2587%25ba%25e5%258a%259b%25e6%2596%25b9%25e6%25b3%2595%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>やっぱり久々なポストです。</p>
<p>iPadでは外部映像出力が可能なので、それを試しているのですが、ちょっと解らずハマっていた事があったのでメモ程度に書いておきますね。デバッグするのも困難ですし。</p>
<p>基本的な実装の手順としては、下記の通りです。<br />
1. つながっているスクリーンを[UIScreen screens]がNSArrayで取得する。<br />
2. 1.で取得したUIScreenからお好みのUIScreenModeを取得する。<br />
3. UIScreenを取得する。<br />
4. 取得したUIScreenのcurrentModeに2.で取得した内容を設定する。<br />
5. 表示させたいコンテンツを作成する。<br />
6. 外部出力させるためにUIWindowを作る。<br />
7. 6.に表示させたいコンテンツをaddSubView: する。<br />
8. window.screen に3.のUIScreenを設定する。<br />
9. windowの基礎的な設定を行う。</p>
<p>以上です。</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<pre class="brush: plain; title: ; notranslate">
// ログとして外部モニターに表示する内容
// log message displayed in external monitor.
NSMutableString *str = [[NSMutableString alloc] init];
int screenCount = [[UIScreen screens] count];

// 設定されるスクリーンモード
// used screen mode
UIScreenMode *current = nil;

// checking each screen information
for(int i = 0; i &lt; screenCount; i++)
{
 int modelen = [[[[UIScreen screens] objectAtIndex:i] availableModes] count];

 // checking each screen mode in screen.
 for (int j = 0; j &lt; modelen; j++)
 {
   // getting screen mode
   UIScreenMode *curMode = [[[[UIScreen screens] objectAtIndex:i] availableModes]
 objectAtIndex:j];

   // get information of screen.
   NSString *sstr = [NSString stringWithFormat:@&quot;screen:%i, mode:%i, w:%f, h:%f,
  ratio:%f ---&quot;, i, j, current.size.width, current.size.height,
current.pixelAspectRatio];

   [str appendString:sstr];

   // if curMode.size.width is larger than current, change current reference
   if(curMode.size.width &gt; current.size.width){
    current = curMode;
    }
   }
  }

  // screen object
  UIScreen *another = [[UIScreen screens] objectAtIndex:1];
  another.currentMode = current;
  CGSize size = current.size;
  uvc = [[UIViewController alloc] init];

  // create new window.
  UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(
 0.0f,
 0.0f,
 size.width,
 size.height
)];

UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(
0.0f, 0.0f, 800.0f, 800.0f)
];
[uvc.view addSubview:tv];
tv.text = str;

[tv release];

[window addSubview:uvc.view];
window.screen = another;

[window makeKeyAndVisible];
[window setHidden:NO];
</pre>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
※syntaxhighlighterをうまくつかえていないので改行をくわえています。</p>
<p>ちなみにgithubにのせてますのでご興味のある方はご覧下さい。<br />
<a href="http://github.com/mmlemon/iPad-external-display-sample" target="_blank">http://github.com/mmlemon/iPad-external-display-sample</a></p>
<p>何か間違いやご不明な点があればお気軽にご質問下さいね！</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hi-farm.net/2010/09/06/ipad-%e5%a4%96%e9%83%a8%e5%87%ba%e5%8a%9b%e6%96%b9%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhoneでFlashの画面を操作する</title>
		<link>http://blog.hi-farm.net/2010/02/25/iphone%e3%81%a7flash%e3%81%ae%e7%94%bb%e9%9d%a2%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b/</link>
		<comments>http://blog.hi-farm.net/2010/02/25/iphone%e3%81%a7flash%e3%81%ae%e7%94%bb%e9%9d%a2%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 00:29:15 +0000</pubDate>
		<dc:creator>hi-farm.net</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Actionscript3]]></category>
		<category><![CDATA[Cocoa(Objective-C)]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[iPhone勉強]]></category>
		<category><![CDATA[勉強会とか]]></category>

		<guid isPermaLink="false">http://blog.hi-farm.net/?p=235</guid>
		<description><![CDATA[
			
				
			
		
以前、名古屋のFxugにて少し発表した内容なんですが、ずっと記事にできてなかったので、今更ながらまとめます。
密かに前から社内用発表会のネタとして作ってはいたのですが、僕個人的にも、なか [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.hi-farm.net%2F2010%2F02%2F25%2Fiphone%25e3%2581%25a7flash%25e3%2581%25ae%25e7%2594%25bb%25e9%259d%25a2%25e3%2582%2592%25e6%2593%258d%25e4%25bd%259c%25e3%2581%2599%25e3%2582%258b%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.hi-farm.net%2F2010%2F02%2F25%2Fiphone%25e3%2581%25a7flash%25e3%2581%25ae%25e7%2594%25bb%25e9%259d%25a2%25e3%2582%2592%25e6%2593%258d%25e4%25bd%259c%25e3%2581%2599%25e3%2582%258b%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>以前、<a href="http://www.fxug.net/modules/bwiki/index.php?Flex%CA%D9%B6%AF%B2%F1%C2%E896%B2%F3%40%CC%BE%B8%C5%B2%B0%BB%B2%B2%C3%BC%F5%C9%D5" target="_blank">名古屋のFxug</a>にて少し発表した内容なんですが、ずっと記事にできてなかったので、今更ながらまとめます。</p>
<p>密かに前から社内用発表会のネタとして作ってはいたのですが、僕個人的にも、なかなか披露する機会がないまま、時間が過ぎてしまいました。</p>
<p>概要としては、<br />
1. iPhone上でボタンをタップすると、AIR 2で作ったサーバーに、iPhoneからSocket経由で信号を送ります。<br />
2. AIR 2のサーバーが、信号を受け取り、信号に応じた処理を行います。</p>
<p>これが作ったアプリのキャプチャです。</p>
<p><a rel="lightbox" href="http://blog.hi-farm.net/wp-content/uploads/2010/02/viewer.png"><img style="display: block; margin-left: auto; margin-right: auto; border: 0px initial initial;" title="viewer" src="http://blog.hi-farm.net/wp-content/uploads/2010/02/viewer.png" alt="viewer" width="800" height="223" /></a></p>
<p>iPhoneとAIR 2サーバーの関係は、この通りです。</p>
<p><a rel="lightbox" href="http://blog.hi-farm.net/wp-content/uploads/2010/02/kousei.png"><img class="aligncenter size-full wp-image-245" title="kousei" src="http://blog.hi-farm.net/wp-content/uploads/2010/02/kousei.png" alt="kousei" width="395" height="123" /></a></p>
<p>簡単に行ってしまえば、これだけです。<br />
では、ここから説明します。</p>
<p><strong>1. AIR 2のサーバー部分を作成</strong><br />
AIRでサーバーを作るには、UDPとTCPのサーバーがありますが、今回はTCPで通信するので、flash.net.ServerSocketクラスを使用します。</p>
<p>宣言〜受付開始</p>
<pre class="brush: plain; title: ; notranslate">
&lt;pre&gt;import flash.net.ServerSocket;

// 接続してきたSocketを保持する
var socks:Vector. = new Vector.();
// インスタンス生成
var server:ServerSocket = new ServerSocket();
// 接続時のイベントハンドラ作成
server.addEventListener(ServerSocketConnectEvent.CONNECT, serverSocketConnectHandler, false, 0, false);
// 待ち受けポートを指定（43243番で受け付ける）
server.bind(43243);
// 待ち受け開始
server.listenen();&lt;/pre&gt;
</pre>
<p>接続時：</p>
<pre>function serverSocketConnectHandler(event:ServerSocketConnectEvent):void
{
  // 接続してきたSocket
  var socket:Socket = event.socket;
  // 接続してきたSocketにデータを返すため、イベント設定
  socket.addEventListener(ProgressEvent.SOCKET_DATA, receiveHandler, false, 0, false);
  // 接続してきたSocketを保持する
  socks.push(socket);
}</pre>
<p>受信時：（本来は宛先を指定するべきだが、特に指定せず、全てのSocketに送信しています）</p>
<pre>function receiveHandler(event:ProgressEvent):void
{
  // データを送信したSocketを取得
  var socket:Socket = event.target as Socket;
  if(socket!=null)  // nullチェック
  {
    // 受信データを取得
    var recv:String = socket.readUTFBytes(socket.bytesAvailable);
    // 操作対象のVideoPlayerを取得
    var target:VideoPlayer = getCurrentVideo(); // 自作のメソッドです
    // コマンドを取得し、操作を実行。コマンドを取得するため、indexOfを使っています。
    if( recv.indexOf("prev") &gt;= 0) {
      setPos("prev");
    } else if( recv.indexOf("next") &gt;= 0) {
      setPos("next");
    } else if( recv.indexOf("play") &gt;= 0) {
      if( target.playing ) {
        target.pause();
      } else {
        target.play();
      }
    }
  }
}</pre>
<p>AIRで作るサーバー周りは、こんなところです。エラー処理や切断時の処理などは書いてなくてごめんなさい。</p>
<p><strong>iPhone側アプリケーションのSocket処理</strong><br />
では、次。iPhoneのほう。これも簡単な書き方でごめんなさいね。と、いうかCで最低限の実装しかしていないです。</p>
<p>TCPSendClient.m<br />
接続：</p>
<pre>-(void)connect:(NSString *)ip toPort:(NSInteger)port
{
  	if(_connected)  // TCPSendClientが持っている、接続状態を保持する変数
	{
		return;
	}
	_connected = NO;
	// IPアドレスを取得
	servIP = [ip UTF8String];
	// portを取得
	servPort = port;
	// socketが正しく生成できているかチェック
	if((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) &lt; 0)
	{
		NSLog(@"socket creation error.");
		return;
	}
	// socketの設定
	memset(&amp;servAddr, 0, sizeof(servAddr));
	servAddr.sin_family = AF_INET;
	servAddr.sin_addr.s_addr = inet_addr(servIP);
	servAddr.sin_port = htons(servPort);
	// 接続
	if(connect(sock, (struct sockaddr *)&amp;servAddr, sizeof(servAddr)) &lt; 0)
	{
		NSLog(@"connect error.");
		return;
	}
	_connected = YES;
	NSLog(@"connect succeed.");
}</pre>
<p>送信：</p>
<pre>-(void)send:(NSString *)message
{
  mes = [message UTF8String];
  mesLen = strlen(mes);
  // 送信
  if(send(sock, mes, mesLen, 0) != mesLen) {
    NSLog(@"send failed.");
  }
}</pre>
<p>ちなみに、<br />
TCPSendClientクラスは、Socket処理を受け持つクラスで、自作しています。<br />
TCPSendClient.hはこんな風に書いています。</p>
<pre>#import &lt;Foundation/Foundation.h&gt;
#import &lt;stdio.h&gt;
#import &lt;sys/socket.h&gt;
#import &lt;arpa/inet.h&gt;
#import &lt;stdlib.h&gt;
#import &lt;string.h&gt;
#import  &lt;unistd.h&gt;

@interface TCPSendClient : NSObject {
	int sock;
	struct sockaddr_in servAddr;
	unsigned short servPort;
	const char *servIP;
	const char *mes;
	unsigned int mesLen;
	BOOL _connected;
}

-(void)connect:(NSString *)ip toPort:(NSInteger)port;
-(void)send:(NSString *)message;
-(void)close;
-(BOOL)getConnected;
@property(readonly) BOOL connected;

@end</pre>
<p>このサンプルでは、このようにTCPSendClientを使っています。</p>
<p>PagerViewController.m</p>
<pre>-(IBAction) processConnect:(id)sender  // ボタンをタップした時のAction
{
	if([connectSwitch isOn])  // これは、接続のon/offを切り替えるUISwitchです。
	{
		[sendc connect:@"10.0.2.1" toPort:43243];  // sendcというのがTCPSendClientです
		stateField.text = @"connect";
	}
	else
	{
		[sendc close];  // 本文では紹介しなかったですが、切断します。
		stateField.text = @"disconnect";
	}
}</pre>
<p>データ送信：</p>
<pre>-(IBAction) btnUp:(id)sender  // 各ボタンのTouchUpInsideと関連づけています。
{
	isPress = NO;
	prevValue = 0;
	if( (UIButton*)sender == btn) // btnとは、一つ前の動画にフォーカスをあてるためのボタンです。
	{
		dir = @"prev";
		[sendc send:dir];
	}
	else if((UIButton*)sender == nextBtn) { // nextBtnとは、一つ次の動画にフォーカスをあてるためのボタンです。
		dir = @"next";
		[sendc send:dir];
	}
	else if((UIButton*)sender == playBtn) { // playBtnとは、フォーカスがあたっている動画を再生するためのボタンです。
		dir = @"play";
		[sendc send:dir];
	}
}</pre>
<p>ちなみに、こちらがiPhoneアプリの画面です。（すごい地味ですね。。。笑えない）</p>
<p>Interface Builderのキャプチャです。</p>
<p><a rel="lightbox" href="http://blog.hi-farm.net/wp-content/uploads/2010/02/ib.png"><img class="aligncenter size-full wp-image-244" title="ib" src="http://blog.hi-farm.net/wp-content/uploads/2010/02/ib.png" alt="ib" width="320" height="502" /></a></p>
<p><strong>Macをルーターにする</strong><br />
最後に、iPhoneとAIRサーバーを接続するための設定をします。Macなら「インターネット共有」を使えば簡単にルーターにして連携させる事が可能です。こういうときに、一つのメーカーが作っている事が良い事に思えますね。<br />
今回は、AirMac経由で共有します。</p>
<p><a rel="lightbox" href="http://blog.hi-farm.net/wp-content/uploads/2010/02/kyouyuu.png"><img class="aligncenter size-full wp-image-246" title="kyouyuu" src="http://blog.hi-farm.net/wp-content/uploads/2010/02/kyouyuu.png" alt="kyouyuu" width="668" height="547" /></a></p>
<p>1. 「システム環境設定」を開く<br />
2. 「共有」を開く<br />
3. 「インターネット共有」を選択する<br />
4. 「共有する接続回路」がAirMac以外であることを確認。なっていなければ変更します。<br />
→iPhoneとMacをAirMac（無線）で接続する<br />
5.  「インターネット共有」のチェックを入れると、共有を開始するか確認してきますので、開始をクリックします。すると、画面右のAirmacのアイコンがこのようになります。</p>
<p><a rel="lightbox" href="http://blog.hi-farm.net/wp-content/uploads/2010/02/airmac.png"><img class="aligncenter size-full wp-image-243" title="airmac" src="http://blog.hi-farm.net/wp-content/uploads/2010/02/airmac.png" alt="airmac" width="251" height="24" /></a></p>
<p>開始順としては、AIRサーバーとiPhoneが接続する必要があるので、<br />
1. Macをルーターにする<br />
2. AIRサーバーアプリを起動する<br />
3. iPhoneアプリを起動して接続する。<br />
4. iPhone上で操作する。</p>
<p>というところです。</p>
<p>今回簡単に紹介しすぎててすみません。このままでわかりにくいなどご意見ありましたら整理した上で、ソース込みで全て公開します。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hi-farm.net/2010/02/25/iphone%e3%81%a7flash%e3%81%ae%e7%94%bb%e9%9d%a2%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

