Overview
Lab 12 implements email with file attachments using a custom wwEmailWithAttachment.pas unit that bridges to iOS MessageUI framework Objective-C APIs and Android Intent-based email. Both approaches have changed on modern OS versions and the iOS implementation requires manual SDK framework configuration. A modern replacement using the platform share sheet (UIActivityViewController on iOS, ACTION_SEND Intent with FileProvider on Android) is simpler, more reliable, and doesn't require native framework bridging.
Background
iOS Issues with Current Approach
MFMailComposeViewController (MessageUI) requires the device to have a Mail account configured. If no account is set up, the composer silently fails.
- The
MessageUI.framework must be manually added to the Delphi SDK Manager — a step that trips up training attendees and isn't necessary in modern development.
- iOS 16+ introduced changes to
MFMailComposeViewController presentation that can cause display issues if the view controller hierarchy is not handled correctly.
Android Issues with Current Approach
- The Intent-based approach uses a bare
file:// URI for the attachment, which throws FileUriExposedException on Android 7+ (API 24+). A content:// URI via FileProvider is required.
ACTION_SEND with EXTRA_EMAIL and EXTRA_STREAM still works but the file URI handling must be updated.
Modern Replacement
Delphi 13 (and earlier versions from XE8+) includes FMX.Share which wraps UIActivityViewController on iOS and the Android share Intent — both use the system share sheet, which lets the user choose mail, messages, AirDrop, or any other app. This:
- Requires no iOS framework SDK additions
- Automatically handles file URIs correctly on Android
- Works even if no email client is configured (offers other sharing options)
Files Affected
lab-src/Lab12.../units/wwEmailWithAttachment.pas (replace entirely)
lab-src/Lab12.../forms/formMain.pas (call site update)
lab-src/Lab12.../FieldLogger.dproj (remove MessageUI SDK framework entry)
Steps to Address
- Replace
wwEmailWithAttachment.pas with a thin wrapper around FMX.Share.TShareSheet (or inline the share logic in formMain.pas):
uses FMX.Share;
procedure TFormMain.ShareReport(const FilePath: string);
begin
TShareSheet.Share(Self, 'Share Report', [FilePath]);
end;
- Remove the
MessageUI.framework entry from the Delphi SDK Manager settings documented in the lab instructions.
- Update the Lab 12 instructions to describe the share sheet approach and why it is preferred.
- Remove the Outlook COM/OLE code path for Windows (or keep it conditionally — it is still valid on desktop, but can be simplified).
- Verify that the HTML report file path passed to the share sheet resolves to a real temp/documents path on both platforms.
- Test that the share sheet receives the correct file MIME type (
text/html for the report).
Test Plan
Overview
Lab 12 implements email with file attachments using a custom
wwEmailWithAttachment.pasunit that bridges to iOSMessageUIframework Objective-C APIs and AndroidIntent-based email. Both approaches have changed on modern OS versions and the iOS implementation requires manual SDK framework configuration. A modern replacement using the platform share sheet (UIActivityViewControlleron iOS,ACTION_SENDIntent withFileProvideron Android) is simpler, more reliable, and doesn't require native framework bridging.Background
iOS Issues with Current Approach
MFMailComposeViewController(MessageUI) requires the device to have a Mail account configured. If no account is set up, the composer silently fails.MessageUI.frameworkmust be manually added to the Delphi SDK Manager — a step that trips up training attendees and isn't necessary in modern development.MFMailComposeViewControllerpresentation that can cause display issues if the view controller hierarchy is not handled correctly.Android Issues with Current Approach
file://URI for the attachment, which throwsFileUriExposedExceptionon Android 7+ (API 24+). Acontent://URI viaFileProvideris required.ACTION_SENDwithEXTRA_EMAILandEXTRA_STREAMstill works but the file URI handling must be updated.Modern Replacement
Delphi 13 (and earlier versions from XE8+) includes
FMX.Sharewhich wrapsUIActivityViewControlleron iOS and the Android share Intent — both use the system share sheet, which lets the user choose mail, messages, AirDrop, or any other app. This:Files Affected
Steps to Address
wwEmailWithAttachment.paswith a thin wrapper aroundFMX.Share.TShareSheet(or inline the share logic informMain.pas):MessageUI.frameworkentry from the Delphi SDK Manager settings documented in the lab instructions.text/htmlfor the report).Test Plan
FileUriExposedExceptionis thrown.wwEmailWithAttachment.pasunit.