在Files顯示自己的APP
info.plist 添加Supports opening documents in place(LSSupportsOpeningDocumentsInPlace)
就可以在On My iPhone看到自己的APP,如果沒(méi)有的話,就打開相冊(cè)隨便分享一個(gè)圖片到Save to Files就會(huì)出現(xiàn)


Application supports iTunes file sharing(UIFileSharingEnabled)是指把Documents共享給iTunes,連上數(shù)據(jù)線可以在文件共享看到對(duì)應(yīng)App的Document文件夾的數(shù)據(jù),因此對(duì)一些私密的文件來(lái)說(shuō)是不安全的。所以想開共享,又不想暴露太多文件數(shù)據(jù)的話,需要調(diào)整項(xiàng)目文件的讀取路徑。
如果不是那么重要的文件,我們可以將它們存放在 NSCachesDirectory 或者是 NSTemporaryDirectory 文件夾下面;如果它是重要的文件,大多數(shù)情況下,我們是需要將它們備份在 iCloud 上的,這樣的文件我們建議將它存放在 NSApplicationSupportDirectory目錄下。

第三方App調(diào)用自己的App打開

針對(duì)系統(tǒng)相冊(cè)處理方式與其他APP并不一樣,下面方式是針對(duì)一般第三方App。系統(tǒng)相冊(cè)需要添加Share Extension,可以看這篇文章
在區(qū)域1顯示自己的APP
info.plist中添加
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Type Name</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>LSItemContentTypes</key>
<array>
<string>com.example.plain-text</string>
</array>
</dict>
</array>
CFBundleDocumentTypes只要有數(shù)據(jù),會(huì)在target setting info中相對(duì)應(yīng)顯示。

CFBundleTypeName:文檔的類型名稱(自定義輸入)
Handler rank:字符串類型,包含Owner,Default,Alternate,None四個(gè)可選值,指定對(duì)于某種類型的優(yōu)先權(quán)級(jí)別,而Launcher Service會(huì)根據(jù)這個(gè)優(yōu)先級(jí)別來(lái)排列顯示的App的順序。優(yōu)先級(jí)別從高到低依次是Owner,Alternate,Default。None表示不接受這種類型。
LSItemContentTypes根據(jù)UTIs lists定義,并非亂填。
基本上用
<string>com.microsoft.powerpoint.ppt</string>
<string>com.microsoft.word.doc</string>
<string>com.microsoft.excel.xls</string>
<string>com.adobe.pdf</string>
<string>public.item</string>
<string>public.image</string>
<string>public.content</string>
<string>public.composite-content</string>
<string>public.archive</string>
<string>public.audio</string>
<string>public.movie</string>
<string>public.text</string>
<string>public.data</string>
就能涵蓋大部分常用類型,其它的字段都可以隨意添加,會(huì)顯示在Additional document type properties中
第三方應(yīng)用打開文件會(huì)調(diào)用下面的代理方法
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation
{
if (self.window) {
if (url) {
NSString *fileNameStr = [url lastPathComponent];
NSString *Doc = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/localFile"] stringByAppendingPathComponent:fileNameStr];
NSData *data = [NSData dataWithContentsOfURL:url];
[data writeToFile:Doc atomically:YES];
NSLog(@"文件已存到本地文件夾內(nèi)");
}
}
return YES;
}
這樣就可以根據(jù)自己的業(yè)務(wù)做保存或打開。
在區(qū)域2顯示自己的APP
在target中添加新target:Action Extension

之后看這篇文章(http://www.itdecent.cn/p/37f23426bb04)
info.plist其它key解讀
UISupportsDocumentBrowser
如果應(yīng)用使用UIDocumentInteractionController來(lái)打開文件,info.plist就要將 UISupportsDocumentBrowser設(shè)置為YES