UIDocumentPickerViewController中的iOS自定义UTI initWithDocumentTypes

我试图在我的应用程序中从iCloud驱动器打开.obj文件抛出UIDocumentPickerViewController。 我找不到.obj文件的标准UTi。 因此,使用此https://developer.apple.com/library/content/qa/qa1587/_index.html我尝试为我的应用添加对此文件扩展名的支持。

有info.plist部分:

CFBundleDocumentTypes   CFBundleTypeIconFiles  arrow1  CFBundleTypeName OBJ model CFBundleTypeRole Editor LSHandlerRank Owner LSItemContentTypes  com.giena.Interface.obj    UTExportedTypeDeclarations   UTTypeConformsTo  public.data  UTTypeDescription OBJ model UTTypeIdentifier com.giena.Interface.obj UTTypeSize320IconFile arrow1 UTTypeSize64IconFile arrow1 UTTypeTagSpecification  public.filename-extension  obj     

并且有UIDocumentPickerViewController调用:

  UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.text"] inMode:UIDocumentPickerModeOpen]; documentPicker.delegate = self; documentPicker.modalPresentationStyle = UIModalPresentationFormSheet; [self presentViewController:documentPicker animated:YES completion:nil]; 

当我运行应用程序时,我看到文件选择的弹出视图,但.obj文件是灰色的,不可选择。 我究竟做错了什么?

您应该在文档类型列表中使用自定义UTI:

 UIDocumentPickerViewController *documentPicker =[[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.giena.Interface.obj"] inMode:UIDocumentPickerModeOpen];