react-native-documents / document-picker

Document Picker for React Native
https://react-native-documents.github.io/
MIT License
1.35k stars 438 forks source link

Unable to select Google Drive files on iOS #97

Closed CarlaTeo closed 6 years ago

CarlaTeo commented 6 years ago

Native files (docs, sheets, slides) appear to be unselectable, meanwhile on Android they appear selectable as PDF (it seems they are automatically converted, but that's OK for me).

img_da1797075694-2

It used to work on iOS too.

dantman commented 6 years ago

What settings are you using to open the picker?

CarlaTeo commented 6 years ago

@dantman I'm using this:

DocumentPicker.show({ filetype: ['public.content'] }, (error, response) => {
      if (error) {
        doReject(error);
      } else {
        doResolve(decodeURIComponent(response.uri));
      }
    });
CarlaTeo commented 6 years ago

This situation happened to some Androids too, but cleaning the cache of Google Drive solved the problem to them, but not to iOS users.

dantman commented 6 years ago

Try adding 'com.adobe.pdf' to your filetype list.

Then instead of that try adding 'com.microsoft.word.doc', 'com.microsoft.excel.xls'.

CarlaTeo commented 6 years ago

Using 'com.adobe.pdf'only the pdf file was selectable, and using 'com.microsoft.word.doc', 'com.microsoft.excel.xls' none of them became selectable...=/

dantman commented 6 years ago

com.adobe.pdf inherits from public.data and public.composite-​content, public.composite-​content inherits from public.content. So it's strange if it's only available when listing pdf. But I guess that's just a Drive/iOS quirk.

If the word and excel UTIs don't work, then Drive is either using mysterious unidentified custom UTIs we don't know or using the root public.item and not bothering to give their documents proper types.

You can use public.item, but that will select absolutely everything. Including any non-content items declaring UTis for databases, calendar events, emails, SMS messages, executable binaries, archives, URLs, vCards, etc if the document provider exposes them.

CarlaTeo commented 6 years ago

Thank you very much, Daniel, it does the job. Later I'll explore more what UTIs Google might be using, but for now I'll stay with your fix. 😄

PS: I also asked on StackOverflow, you may post your solution there too so that I can accept. Otherwise, later I'll answer it myself and link it to your answer here.

dantman commented 6 years ago

You could try out org.openxmlformats.spreadsheetml.sheet.

Also, if you switch to v3 you could add something like this to export the UTI in the metadata:

NSString *utiString = (__bridge_transfer NSString *)uti;
[result setValue:utiString forKey:@"uti"];

Then you can use public.item to make everything selectable and investigate what Drive gives for the UTI when you select it. (Though it's based on file extension so I can't guarantee it's the same, but it's a start)

CarlaTeo commented 6 years ago

I tried org.openxmlformats.spreadsheetml.sheet with no success.

I'll take a look in v3.

In the meantime, do you know by any chance how could I convert the files to PDF? Because they are being picked with gdoc/gsheet extensions, that only works in the GDrive app. =/

dantman commented 6 years ago

Android offers an API for converting to a mime type if the DocumentProvider supports it. But I am not aware of any API like that for iOS.