iOS 7.1 MFMailComposeViewController Error - ios

I was coding a new iPhone App with iOS 7 and iOS 7.1 Beta 5.
Not iOS 7.1 released for everybody and my MFMailComposeViewController isn't working anymore.
This is my code:
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
[mail setSubject:#"Test"];
[mail setToRecipients:#[#"alexander#sn0wfreeze.de"]];
[mail setMessageBody:#"Test" isHTML:NO];
[mail setMailComposeDelegate:self];
[self presentViewController:mail animated:YES completion:nil];
Well I think that has to be a serious bug in iOS 7.1
What do you say?
I tried it again in a sample App, which could only present the mail view controller.
The Problem is that it doesn't allows the user to interact and it doesn't set the recipient and the message body. As you can see in my screenshot below:
EDIT:
In the simulator it works perfectly!
So please test it on a device
Greetings,
Alexander Heinrich

MFMailComposeViewController * mailim = [[MFMailComposeViewController alloc]init];
[mailim setMailComposeDelegate:self];
NSString * mailara =#"xxx#yandex.ru";
NSArray *emailArray = [[NSArray alloc]initWithObjects:mailara, nil];
[mailim setToRecipients:emailArray];
[mailim setSubject:#"Bilgi Almak Istiyorum"];
[self presentViewController:mailim animated:YES completion:nil];
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}

I fixed the problem by restarting the iPhone.
Never came across with such problems before...
I hope this won't occur more often

Related

dismissViewControllerAnimated not being called on iPhone

I have the following code where I am trying to show a PDF preview. It words perfectly on an iPad however when I am trying to do it on a iPhone it dosnt work.
QLPreviewController* preview = [[QLPreviewController alloc] init];
preview.dataSource = self;
[self dismissViewControllerAnimated:YES completion:^{
[self presentViewController:preview animated:YES completion:nil];
}];
The thread on the iPhone never makes it to this line
[self presentViewController:preview animated:YES completion:nil];
but works fine on ipad.. I am not sure what to even look at. Any help would be appreaciated.
To access the instances/variables (that are declared outside of the block) inside a block, you need to declare those instances/variables like this:
__block type identifier = initial value (optional) e.g, in your case use
__block QLPreviewController* preview = [[QLPreviewController alloc] init];
Try to use
[self.presentingViewController presentViewController:preview animated:YES completion:nil];
instead of
[self presentViewController:preview animated:YES completion:nil];

MFMessageComposeViewController addAttachmentData on iPad iOS7 black screen

I have a MFMessageComposeController, and I want to send images via iMessage (SMS not available on my iPad).
This is my code:
- (void)presentMessageController {
if(![MFMessageComposeViewController canSendAttachments])
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Your device doesn't support sharing photos via SMS!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[warningAlert show];
return;
}
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController addAttachmentData:imgData typeIdentifier:(NSString *)kUTTypePNG filename:#"image.png"];
// Present message view controller on screen
[self presentViewController:messageController animated:YES completion:nil];
}
The problem seems to be in [messageController addAttachmentData...]. The messageController is not presented, instead a blank screen appears, and app is hanging up, and after 1-2seconds, the delegate responds with MessageComposeResultCancelled, and I see this in console:
timed out waiting for fence barrier from com.apple.mobilesms.compose
Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!
If I comment that line, the messageController is presented (iMessage is opened).
IMPORTANT:
This is happening when testing on iPad (I tested on iPad 2 only, with iOS 7.0.3 installed). Same code works perfect in iPhone 5, 4, 4S with iOS 7.0.3.
When black screen appears, there is no way to return to app. You have to terminate the app, and restart.
Anybody experiencing same issue? Please help. Thanks.
try changing:
[messageController addAttachmentData:imgData typeIdentifier:(NSString *)kUTTypePNG filename:#"image.png"];
to:
[messageController addAttachmentData:imgData typeIdentifier:#"public.data" fileName:#"image.png"];
Call presentMessageController method after some delay
[self performSelector:#selector(presentMessageController) withObject:nil afterDelay:0.5];

MFmailComposer error

I want to apologize in advance because I am fairly new to programming, so if I am not as specific as I can be I am sorry but I will try to explain my problem as best as I can anyways, I am creating an app that needs to have the ability to send emails and I have looked everywhere, tried every sample code I could find and nothing seems to work every time I use code I get the following error:
2013-02-03 20:23:39.372 Tones[16409:c07] Warning: Attempt to present
on
whose view is not in the window hierarchy!
This is the code I am currently using in the viewcontroller.h file:
UIViewController <MFMailComposeViewControllerDelegate>
- (IBAction)Mail:(id)sender;
and this is in my viewcontroller.m file:
- (IBAction)Mail:(id)sender {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:#"Subject"];
NSArray *recipient = [NSArray arrayWithObjects:#"mail#example.com", nil];
[mail setToRecipients:recipient];
NSString *body = #"body!";
[mail setMessageBody:body isHTML:NO];
[self presentModalViewController:mail animated:YES];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
I also get a message that says both self presentModalViewController and self dismissModalViewController is deprecated in IOS 6 so does that mean I cant use it or am I doing something wrong?
So any help on what I am doing wrong with the mail composer would be much appreciated and again im sorry if I was not specific enough thanks in advance
You can use presentModalViewController:animated: to show the modal viewcontroller, but it is now recommended to use the new one: presentViewController:animated:completion:. The new on owns a completion handler and you can get more control of the code. Be careful the new method required a iOS 5.0 above. If your target is iOS5.0 above, you should use the new method. And the same for dismissModalViewControllerAnimated:, use dismissViewControllerAnimated:completion: instead.
The warning "Warning: Attempt to present on whose view is not in the window hierarchy!" suggests the view is not connected in the Interface Builder or programmatically.
The Deprecated warnings result from Xcode checking the APIs you use in your project settings. If you set the Build Settings' IOS Deployment Target of your Xcode project to iOS 6, then any APIs (such as presentModalViewController and dismissModalViewController) that are marked by Apple as deprecated will be flagged.
Instead use presentViewController:animated:completion: and dismissViewControllerAnimated:completion:, respectively.
[self presentModalViewController:mail animated:YES];
can be replaced by
[self presentViewController:mail animated:YES completion:nil];
and
[self dismissModalViewControllerAnimated:YES];
by
[self dismissViewControllerAnimated:YES completion:nil];
Like Sudha said, use [self presentViewController:mail animated:YES/NO completion:nil];
From iOS6 onwards, presentModalViewController and dismissModalViewController are deprecated, they are used with completion, which would be nil for your case .
Hi you can check MFMailComposerViewController class present or not.
-(void)email{Class emailClass=(NSClassFromString(#"MFMailComposeViewController"));if emailClass!=nil)if ([emailClass canSendMail]{[self displayComposePage];
}

iPad Mini crashing on modal segue

I am developing an app that runs on all the deployment target simulators (5.0-6.1) and on my iPhone 3GS, 4, 4S and a gen 2 iPad. I had the opportunity today to try running it on an iPad Mini. I works everywhere except when I try to segue to a MFMailComposeViewController object to send an email, which causes it to crash with an exception.
I use the code directly from the MailComposer sample project, but it always crashes when it calls presentModalViewController:animated:. So I tried presentViewController:animated:completion: as the other method is deprecated, but it still doesn't work.
I linked to MessageUI.framework imported the classes:
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
The delegate is set. Here is the code:
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Contact Email"];
// Set up recipient
NSArray *toRecipients = [NSArray arrayWithObject:#"info#foo.bar"];
[picker setToRecipients:toRecipients];
// [self presentModalViewController:picker animated:YES];
[self presentViewController:picker animated:YES completion:NULL];
}
Might there be a bug causing this in the iPad Mini? I don't have any other new devices I can try it on so I'm not sure if its a Mini problem or something bigger. Any help would be appreciated as I'm ready to submit to Apple but I sure don't want to do that with a crashing bug.
It's likely that a mail account has not been set up or for some other reason cannot send email.
Be sure to call the + (BOOL)canSendMail function of MFMailComposeViewController first.
Try wrapping your MFMailComposeViewController code with
if ( [MFMailCompseViewController canSendMail])
I'd guess the device doesn't have mail setup on it.

Release MFMAilComposeViewController after presentModalViewController: crashes

I have the following block of code which works fine in the simulator and on most devices, on some devices however (all on the same iOS version 4.2.1) the app is crashing when it gets to the [mailComposer release] call, does anyone have any insight on why this would be happening?
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:[self.webView stringByEvaluatingJavaScriptFromString:#"document.title"]];
[mailComposer setMessageBody:[NSString stringWithFormat:#"Hello, \n\n Here is the link we discussed. \n %#", [self.webView.request URL]] isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];
I had this exact same problem and I really have NO idea why it would crash, because presentModalViewController is supposed to retain the view controller. After fighting with it, I finally just added a property on my view controller which retained the reference to the mfMailComposeViewController and it worked fine. :/
MFMailComposeViewController* mfMailComposeViewController;
#property (nonatomic, retain) MFMailComposeViewController *mfMailComposeViewController;
then..
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:subject];
[controller setBody:body];
self.mfMailComposeViewController = controller;
[controller release];
Ok so I managed to figure out what was causing my issue with the help of my new iPad 2.
The issue was caused by not having any mail accounts configured, simply adding
if ([MFMailComposeViewController canSendMail])
before I create and present the view prevents the crashing, in my else block I added an UIAlertView to let the user know they cannot access that feature without first configuring a mail account.

Resources