Essentials: [Bug] Email.ComposeAsync and Launcher.OpenAsync not support on iOS devices

Created on 19 Nov 2020  路  5Comments  路  Source: xamarin/Essentials

Description

Recently I migrated Xamarin.Forms from v3.6 to the latest stable v4.8. In the process, the old code that was used for opening email was Device.OpenUri("mailto:[email protected]"). But this code, Device.OpenUri is deprecated as of Xamarin.Forms v4.8. So I replace it with Xamarin.Essentials' Email.ComposeAsync. The problem is that I still have to support devices running iOS 9, and I tried both Email.ComposeAsync as well as Launcher.OpenAsync but neither of them support iOS 9. Thus causing a bit of inconvenience here.

Steps to Reproduce

  1. Download/Clone the project from Reproduction Link
  2. Run the application on an iOS 9 device.
  3. Tap on each sample email provided on the initial screen.

Expected Behavior

Can open the email app

Actual Behavior

Can not open the email app

Basic Information

  • IDE: Visual Studio for Mac 2019
  • Platform Target Frameworks:

    • iOS: 14.4.1.3

  • Affected Devices: iOS devices running iOS 9

Reproduction Link

(https://github.com/hungxtran/XamarinEssentials-EmailAndLauncherNotSupportiOS9)[https://github.com/hungxtran/XamarinEssentials-EmailAndLauncherNotSupportiOS9]

Workaround

The only workaround I found is switch back to Device.OpenUri and add suppress warning. But this is not pretty. Someone might be thinking "Oh, it's 2020 and nobody is using iOS 9 anymore". But the fact is there still users who hasn't update their iDevices and there are specific cases that I need to deploy to them.

bug

Most helpful comment

I think @mattleibow on TryOpenAsync it will work fine, but on OpenAsync it wont -> https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/Launcher/Launcher.ios.tvos.cs#L14-L28 see how we detect iOS 10 and above. We should clean this code up.

All 5 comments

@hungxtran is it crashing? I believe we should be supporting older iOS...

What error are you experiencing? I can't really test right now as I only have new OS versions since I just updated to test iOS 14. And Xcode no longer ships iOS 9, and email doesn't work on simulators either...

@mattleibow No, it's not crashing. It just doesn't show any signs of response when I tap on emails, and as I described above, it does not open email.
And yes, it's quite an inconvenience because email doesn't work on simulators as well as new versions of Xcode doesn't ships iOS 9. But according to Apple Documentation here, the latest stable version of Xcode, which is 12.2 release, still supports on-device debugging for iOS 9 and later. So to test this particular bug, we would need a real iOS device running iOS 9.

There is something weird going on here. When using the Email API, we are just doing a simple call with MFMailComposeViewController, which has been there since iOS 3.0. Is there a native crash log in the Xcode | Window | Devices and simulators window?

What happens if you try Browser.OpenAsync? Make sure to use BrowserLaunchMode.External. That should follow the same path that Device.OpenUri does. It will mangle the URI a bit, but at least it should open the email app.

I think @mattleibow on TryOpenAsync it will work fine, but on OpenAsync it wont -> https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/Launcher/Launcher.ios.tvos.cs#L14-L28 see how we detect iOS 10 and above. We should clean this code up.

Was this page helpful?
0 / 5 - 0 ratings