iOS 5 iCloud プログラミング

ニンテンドーDSi ウェア ‘プチコンmkII’ で、もう一つ取り組んでいるプログラムがあります。しかし、ちょっと一段落して iOS の iCloud について調べてみました。

最初に、新しくなった Xcode 4 の復習のため

Start Developing iOS Apps Today: Introduction
https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/Introduction/Introduction.html
Your Second iOS App: Storyboards: About Creating Your Second iOS App
https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/SecondiOSAppTutorial/Introduction/Introduction.html
Your Third iOS App: iCloud: About Your Third iOS App
https://developer.apple.com/library/ios/#documentation/General/Conceptual/iCloud101/Introduction/Introduction.html

の3つの例題を試してみました。最終目的の iCloud プログラミングの理解に、3番目の Your Third iOS App が一番参考になります。iCloud は Simulator では動作しないので注意してください。

私自身、あくまでも趣味の範囲なので、iCloud の理解も UIDocument を基準にすることにしました。

iCloud に、どんなファイルが保存されているか調べるには OS X 上では

OS X (iCloud)
~/Library/Mobile Docunents

の上記フォルダで確認することができます。このフォルダの中身を変更すると問題が起こる確率が高いので、やめたほうがいいと思います。

また、iPhoneiPadiPod touch 上の

設定.app
iCloud  > ストレージとバックアップ > ストレージを管理 > 書類およびデータ

から、アプリを選択すると iCloud 内のファイルが表示されます。

右上に ‘編集’ ボタンがあるので iCloud 内のファイルを削除する時は、こちらを使うと良いと思います。

後、OS X、iOS 開発書籍の著者として有名な木下誠さんの iOS 技術情報誌アプリ

HMDT BOOKS
カテゴリ: ブック
販売業者: HMDT Co., Ltd.
http://itunes.apple.com/jp/app/hmdt-books/id500860946?mt=8
HMDT
http://hmdt.jp/

HMDT JOURNAL Vol.001
第1回 iCoud(1) iCoud とは
\170
HMDT JOURNAL Vol.002
第2回 iCoud(2) NSUbiquitousKeyValueStore
\170
HMDT JOURNAL Vol.003
第3回 iCoud(3) ファイルベースの同期
\170
HMDT JOURNAL Vol.004
第4回 iCoud(4) ドキュメントベースの同期
\170

も参考になると思います。貴重な情報源で、書籍のように邪魔にならないので、毎回購入しています。

まず最初に、Document-Based App を理解しないといけないので

Document-Based App Programming Guide for iOS: Creating a Custom Document Object
http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/DocumentBasedAppPGiOS/CreateCustomDocument/CreateCustomDocument.html#//apple_ref/doc/uid/TP40011149-CH8-SW1
▼Creating a Custom Document Object
Loading Document Data
Supplying a Snapshot of Document Data
Storing Document Data in a File Package

上の説明に出てくるソースから、Document-Based App を作りました。

また、ドキュメントデータをそれぞれ NSData、NSFileWrapper のどちらかで保存する方法も学びました。

NSURL の

+ URLWithString:
+ fileURLWithPath:

の違いに注意してください。

また、Document Type の宣言方法は、

Document-Based App Programming Guide for iOS: Document-Based Application Preflight
http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/DocumentBasedAppPGiOS/DocumentImplPreflight/DocumentImplPreflight.html#//apple_ref/doc/uid/TP40011149-CH3-SW2
▼Document-Based Application Preflight
▼Creating and Configuring the Project
Declare a Document Type

上記 URL のページが参考になります。

UTI の種類は

Uniform Type Identifiers Reference: Introduction to Uniform Type Identifiers Reference
http://developer.apple.com/library/ios/#documentation/Miscellaneous/Reference/UTIRef/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009258-SW1

を参照してください。

ここまで、Document-Based App の理解が進むと iCloud に取り掛かるのに充分だと思います。

iCloud について

Document-Based App Programming Guide for iOS: Designing a Document-Based Application
http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/DocumentBasedAppPGiOS/DocumentArchitectureiniOS/DocumentArchitectureiniOS.html#//apple_ref/doc/uid/TP40011149-CH2-SW7
▼Designing a Document-Based Application
▼A Document in iOS
 		A Document in iCloud Storage

を読んでから、もう一度

Your Third iOS App: iCloud: About Your Third iOS App
https://developer.apple.com/library/ios/#documentation/General/Conceptual/iCloud101/Introduction/Introduction.html

のソースと

Document-Based App Programming Guide for iOS: Managing the Life Cycle of a Document
http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/DocumentBasedAppPGiOS/ManageDocumentLifeCycle/ManageDocumentLifeCycle.html#//apple_ref/doc/uid/TP40011149-CH4-SW1
▼Managing the Life Cycle of a Document
▼Creating a New Document
▼Opening and Closing a Document

を参考に理解を深めると良いと思います。

Version Conflicts については

iiOS App Programming Guide: iCloud Storage
https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/iCloud/iCloud.html#//apple_ref/doc/uid/TP40007072-CH5-SW1
▼iCloud Storage
▼Using iCloud Document Storage
Choosing a Strategy to Respond to Version Conflicts

が参考になります。

また、iCoud と Local 間の Documents の移動は

Document-Based App Programming Guide for iOS: Managing the Life Cycle of a Document
http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/DocumentBasedAppPGiOS/ManageDocumentLifeCycle/ManageDocumentLifeCycle.html#//apple_ref/doc/uid/TP40011149-CH4-SW1
▼Managing the Life Cycle of a Document
▼Moving Documents to and from iCloud Storage

に説明されています。HMDT JOURNAL Vol.001 ~ Vol.004 も参考になります。

Your Third iOS App: iCloud: About Your Third iOS App
https://developer.apple.com/library/ios/#documentation/General/Conceptual/iCloud101/Introduction/Introduction.html

のソースを読んでいると Blocks

Blocks Programming Topics: Introduction
https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html
A Short Practical Guide to Blocks
https://developer.apple.com/library/ios/#featuredarticles/Short_Practical_Guide_Blocks/_index.html
Building with Blocks in C and Objective-C
https://developer.apple.com/library/mac/#featuredarticles/BuildingWithBlocks/_index.html

や GCD

Concurrency Programming Guide: Introduction
https://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/Introduction/Introduction.html

の理解も必要になってくると思います。

手っ取り早く理解したい場合は

Introducing Blocks and Grand Central Dispatch
https://developer.apple.com/library/mac/#featuredarticles/BlocksGCD/_index.html

が参考になります。

私自身、なかなか理解できない部分もあるので 、書籍

Creating iOS 5 Apps: Develop and Design

Creating iOS 5 Apps: Develop and Design

Creating iOS 5 Apps: Develop and Design [Kindle Edition]
Rich Warren (Author)
Kindle Price:
$21.99

を Amazon で購入し、iPadKindle で読んでいる途中です。iOS 5 になって変わった基本的な Objective-C の機能についての説明もあるので、今まで iOS 開発を行ってきた人にもお勧めの本です。

'プチコンmkII' 上で動作するマインスイーパの QR コード公開、新しい iPad 購入。

プチコンmkII’ 上で動作するマインスイーパの QR コードを下記 URL で公開します。

Yoshiaki's HomePage - プチコンmkII
プチコンmkII版マインスイーパ Version 1.0.0
http://kyoshiaki.sakura.ne.jp/osx/petitcom.html

良かったら、遊んでみてください。

Twitterハッシュタグ #ptcmqr でいろいろな ‘プチコンmkII’ の QR コードが公開されていますが、

SHOHD
QRコード32枚
投稿プログラム : ホラーダンジョン - プチコンまとめWiki
http://wiki.hosiken.jp/petc/?Toukou%2F%A5%DB%A5%E9%A1%BC%A5%C0%A5%F3%A5%B8%A5%E7%A5%F3
GN_TRK03
StarTrek for Petitcom
http://www2.u-netsurf.ne.jp/~ozawa/startrek/startrek.html
コマンドの詳しい解説は
Star Trek
http://www.dunnington.u-net.com/public/startrek/
で紹介されているリンク先ファイル TREK.DOC [ http://www.dunnington.u-net.com/public/startrek/TREK.DOC ] が参考になります。
KYMTREK
スタートレック
http://www1.odn.ne.jp/beni/petitcom/trek/list.html
SPEHURRI
SPECTACLE HURRICANE
『プチコン』のページ
http://www1.ocn.ne.jp/~tabby/games/ds_kkoj.html
http://www1.ocn.ne.jp/~tabby/games/ds_knaj.html
RE201
Reflect EDGE Ver2.01
http://www.geocities.jp/sp1_ssr/ReflectEDGE1.htm
TINYKITT
プチコンmkII用「ナンジグライダー」
プチコン関連
http://www.geocities.jp/tiny_yarou/petitcom/index.html
(Safari で見る場合は、メニュー/表示/テキストエンコーディング:日本語 (EUC) を選択してください。)
DROPPZL
ありそうで無かった「逆テ○リス?」
http://www.ma.mctv.ne.jp/~miche/ptc/hare/index.html
GRPSHP2P
お絵描きツール
mkII - 湯飲実験室 (QRコードと操作説明)
http://www.sotohane.com/2012/03/mkii.html#more
QRコード
http://twitpic.com/8y4hgw
G2MMLEX
G2MMLSMP
プチコンmkIIのMMLをマクロ対応にするプログラム
http://www.gradius2.com/index.php?UID=1332082863
OCHAOSP
自動歌唱ソフト OSP
OCHAOSP2
棒歌ロイド OSP2
http://ww5.tiki.ne.jp/~ochame/petitcom/1page.htm#osp
MRPLAY
MML音色試聴ツール
http://twitpic.com/8zrzq2
S51PTCL3
投稿プログラム : PetitcoLOID - プチコンまとめWiki
http://wiki.hosiken.jp/petc/?Toukou%2FPetitcoLOID

がお勧めです。後、プログラムの中断は ‘SELECT ボタン’ を押してください。

Apple が 2012年3月7日(水)AM10時 (PST) [日本時間 2012年3月8日(木)AM3時] より、米カリフォルニア州サンフランシスコの Yerba Buena Center for the Arts(YBCA)でスペシャルイベントを開催しました。新しい iPadiOS 5.1が発表されました。早速、iOS 5.1にアップデートしました。iPhone 4S を持っていないので Siri を試せないのが、残念です。

初代 iPad は、購入しました。しかし iPad 2 は Retina Display に対応していなかったので、見送りました。新しい iPad は、発表があってからすぐに ‘ホワイト WiFiモデル 32GB’ を予約しました。16日に到着しました。拙作 iYKRSSHD [ http://itunes.com/apps/iYKRSSHD ] になるべく早く対応したいです。iCloud を勉強中なので、アプリに活かしてみたいですね!

Mac OS X、Ubuntu、Cygwin、MinGW のターミナル上で動作するプチコン準拠 BASIC インタプリタ basic を公開。

Mac OS XUbuntuCygwinMinGW のターミナル上で動作する BASIC インタプリタ basic を下記 URL で公開します。

basic version 1.0.0
http://kyoshiaki.sakura.ne.jp/osx/index.html

BASIC の文法は、

プチコン
http://smileboom.com/special/petitcom/

に準拠します。ただし、スプライト、BGスクリーン、256色グラフィック、ファイルと通信、音楽などに関するステートメントと関数は、対応していません。

あくまでも、実験的に作成したものです。メモリの解放なども省いています。flex、bison、C 言語で作成され、ソースも含まれています。

実用性に乏しいですが、良かったらダウンロードしてください。

BASIC インタプリタだけだと寂しいので、Land of Lisp から

Land of LISP: Learn to Program in Lisp, One Game at a Time!

Land of LISP: Learn to Program in Lisp, One Game at a Time!

orc-battle.lisp
robots.lisp
evolution.lisp

を移植してみました。evolution.lisp の移植には、かなり苦労しました。自分で言うのも、おこがましいのですが、力作です。
後、BASIC で再帰処理とローカル変数を実現するのには無理があるので、dice_of_doom_v1.lisp はあきらめました。

Boot Camp 上に Windows 7 はインストールしてありますが、Windows プログラミングについて、ほとんど知識がありません。

Cygwin
http://www.cygwin.com/
MinGW | Minimalist GNU for Windows
http://www.mingw.org/

CygwinMinGW で何とかビルドができるように対応してみました。ただし、MinGW については、日本語表示(半角カタカナ)とエスケープシーケンスに問題があります。Cygwin がお勧めです。本当は、CygwinMinGW のインストールも説明すべきなのですが、よくわからないので省きました。ごめんなさい。

robots.bas.txt、evolution.bas.txt を実行した動画を添付しておきます。

robots.bas.txt

evolution.bas.txt