B-Stewart
B-Stewart

Reputation: 697

Cordova Ionic email plugin not working on iOS 9 due to URL

I'm using the email composer plugin for my ionic application and I'm running into a problem on iOS 9 where I am unable to work with an external email application. I've tried adding the following to plist since it is a url scheme but that doesn't seem to have helped.

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>mailto</string>
    </array>

Error xcode gives:

2015-10-06 22:10:45.037 NSP[1830:29571] -canOpenURL: failed for URL: "mailto:[email protected]" - error: "(null)"
2015-10-06 22:10:45.044 NSP[1830:29571] -canOpenURL: failed for URL: "mailto:[email protected]" - error: "(null)"
2015-10-06 22:10:45.047 NSP[1830:29571] -canOpenURL: failed for URL: "mailto:[email protected]" - error: "(null)"

Yes, it was 3 errors on a single call. Here is the call code:

$cordovaEmailComposer.isAvailable().then(function () {
                $cordovaEmailComposer.open({
                    to: [], // email addresses for TO field
                    cc: [], // email addresses for CC field
                    bcc: [], // email addresses for BCC field
                    attachments: [], // file paths or base64 data streams
                    subject: item.name, // subject of the email
                    body: item.name + " download link: " + item.link, // email body (for HTML, set isHtml to true)
                    isHtml: false, // indicats if the body is HTML or plain text
                }, function () {
                    //console.log('email view dismissed');
                }, this);
            }, function () { //Not available
                MessageBox.ShowAlert("Unavailible", "Email is currently unavailable on this platform");
            });

Is there any way to fix this? It works great on android, and earlier versions of iOS or is it a plugin problem that I can't fix? Everything is updated. Possible workarounds or other plugins to make this work? I tried the solution here but I don't think this is related to my issue.

Upvotes: 2

Views: 1747

Answers (3)

Shankari
Shankari

Reputation: 399

I can confirm that when the stock plugin (no LSApplicationQueriesSchemes) is installed on an actual device with the mail client configured, it works great. I think that canOpenURL issues primarily occur on the simulator.

And even on the actual device, if you don't set up the default mail client, then you get all kinds of weird crashes (controller is not displayed in UI view, etc).

Just try it on a device with the mail client configured.

Upvotes: 1

John Fable
John Fable

Reputation: 1091

I had the exact same problem.

After adding LSApplicationQueriesSchemes and having no luck, I tried on an actual device and it did work properly. It just isn't working in the simulator.

A quick way to add LSApplicationQueriesSchemes is with:

cordova plugin add cordova-plugin-queries-schemes

Upvotes: 1

user3255670
user3255670

Reputation:

Okay. Two random guesses. If these don't work, I will delete this.

1) Support for Cordova for iOS9 was released just a few days ago.

Try upgrading, that may solve your problem:

https://cordova.apache.org/announcements/2015/11/02/cordova-ios-3.9.2.html

2) 'mailto:' may be subject to the whitelist rules required for Cordova Tools 5.x. You will need to apply the entire whitelist or just the CSP portion of it.

HOW TO apply the Cordova/Phonegap the whitelist system

I see no indication that this is under the new Apple ATS security filter, but it may be.

To be clear, apply CSP to the webpage, then the whitelist and plugin, the finally Apple's ATS. There are some shortcuts that are spelled out in that document.

Any question? May sure to use an @ before my handle so I get the message.

Upvotes: 1

Related Questions