2012-10-07 12 views
8

Sto tentando di creare/esportare un tipo UTI esclusivo per la mia app iOS (molto simile a come Instagram gestisce esclusivamente UTI com.instagram.exclusivegram).UTI iOS esclusivo

In pratica, voglio che com.photoapp.photo sia l'app che può essere utilizzata da un'app se vuole poter aprire la foto in qualsiasi app registrata per scattare foto (simile a com.instagram.photo di Instagram). Quindi voglio che com.photoapp.exclusive sia in grado di aprire solo nella mia app (simile a com.instagram.exclusivegram).

Quello che sto provando sul mio dispositivo è che anche quando si utilizza com.photoapp.exclusive, UIDocumentController mi chiede di aprirlo in PhotoApp o DropBox dove dovrebbe essere solo PhotoApp.

Ho la mia app che registra l'UTI nonché un'app di esempio che sto usando per verificare l'abilità di apertura. Il codice che sto usando l'esempio app è al di sotto:

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"photoapp://"]]) { 
     NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"derp.png"], 1.0); 
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *fullPathToFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"photoapp.pae"]; 
     [imageData writeToFile:fullPathToFile atomically:NO]; 

     interactionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"file://%@", fullPathToFile]]]; 
     interactionController.UTI = @"com.photoapp.exclusive"; 
     interactionController.delegate = self; 

     [interactionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES]; 
    } 

E qui è quello che ho nel mio file plist per la mia app:

<key>UTExportedTypeDeclarations</key> 
<array> 
    <dict> 
     <key>UTTypeDescription</key> 
     <string>Exclusive PhotoApp Photo</string> 
     <key>UTTypeConformsTo</key> 
     <array> 
      <string>com.photoapp.photo</string> 
     </array> 
     <key>UTTypeIdentifier</key> 
     <string>com.photoapp.exclusive</string> 
     <key>UTTypeTagSpecification</key> 
     <dict> 
      <key>public.filename-extension</key> 
      <string>pae</string> 
     </dict> 
    </dict> 
    <dict> 
     <key>UTTypeTagSpecification</key> 
     <dict> 
      <key>public.filename-extension</key> 
      <string>pa</string> 
     </dict> 
     <key>UTTypeIdentifier</key> 
     <string>com.photoapp.photo</string> 
     <key>UTTypeDescription</key> 
     <string>PhotoApp Photo</string> 
     <key>UTTypeConformsTo</key> 
     <array> 
      <string>public.png</string> 
      <string>public.jpeg</string> 
     </array> 
    </dict> 
</array> 
<key>UIFileSharingEnabled</key> 
<true/> 
<key>CFBundleDocumentTypes</key> 
<array> 
    <dict> 
     <key>LSItemContentTypes</key> 
     <array> 
      <string>com.photoapp.exclusive</string> 
      <string>com.photoapp.photo</string> 
     </array> 
     <key>CFBundleTypeName</key> 
     <string>Photo</string> 
     <key>LSHandlerRank</key> 
     <string>Default</string> 
    </dict> 
</array> 
+1

Non appena si specifica che il formato del file è conforme a 'public.png' o' public.jpeg' o simile, tutte le app che specificano che possono aprire i file di queste UTI saranno in grado di aprirli. Se rimuovi la tua matrice 'UTTypeConformsTo', dovrebbe risolvere il tuo problema. – Greg

+1

In altre parole, non specificare che il tuo 'com.photoapp.exclusive' sia conforme a' com.photoapp.photo'. Lascia 'com.photoapp.photo' così com'è, e non specificare alcuna conformità per' com.photoapp.exclusive'. – Greg

+0

Grazie! Vuoi fare un commento in modo che io possa accettare la tua risposta? – joshholat

risposta

5

Non appena si specifica un UTI come public.png o public.jpeg, tutte le app che specificano che possono aprire file di questi tipi saranno in grado di aprire il file. Pertanto, se non specifichi alcun tipo di conformità nell'UCI com.photoapp.exclusive, non sembrerà che app lo supportino.

Problemi correlati