Example #1
0
        public override Task ShareFileAsync(string path, string subject, string mimeType)
        {
            return SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(async () =>
            {
                if (!MFMailComposeViewController.CanSendMail)
                {
                    await FlashNotificationAsync("You do not have any mail accounts configured. Please configure one before attempting to send emails from Sensus.");
                    return;
                }

                NSData data = NSData.FromUrl(NSUrl.FromFilename(path));

                if (data == null)
                {
                    await FlashNotificationAsync("No file to share.");
                    return;
                }

                MFMailComposeViewController mailer = new MFMailComposeViewController();
                mailer.SetSubject(subject);
                mailer.AddAttachmentData(data, mimeType, Path.GetFileName(path));
                mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
            });
        }
Example #2
0
 public override void ShareFileAsync(string path, string subject)
 {
     Device.BeginInvokeOnMainThread(() =>
     {
         MFMailComposeViewController mailer = new MFMailComposeViewController();
         mailer.SetSubject(subject);
         mailer.AddAttachmentData(NSData.FromUrl(NSUrl.FromFilename(path)), "application/json", Path.GetFileName(path));
         mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
         UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
     });
 }
Example #3
0
 public override void SendEmailAsync(string toAddress, string subject, string message)
 {
     Device.BeginInvokeOnMainThread(() =>
     {
         MFMailComposeViewController mailer = new MFMailComposeViewController();
         mailer.SetToRecipients(new string[] { toAddress });
         mailer.SetSubject(subject);
         mailer.SetMessageBody(message, false);
         mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
         UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
     });
 }
Example #4
0
        private static async Task ComposeEmailWithMFAsync(EmailMessage message)
        {
            if (UIApplication.SharedApplication.KeyWindow?.RootViewController == null)
            {
                throw new InvalidOperationException("Root view controller is null, API called too early in the application lifecycle.");
            }

#if __MACCATALYST__ // catalyst https://github.com/xamarin/xamarin-macios/issues/13935
            throw new InvalidOperationException("Not supported on catalyst (https://github.com/xamarin/xamarin-macios/issues/13935)");
#else
            var controller = new MFMailComposeViewController();

            if (!string.IsNullOrEmpty(message?.Body))
            {
                controller.SetMessageBody(message.Body, true);
            }

            if (!string.IsNullOrEmpty(message?.Subject))
            {
                controller.SetSubject(message.Subject);
            }

            if (message?.To?.Count > 0)
            {
                controller.SetToRecipients(
                    message.To.Select(r => r.Address).ToArray());
            }

            if (message?.CC?.Count > 0)
            {
                controller.SetCcRecipients(
                    message.CC.Select(cc => cc.Address).ToArray());
            }

            if (message?.Bcc?.Count > 0)
            {
                controller.SetBccRecipients(
                    message.Bcc.Select(bcc => bcc.Address).ToArray());
            }

            await UIApplication.SharedApplication.KeyWindow?.RootViewController.PresentViewControllerAsync(controller, true);

            await controller.DismissViewControllerAsync(true);
#endif
        }
Example #5
0
 public override void SendEmailAsync(string toAddress, string subject, string message)
 {
     SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() =>
     {
         if (MFMailComposeViewController.CanSendMail)
         {
             MFMailComposeViewController mailer = new MFMailComposeViewController();
             mailer.SetToRecipients(new string[] { toAddress });
             mailer.SetSubject(subject);
             mailer.SetMessageBody(message, false);
             mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
             UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
         }
         else
         {
             FlashNotificationAsync("You do not have any mail accounts configured. Please configure one before attempting to send emails from Sensus.");
         }
     });
 }
Example #6
0
        private static async Task ComposeEmailWithMFAsync(EmailMessage message)
        {
            if (UIApplication.SharedApplication.KeyWindow?.RootViewController == null)
            {
                throw new InvalidOperationException("Root view controller is null, API called too early in the application lifecycle.");
            }

            var controller = new MFMailComposeViewController();

            if (!string.IsNullOrEmpty(message?.Body))
            {
                controller.SetMessageBody(message.Body, true);
            }

            if (!string.IsNullOrEmpty(message?.Subject))
            {
                controller.SetSubject(message.Subject);
            }

            if (message?.To?.Count > 0)
            {
                controller.SetToRecipients(
                    message.To.Select(r => r.Address).ToArray());
            }

            if (message?.CC?.Count > 0)
            {
                controller.SetCcRecipients(
                    message.CC.Select(cc => cc.Address).ToArray());
            }

            if (message?.Bcc?.Count > 0)
            {
                controller.SetBccRecipients(
                    message.Bcc.Select(bcc => bcc.Address).ToArray());
            }

            await UIApplication.SharedApplication.KeyWindow?.RootViewController.PresentViewControllerAsync(controller, true);

            await controller.DismissViewControllerAsync(true);
        }
 public override void ShareFileAsync(string path, string subject, string mimeType)
 {
     Device.BeginInvokeOnMainThread(() =>
         {
             if (MFMailComposeViewController.CanSendMail)
             {
                 MFMailComposeViewController mailer = new MFMailComposeViewController();
                 mailer.SetSubject(subject);
                 mailer.AddAttachmentData(NSData.FromUrl(NSUrl.FromFilename(path)), mimeType, Path.GetFileName(path));
                 mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
                 UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
             }
             else
                 SensusServiceHelper.Get().FlashNotificationAsync("You do not have any mail accounts configured. Please configure one before attempting to send emails from Sensus.");
         });
 }
 public override void SendEmailAsync(string toAddress, string subject, string message)
 {
     Device.BeginInvokeOnMainThread(() =>
         {
             if (MFMailComposeViewController.CanSendMail)
             {
                 MFMailComposeViewController mailer = new MFMailComposeViewController();
                 mailer.SetToRecipients(new string[] { toAddress });
                 mailer.SetSubject(subject);
                 mailer.SetMessageBody(message, false);
                 mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
                 UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
             }
             else
                 SensusServiceHelper.Get().FlashNotificationAsync("You do not have any mail accounts configured. Please configure one before attempting to send emails from Sensus.");
         });
 }
 public override void ShareFileAsync(string path, string subject)
 {
     Device.BeginInvokeOnMainThread(() =>
         {
             MFMailComposeViewController mailer = new MFMailComposeViewController();
             mailer.SetSubject(subject);
             mailer.AddAttachmentData(NSData.FromUrl(NSUrl.FromFilename(path)), "application/json", Path.GetFileName(path));
             mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
             UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
         });
 }
 public override void SendEmailAsync(string toAddress, string subject, string message)
 {
     Device.BeginInvokeOnMainThread(() =>
         {
             MFMailComposeViewController mailer = new MFMailComposeViewController();
             mailer.SetToRecipients(new string[] { toAddress });
             mailer.SetSubject(subject);
             mailer.SetMessageBody(message, false);
             mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
             UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
         });
 }