Skip to content

Commit 805e112

Browse files
committed
[Email] show the alart if run on Simulator
MFMailComposeViewController does not work on Simulator and it causes a crash
1 parent 8c3dec4 commit 805e112

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

ios/Email/app/app_delegate.rb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,29 @@ def viewDidLoad
2626
end
2727

2828
def presentEmailEditor
29-
# called when the button is pressed
30-
31-
# http://stackoverflow.com/a/1513433/94154
32-
#
33-
# MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
34-
# controller.mailComposeDelegate = self;
35-
# [controller setSubject:@"My Subject"];
36-
# [controller setMessageBody:@"Hello there." isHTML:NO];
37-
# if (controller) [self presentModalViewController:controller animated:YES];
38-
# [controller release];
39-
40-
controller = MFMailComposeViewController.alloc.init
41-
controller.mailComposeDelegate = self
42-
controller.setSubject("My Subject")
43-
controller.setMessageBody("Hello there", isHTML:false)
29+
unless MFMailComposeViewController.canSendMail
30+
controller = UIAlertController.alertControllerWithTitle("Alert", message:"Cannot send Email on Simulator", preferredStyle:UIAlertControllerStyleAlert)
31+
controller.addAction(UIAlertAction.actionWithTitle:"OK",style:UIAlertActionStyleDefault, handler:lambda { |action|
32+
})
33+
else
34+
35+
# called when the button is pressed
36+
37+
# http://stackoverflow.com/a/1513433/94154
38+
#
39+
# MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
40+
# controller.mailComposeDelegate = self;
41+
# [controller setSubject:@"My Subject"];
42+
# [controller setMessageBody:@"Hello there." isHTML:NO];
43+
# if (controller) [self presentModalViewController:controller animated:YES];
44+
# [controller release];
45+
46+
controller = MFMailComposeViewController.alloc.init
47+
controller.mailComposeDelegate = self
48+
controller.setSubject("My Subject")
49+
controller.setMessageBody("Hello there", isHTML:false)
50+
end
51+
4452
self.presentModalViewController(controller, animated:true)
4553
end
4654

0 commit comments

Comments
 (0)