j3k0 / cordova-plugin-openwith

Get your Cordova App in the O.S. "Share" menu on iOS and Android
MIT License
137 stars 114 forks source link

iOS: File Not Received While App is in Background + Background Task Assertion #106

Open michaellavender opened 4 years ago

michaellavender commented 4 years ago

So after struggling with getting everything set up correctly I finally have this working so that I can send a file on iOS and it's received by my app, BUT the event handler is only called when I switch back over to my app and until I do that the sent file is sitting in limbo.

Running in debug mode against my phone from Xcode I can see that the plugin initialized successfully, and nothing is logged indicating an issue. I switch over to Photos and do the open-with action and select my app, then I get the dialog showing the selected image and can enter a message. I tap Post and the window closes, but my handler is not invoked. It's only when I switch over to my app that I get the following:

[ProcessSuspension] 0x######## - WKProcessAssertionBackgroundTaskManager: Ignored request to start a new background task because the application is already in the background  
[ProcessSuspension] 0x######## - WKProcessAssertionBackgroundTaskManager: Ignored request to start a new background task because the application is already in the background  
intent received  
...  
THREAD WARNING: ['OpenWithPlugin'] took '776.545898' ms. Plugin should use a background thread.

Similarly, if my app isn't running and I use the open-with action from Photos it doesn't cause my app to open. When I then run my app in debug mode using Xcode it picks up the message once the app loads, but logs the following warning:

THREAD WARNING: ['OpenWithPlugin'] took '57.57021' ms. Plugin should use a background thread.  
openwith initialized  
intent received  
...

The 'openwith initialized' message is one I'm logging in the success callback of cordova.openwith.init

After either switching to my app or starting it running the phone immediately switches me back over to the Photos app, away from my app even though it only activated my app when I switched over to it or started it running.

I'm really hoping I'm doing something incorrect here and that the plugin should be activating my app if it's not running or is in the background to process the openwith handler. The communication does seem to be happening and the App Group, etc., seem to be properly configured because it's capable of sending and receiving the file, but having to manually activate / run the app in order to get it receive the sent file isn't really practical because for the user it seems like they sent their file, but nothing happened.

This is using version 2.0.0 of the plugin and I'm running Xcode 11.5 and iOS 13.5.1 on an iPhone.