2014年3月30日日曜日

Mailアタッチメントのインポート

Supporting Files > ...-info.plistを選択

Information Property Listの+をクリックし、Document typesを追加

Document typesにサポートするDocument Content Type UTIsを追加

ここまででMail添付のファイルをプレスしたときにこのアプリのアイコンも表示されるされるようになる。

AppDelegateにapplication:openURL:sourceApplication:メソッド追加
他のアプリからファイルオープンで起動またはアクティベイトされた場合に呼ばれる。
メソッドが呼ばれたとにきには既にInboxにインポートするファイルがコピーされている。
- (BOOL)application:(UIApplication *)application
                                openURL:(NSURL *)url
                  sourceApplication:(NSString *)sourceApplication
                             annotation:(id)annotation
{
    //url=コピーされたファイルのURL
}

Inboxディレクトリの場所
NSString *inboxDir = [NSString stringWithFormat:@"%@/Documents/Inbox", NSHomeDirectory()];

Inbox内のファイルリスト

NSFileManager *fileManager = [NSFileManager defaultManager];

NSArray *files = [fileManager subpathsAtPath: inboxDir];

テキストファイルの場合
NSStringEncoding enc;
NSString *inboxText = [NSString stringWithContentsOfFile:fullPath usedEncoding:&enc error:&err];

参考: Registering the File Types Your App Supports

カスタムタイプ追加例

  • ExporTTypeUTIsを追加。子要素が自動的に追加される。
  • Conforms to UTIsに親定義を設定。ここではpublic.plane-textを選択。
  • identifierにユニークな識別子を設定。
  • Equivalent Typesにpublic.filename-extensionを追加し、拡張子を設定。
  • Document Types/Document Content Type UTIsにItemを追加し、上記identifierを設定する。

0 件のコメント: