AIR for iOSにおけるUIDocumentInteractionController連携方法

142 views
Skip to first unread message

内田 大輔

unread,
May 26, 2011, 10:03:29 PM5/26/11
to AIR/Flash for Android
いつも参考にさせて頂いております。

有用かどうかは微妙ですが、iOSの機能でUIDocumentInteractionControllerという
ファイル受け渡しによるアプリケーション間連携ができるのですが、
それをAIR for iOSでも他のアプリからファイルを受け取る方法が解って独りテンションが高くなりました。

以下が方法です。(Flash Builder 4.5のActionScriptモバイルプロジェクトを使用します)

1.xxx-app.xmlにiPhone用の独自設定を記述します
 (220行目付近にある<iPhone>タグの中の<InfoAdditions>タグ内に追記します

 例:(PDFファイルを受け取る場合)
<iPhone>
<InfoAdditions><![CDATA[
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>PDF</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>com.adobe.pdf</string>
</array>
</dict>
</array>
]]></InfoAdditions>
</iPhone>

2.Invokeイベントを受け取り、パラメータからPDFファイルパスを取り出す
 例:
 NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invokeHandler);

public function invokeHandler(e:InvokeEvent):void {
if(e.arguments != null) {
if(e.arguments[0] != null) {
var aseetFolder:File = new File(e.arguments[0].toString());
webview = new StageWebView();
webview.stage = this.stage;
webview.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );
if(aseetFolder.url == null || aseetFolder.url == "") {
webview.loadURL("http://www.google.co.jp/");
}
else {
webview.loadURL(aseetFolder.url);
}
}
}
}

きたない例ですが、個人的に嬉しくなっちゃったので投稿しちゃいました。
AIR for Androidの方もmanifestAdditions内に必要な設定を追記すればファイルによる暗黙のIntentは取得できました。
何らかお役に立てれば嬉しいです。

吉岡梅

unread,
May 26, 2011, 11:26:46 PM5/26/11
to af...@googlegroups.com
吉岡です。

アプリ間で通信できるのは面白いですね!

アプリケーション設定ファイル系では、UIFileSharingEnabledキーもいろいろと役に立ちますよ。
記述はこんな感じです。

<iPhone>
<InfoAdditions>
<![CDATA[
<key>UIFileSharingEnabled</key><true/>
]]>
</InfoAdditions>
</iPhone>

何の設定かといいますと、デバイスとPC間でiTunes経由でファイルのやり取りができるようにする設定です。
UIFileSharingEnabledをYES(true)に設定したアプリをインストールすると、iTunesのデバイスの[App]タブの
下端に、[ファイル共有]という項目が追加され、デバイスとPC間でファイルを共有できるようになります。

つまりはアプリで作成したファイルをPCへと取り出したり、PCで作成したファイルをアプリへ送れるというわけですね。

AS3.0でこの共有ファイルにアクセスする場合には、File.documentsDirectoryで得られる
「ドキュメントフォルダ」のパスから保存/読み込み可能です。

import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;

//「ドキュメントフォルダ」のファイル一覧を表示
var folder:File = File.documentsDirectory;
var fileList:Array = folder.getDirectoryListing();
for(var i:int=0;i<fileList.length;i++){
var file:File = fileList[i] as File
trace( file.name);
}

//「ドキュメントフォルダ」へファイルを保存
var s:String = "AIR アプリから保存したテキストファイルです"
var file:File = File.documentsDirectory.resolvePath("data.txt");
var fs:FileStream = new FileStream();
fs.open(file,FileMode.WRITE);
fs.writeUTFBytes(s);
fs.close();


また、現状はiOS向けのコンパイルはちょいと時間がかかりますので、開発時にいろいろなパラメータを調整しながら
動きを確認したいようなケースでは、この仕組みを使ってパラメータをitunes経由でコントロールできるように
しておくと便利ですよ。

ではでは。

2011年5月27日11:03 内田 大輔 <d.uch...@gmail.com>:

> --
> /**
> *
> * AIR/Flash for Android
> * http://groups.google.co.jp/group/AF4A
> *
> * To post to this group, send email to
> * AF...@googlegroups.com
> *
> * To unsubscribe from this group, send email to
> * AF4A+uns...@googlegroups.com
> *
> */
>

--

シルエロ:吉岡 梅
umeyo...@gmail.com
yosh...@ciruelo.jp

Reply all
Reply to author
Forward
0 new messages