Chinaunix首页 | 论坛 | 博客
  • 博客访问: 541186
  • 博文数量: 78
  • 博客积分: 1913
  • 博客等级: 上尉
  • 技术积分: 829
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-14 21:29
文章分类

全部博文(78)

文章存档

2011年(27)

2010年(26)

2009年(20)

2008年(5)

我的朋友

分类: LINUX

2011-07-18 16:31:46

File type handling is new with iPhone OS 3.2, and is different than the already-existing custom URL schemes. You can register your application to handle particular document types, and any application that uses a document controller can hand off processing of these documents to your own application.

For example, my application Molecules (for which the source code is available) handles the .pdb and .pdb.gz file types, if received via email or in another supported application.

To register support, you will need to have something like the following in your Info.plist:

CFBundleDocumentTypeskey>

   

       
CFBundleTypeIconFileskey>
       

           
Document-molecules-320.pngstring>
           
Document-molecules-64.pngstring>
       
array>
       
CFBundleTypeNamekey>
       
Molecules Structure Filestring>
       
CFBundleTypeRolekey>
       
Viewerstring>
       
LSHandlerRankkey>
       
Ownerstring>
       
LSItemContentTypeskey>
       

           
com.sunsetlakesoftware.molecules.pdbstring>
           
org.gnu.gnu-zip-archivestring>
       
array>
   
dict>
array>

Two images are provided that will be used as icons for the supported types in Mail and other applications capable of showing documents. The LSItemContentTypes key lets you provide an array of Uniform Type Identifiers (UTIs) that your application can open. For a list of system-defined UTIs, see Apple's Uniform Type Identifiers Reference. Even more detail on UTIs can be found in Apple's Uniform Type Identifiers Overview. Those guides reside in the Mac developer center, because this capability has been ported across from the Mac.

One of the UTIs used in the above example was system-defined, but the other was an application-specific UTI. The application-specific UTI will need to be exported so that other applications on the system can be made aware of it. To do this, you would add a section to your Info.plist like the following:

UTExportedTypeDeclarationskey>

   

       
UTTypeConformsTokey>
       

           
public.plain-textstring>
           
public.textstring>
       
array>
       
UTTypeDescriptionkey>
       
Molecules Structure Filestring>
       
UTTypeIdentifierkey>
       
com.sunsetlakesoftware.molecules.pdbstring>
       
UTTypeTagSpecificationkey>
       

           
public.filename-extensionkey>
           
pdbstring>
           
public.mime-typekey>
           
chemical/x-pdbstring>
       
dict>
   
dict>
array>

This particular example exports the com.sunsetlakesoftware.molecules.pdb UTI with the .pdb file extension, corresponding to the MIME type chemical/x-pdb.

With this in place, your application will be able to handle documents attached to emails or from other applications on the system. In Mail, you can tap-and-hold to bring up a list of applications that can open a particular attachment.

When the attachment is opened, your application will be started and you will need to handle the processing of this file in your -application:didFinishLaunchingWithOptions: application delegate method. It appears that files loaded in this manner from Mail are copied into your application's Documents directory under a subdirectory corresponding to what email box they arrived in. You can get the URL for this file within the application delegate method using code like the following:

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:

if ([url isFileURL])
{
   
// Handle file being passed in
}
else
{
   
// Handle custom URL scheme
}

阅读(1511) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~