Loading

Monday, August 22, 2011

Open Doc Files from Another Application

1. in AppDelegate
if (launchOptions && [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey])
{

printf("Launch options:\n");
CFShow(launchOptions);
NSString *filePath = [NSString stringWithFormat:@"%@", (NSURL*)[launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSMutableArray *ArrTmp;
if ([[prefs objectForKey:@"DocArray"] count])
{
ArrTmp=[[prefs objectForKey:@"DocArray"] mutableCopy];
}
else
{
ArrTmp=[[NSMutableArray alloc] init];
}
[ArrTmp addObject:filePath];
[prefs setObject:ArrTmp forKey:@"DocArray"];

}


2. Add These Value in infoPList


CFBundleDocumentTypes


CFBundleTypeIconFile
Icon.png
CFBundleTypeName
PDF
CFBundleTypeRole
Editor
LSItemContentTypes

com.adobe.pdf

LSTypeIsPackage

NSDocumentClass
Document
NSPersistentStoreTypeKey
Binary


CFBundleTypeIconFile
Icon.png
CFBundleTypeName
BMP
CFBundleTypeRole
Editor
LSItemContentTypes

com.microsoft.bmp

LSTypeIsPackage

NSDocumentClass
Document
NSPersistentStoreTypeKey
Binary


CFBundleTypeIconFile
Icon.png
CFBundleTypeName
W8BN
CFBundleTypeRole
Editor
LSItemContentTypes

com.microsoft.word.doc

LSTypeIsPackage

NSDocumentClass
Document
NSPersistentStoreTypeKey
Binary


CFBundleTypeIconFile
Icon.png
CFBundleTypeName
XLS8
CFBundleTypeRole
Editor
LSItemContentTypes

com.microsoft.excel.xls

LSTypeIsPackage

NSDocumentClass
Document
NSPersistentStoreTypeKey
Binary


CFBundleTypeIconFile
Icon.png
CFBundleTypeName
SLD8
CFBundleTypeRole
Editor
LSItemContentTypes

com.microsoft.powerpoint.​ppt

LSTypeIsPackage

NSDocumentClass
Document
NSPersistentStoreTypeKey
Binary




Now it handle PDF,Doc,Xls,Ppt files and you have all open files in Userdefault named "DocArray"

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