现在的位置: 首页 > 综合 > 正文

注册你app所支持的文件类型以及Document interaction案例 续

2013年06月30日 ⁄ 综合 ⁄ 共 2749字 ⁄ 字号 评论关闭

可能之前的描述不够清晰:导致一些细节问题,再次多整理写内容

前文:注册你app所支持的文件类型以及Document interaction案例  http://blog.csdn.net/gnicky/article/details/7536751

第一,这个DI controller是一个ios知识点,可以深入看一下

          Understanding Document Interaction Controller

第二,操作实践过程中,选择文档以及类型,存在问题

比如寻找doc的uti

文件后缀和UTI的串

https://developer.apple.com/library/mac/#documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

更多的对应可以参考:

 Apple's Uniform
Type Identifiers Overview

com.microsoft.doc是表格的第一栏,是identity

第三,这里的两个重点,一是role:二是文档扩展名例如xls,ppt等

I think the role and the file extension are missing.
If you want to specify a file extension, you need to add UTTypeTagSpecification:

我觉得缺少的了Role和文件扩展名
如果你想指定一个文件扩展名,你需要添加UTTypeTagSpecification KEY


    <key>UTExportedTypeDeclarations</key>
<array>

    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.text</string>
        </array>
        <key>UTTypeDescription</key>
        <string>my document type</string>
        <key>UTTypeIdentifier</key>
        <string>com.mycompany.myfiletypename</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>iws</string>
            </array>
        </dict>
    </dict>

For the role, you need to add CFBundleTypeRole:

关于Role,你需要添加CFBundleTypeRole KEY

<key>CFBundleDocumentTypes</key>

<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>My file</string>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>document-320.png</string>
            <string>document-64.png</string>
        </array>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.mycompany.myfiletypename</string>
        </array>
    </dict>
</array>

第四,这个DI Controller和 自定义URL来启动别的APP是两个不同的概念,本博也介绍过自定义URL启动其它APP(一般是自己的一个系列的app) 

打开附件时您的应用程序将被启动,您将需要在您的应用程序中处理这个文件通过didFinishLaunchingWithOptions:应用程序委托方法看来,通过这种相应收到的电子邮件文件复制到应用程序的文件目录的子目录中加载方式,通过应用程序中的委托方法,类似于下面的代码方法您可以得到文件

NSURL*url=(NSURL*)[launchOptions
valueForKey
:UIApplicationLaunchOptionsURLKey];

Note that this is the same approach we used for handling custom URL schemes. You can separate the file URLs from others by using code like the following:

注意,这是我们处理自定义的URL计划使用相同的方法通过使用类似于下面的代码你可以区分其开其他的文件URL

if([url
isFileURL
])
{
    
//
Handle file being passed in

}
else
{
    
//
Handle custom URL scheme

}
第五,

如果这个APP是已经启动的,在后台,就不会进入didfinishedlaunchingwithOptions函数。会选择

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation =====
-(BOOL)application:(UIApplication *)application
           openURL:(NSURL *)url
 sourceApplication:(NSString *)sourceApplication
        annotation:(id)annotation {   
    if (url != nil && [url isFileURL]) {
        //[self.viewController handleDocumentOpenURL:url];====〉在这个层次打开文件
    }   
    return YES;}
 

 


抱歉!评论已关闭.