EinfachHans / capacitor-email-composer

E-Mail Composer Plugin for Capacitor
MIT License
21 stars 7 forks source link

App crashes on IOS #30

Closed UAjinkya closed 7 months ago

UAjinkya commented 1 year ago

Hi, I have configured outlook as default mail provider. When I try to open email composer the app is crashing with below error.

⚡️ To Native -> EmailComposer hasAccount 88263923 ⚡️ TO JS {"hasAccount":false} ⚡️ To Native -> EmailComposer open 88263924 [MFMailComposeViewController] Unable to initialize due to + [MFMailComposeViewController canSendMail] returns NO. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <Capacitor.CAPBridgeViewController: 0x10610be80>.' First throw call stack: (0x1aba21e88 0x1a4dc38d8 0x1adefc898 0x1adefb7ec 0x1aded9984 0x1adca7af0 0x1adca792c 0x105044934 0x105044aa8 0x1057145a8 0x10571605c 0x105726810 0x105726354 0x1abab26f8 0x1aba94058 0x1aba98ed4 0x1e44f1368 0x1adf773d0 0x1adf77034 0x104c67e14 0x1ca0f0960) libc++abi: terminating with uncaught exception of type NSException

Ionic info Ionic:

Ionic CLI : 7.0.1 Ionic Framework : @ionic/angular 6.7.5 @angular-devkit/build-angular : 13.1.2 @angular-devkit/schematics : 12.1.4 @angular/cli : 13.1.2 @ionic/angular-toolkit : 4.0.0

Capacitor:

Capacitor CLI : 4.8.1 @capacitor/android : not installed @capacitor/core : 4.8.1 @capacitor/ios : 4.8.1

tih95 commented 11 months ago

@UAjinkya Hey im running into the same issue, have you found a solution to this?

UAjinkya commented 11 months ago

Hi @tih95 ,I have not found solution instead I am using simple window.open("mailto:"+emailTo+'?cc='+emailCC+'&subject='+emailSub+'&body='+emailBody)

EinfachHans commented 10 months ago

I will try to address this as soon as i can - so less time atm 😩

mariusbolik commented 10 months ago

Here is some information from sentry about device type and os. Maybe this helps a bit :)

Bildschirmfoto 2023-11-08 um 20 03 14
EinfachHans commented 10 months ago

Hey everybody,

just wanted to fix that, but it looks like the ios interface doesn't respects the default mail app at all. Thats what i found in the documentation and what i experience in my demo app: I changed the default app and opening the email composer works quite well.

So i guess the issue appears when a user has delete the apple mail app on his device. You don't check that with hasAccount before trying to open the mail composer.

Now how to improve this? Good question. A lot of people just use a mailto link, which works with the default, but can't be implemented in this plugin, because it supports for example attachments.

The Cordova Plugin exposes some methods to check for hasClient and options to open the mail composer of a specific client.

But even with this there is still no automatic default detection possible in ios code as it seems, so users are still forced to implement their own logic like: try open in order (apple mail, outlook, ...) until it works or something like ask the user where to open it. I'm not a fan of both tbh.

So now i need a little bit of your input, how we should handle this 🤔

EinfachHans commented 7 months ago

I still need feedback on this, otherwise i'm going to close this issue...