crazecoder / open_file

A plug-in that can call native APP to open files with string result in flutter, support iOS(UTI) / android(intent) / PC(ffi) / web(dart:html)
BSD 3-Clause "New" or "Revised" License
252 stars 438 forks source link

iOS - Open File #8

Closed daryll-fourie closed 6 years ago

daryll-fourie commented 6 years ago

Hi,

First of all, great work on the plugin! It really helped me a lot with a Flutter App I'm currently busy with.

I just have a question regarding the iOS implementation: I noticed that in Android, when calling open, it actually opens the .jpeg/.pdf in the relevant app on the device. When calling open on an iOS simulator, it opens a dialog from the bottom giving me the options to "Share" the file via AirDrop, ICloud Photo Sharing and also a "Save to Files" option. Is this standard behaviour?

I would expect it to just open the .jpeg/.pdf in the relevant app, just like in Android?

I haven't been able to test this on an actual iOS device yet, so it might be a simulator issue. I just wanted to confirm this behaviour. Please let me know if this is how the plugin should work or am I missing something here?

Keep up the great work!

Regards, Daryll Fourie

crazecoder commented 6 years ago

Yes, it is different on the simulator and on the real machine.

daryll-fourie commented 6 years ago

Okay, thx for the speedy response. I will make sure to test this on an actual device.

Regards, Daryll Fourie

daryll-fourie commented 6 years ago

I just tested this on an iPhone 5s and it also opens that "Share" view.

Please see the attached screenshot: image

I tested this with a .jpeg and a .pdf file.

daryll-fourie commented 6 years ago

Hey, do you perhaps have any feedback regarding this?

If you want, I can create a pull request and see if I can fix the issue on my side. Let me know if I can help you out :)

I'm an Android dev actually but I don't mind working with XCode every now and then.

Regards, Daryll

crazecoder commented 6 years ago

This may be a mechanism issue, and can be previewed if the third-party application is open to the public.

daryll-fourie commented 6 years ago

Unfortunately I cannot share the third-party application as it is a company private in-house app.

When you say a mechanism issue, what do you mean with that? Currently, I just have a .jpeg which is saved in the getApplicationDocumentsDirectory, which is the default Documents directory, is that correct?

daryll-fourie commented 6 years ago

I just checked on my iOS testing device, the path where the file is stored is : /var/mobile/Containers/Data/Application/15EB2091-D8A2-42FF-8379-B3A9CC511F73/Documents/Docs/58/doge.jpeg

This is the Documents directory which only the app can access (https://flutter.io/cookbook/persistence/reading-writing-files/), is this maybe the problem? That the iOS open file app cannot access the image?

Where did you store your files on the iOS device when testing this with flutter?

daniel-mf commented 6 years ago

@daryll-fourie I'm facing the same issue in my flutter app, did you find any workaround? Thanks in advance!

rtoshmukhamedov commented 6 years ago

The same issue on iOS. The bottom sheet is displaying options. However, I can't open any files.

Everything working on Android.

daryll-fourie commented 6 years ago

Hi @daniel-mf & @rtoshmukhamedov , unfortunately I haven't been able to find a solution to this problem. If I do find the problem, I will update this issue as soon as possible.

rtoshmukhamedov commented 6 years ago

May be UIDocumentInteractionController presentpreview should be used?

daniel-mf commented 6 years ago

I think instead of using presentOpenInMenuFromRect we should use presentPreviewAnimated I just followed this tutorial and it works like a charm. I'm gonna give that a try.

daryll-fourie commented 6 years ago

That's awesome @daniel-mf , well done! @crazecoder , if this works will you please merge it into your master branch?

daniel-mf commented 6 years ago

If am not mistaken, as shown in presentPreviewAnimated docs, the UIViewController should extend UIDocumentInteractionControllerDelegate and implement documentInteractionControllerViewControllerForPreview I don't know if that's possible since UIViewController is managed by the flutter framework.

Docs for presentPreviewAnimated:

// Bypasses the menu and opens the full screen preview window for the item at URL.  Returns NO if the item could not be previewed.
// Note that you must implement the delegate method documentInteractionControllerViewControllerForPreview: to preview the document.
daniel-mf commented 6 years ago

I was able to make it work as expected (at least for the few tests I've done) Took as example this plugin DocumentsPickerPlugin I have only tested PDF files, working just fine!

daryll-fourie commented 6 years ago

Hi @daniel-mf , what is the latest status of you progress? I see you've made various commits to your fork, including some Android changes which you rolled back. Is the iOS part working as expected now? I will try and reference your fork locally then I can test a few other file types (other than '.pdf') from my side.

daniel-mf commented 6 years ago

Hey @daryll-fourie, I've tested even with zip files, all working fine on iOS! You can reference my fork adding this to the dependencies section of your pubspec.yaml

open_file:
  git:
    url: git://github.com/daniel-mf/open_file.git

Just to note, I also changed Android code for the result to be asynchronous and removed the static Context property to avoid memory leak (Android Studio shows a warning about the leak).

daryll-fourie commented 6 years ago

@daniel-mf , thanks! I changed my reference in the pubspec.yaml and tested it successfully on Android. I do however get the following error & warning when compiling for iOS -->

screen shot 2018-09-19 at 10 29 09
daryll-fourie commented 6 years ago

@daniel-mf the above error I have might be as result of the version of my Xcode. It is Version 9.4.1 (9F2000), what is yours?

daniel-mf commented 6 years ago

@daryll-fourie just commited a fix for that. Please upgrade localy and check if it is working.

daryll-fourie commented 6 years ago

@daniel-mf works like a charm!! Well freaking done man! :) I tested it with the following files and it worked (on my device) : pdf, jpg & png. I'm pretty sure other file types will work too as long as the OS can handle it! Whoohooo!!! Thank you so much @daniel-mf !

@crazecoder do you perhaps want to merge his branch into yours?

rtoshmukhamedov commented 6 years ago

Thanks a lot @daniel-mf. It is working well.

rtoshmukhamedov commented 6 years ago

@crazecoder Can you merge his changes?

crazecoder commented 6 years ago

yeah,no problem

moin-nimblechapps commented 3 months ago

I have used this package, but it does not open the file manager app for .zip files on Android. Additionally, it opens the downloaded file in full screen immediately after downloading, without showing the corresponding app on iOS.

https://github.com/user-attachments/assets/e775847c-7754-4f64-81f5-de767704c499