La primera parte se resuelve agregando una líneas al Info.plist.
Suponiendo que la extensión sea .abc y que dentro en realidad sea un archivo comprimido zip el código sería el siguiente:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>abc</string>
</array>
<key>CFBundleTypeIconFiles</key>
<array>
<string>abc-doc-small.png</string>
<string>abc-doc-big.png</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/abc</string>
</array>
<key>CFBundleTypeName</key>
<string>ABC</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.tyflos.abc</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>com.pkware.zip-archive</string>
</array>
<key>UTTypeDescription</key>
<string>ABC Document</string>
<key>UTTypeIdentifier</key>
<string>com.tyflos.abc</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>abc</string>
<key>public.mime-type</key>
<string>application/abc</string>
</dict>
</dict>
</array>
Notarás que debes proveer dos iconos, uno de 64x64 y otro de 320x320. Esos son los iconos que se muestran por ejemplo en mail cuando recibes un adjunto de tipo abc.
Luego debes implementar el siguiente método en tu "AppDelegate.m"
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
Este es el mismo método que llama el sistema cuando tu aplicación está registrada para gestionar URLs por lo que deberás asegurarte de que lo que te llega es un archivo:
if ([url isFileURL]) {
NSURL *theDestinationURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()]
URLByAppendingPathComponent:[url lastPathComponent]];
NSError *theError = NULL;
BOOL theResult = [[NSFileManager defaultManager] moveItemAtURL:url toURL:theDestinationURL error:&theError];
}
Este ejemplo lo que hace es mover el archivo que te llega al directorio temporal de tu aplicación.
respondido
09 Nov '11, 09:20
Iván Leider ♦
1.4k626