Problem displaying MFMailComposeViewController modal view - iphone

I'm having problems displaying a modal view for sending emails (MFMailComposeViewController). I'm trying to display this modal view from a detailed view that was pushed on the stack by selecting a cell in an initial table view. My problem is that although the MFMailComposeViewController does display, I do not get the Send and Cancel buttons that I usually go with the MFMailComposeViewController view. I just get the 'Back' button of my detail view in my navigation bar.
My detail view is a subclass of UIViewController conforming to MFMailComposeViewControllerDelegate,UINavigationControllerDelegate protocols:
And my methods for sending emails is:
-(void)sendEmail {
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[mailComposer setToRecipients:[NSArray arrayWithObjects:#"test#gmail.com",nil]];
[mailComposer setSubject:#"Subjecy"];
[mailComposer setMessageBody:#"Body" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
}
[mailComposer release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
if (result == MFMailComposeResultFailed) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Message Failed" message:#"Your message failed to send" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
Many thanks for any help.

I had a similar problem when displaying the email window on an iPad with
[self presentModalViewController:mailComposer animated:YES];
The Send and Cancel buttons were partially cut off because the whole window was shifted up by approximately 20 or 30 pixels. Strangely, this was only happening in Portrait mode when the home button was at the bottom.
The solution was to set the main window size to iPad Full Screen in MainWindow.XIB
It was set to None by default.
Rich

Related

Email Signature App Iphone

I am making an email signature application that allows user to make signatures and use them to send with emails, Their is signature name(Text Field), content(Text View) and image(Image View) and i am saving them in Database so that if the user selects the signature name from the table view that is on the second view the preview will show up on the same view like if i select signature 1 from table view then in preview section the signature image should show up with the signature content in (Text View), and then on the same view we press send(Button) the text and image from the Text View of preview section will be copied to clipboard and then in third view i can paste it in the message section and send the email, is it possible to do that if yes how can i implement it or any other idea how to do this ?
i have this one method for send email with image and message .. just add MFMessageComposeViewControllerDelegate in .h file and add framework MessageUI.framework in your project
-(void)sendMailWithImage:(NSString *)message Image:(UIImage *)image{
if ([MFMailComposeViewController canSendMail])
{
UIImage *tempImageSave=image;
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
NSString *mailBody = message;
NSData *imageData = UIImagePNGRepresentation(tempImageSave);
[mailComposeViewController addAttachmentData:imageData mimeType:#"image/png" fileName:#"Testing"];
[mailComposeViewController setMessageBody:mailBody isHTML:NO];
mailComposeViewController.mailComposeDelegate = self;
[self presentViewController:mailComposeViewController animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"e-Mail Sending Alert"
message:#"You can't send a mail"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
and this bellow method is delegate method of MFMessageComposeViewControllerDelegate
#pragma mark - MFMessage Delegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
if (result == MFMailComposeResultSent)
{
NSLog(#"\n\n Email Sent");
}
[self dismissViewControllerAnimated:YES completion:nil];
}
i hope this help you...

MFMailComposeViewController ModalView crashes the iOS5 application

I have an iOS TabBar Application with tabbarcontroller and navigationcontroller.
In my detail view wich is pushed from my first tab tableviewcontroller i have sharing navigationItem.rightBarButtonItem with email sharing.
I have the following code for this:
- (void)share
{
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:#"Send" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Email",nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[popupQuery showInView:self.view];
[popupQuery release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
if ([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[picker setMailComposeDelegate:self];
[picker setSubject:#"New theme"];
NSString *emailBody = #"Hi there";
[picker setMessageBody:emailBody isHTML:NO];
[self resignFirstResponder];
picker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
picker.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:picker animated:NO];
[picker release];
}
else{
}
}
}
The app shows me the composing view but when i'm trying to do something with this view (e.g. to pick up the address or to spell something) - app crashes with SIGTRAP.
The app crashes only in iOS5, iOS5.1. In iOS4.2.1 everything works perfect.
What's the problem? Any ideas?
Per the docs, I'd suggest calling [MFMailComposeViewController canSendMail] class method before creating MFMailComposeViewController. I also generally don't have that [self resignFirstResponder] line. I gather you're crashing before your mailComposeController:didFinishWithResult:error method is invoked?
Thank you guys for your help and your time.
It was absolutely insane bug. Project has a cyrillic name. I just renamed it to latin name and now everything works fine. My fault :( Thanks Evgeniy Shurakov for the help.

how to let user choose the mail receiver?

in my app i used the code below to handle the messages send from iphone i want to know how to let him choose between contact us and tell a friend like other apps how can i make this issue ?
the code :
-(IBAction)sendEmail {
//Create a new mailComposer object and set the mailComposeDelegate (required).
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
//Set Fields such as Subject, recipients, and message body.
[mailComposer setToRecipients:[NSArray arrayWithObjects:#"info#Myweb.com",nil]];
[mailComposer setSubject:#"App Feadback"];
//Present the mail view controller
[self presentModalViewController:mailComposer animated:YES];
}
//release the mailComposer as it is now being managed as the UIViewControllers modalViewController.
[mailComposer release];
}
//MFMailComposeControllerDelegate method that handles success or failure
//and dismisses the mailComposer
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
if (result == MFMailComposeResultFailed) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Message Failed" message:#"Your message failed to send" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
For Contact Us, you have to prefill your mail address to mailComposer.setToRecipient. as you have done.
And for tell a friend, you have to collect your friend's email address prior the mail composer in view. e.g. using Address book person picker control.
Whatever you do, MFMail composer will not allow you to do anything without the knowledge of the user. The user can delete/add in the mailto field when it pops up.

Show UIAlertView on splash screen

I used to show a splash screen which in background load some data from web, I also check that if the location of the user is changed from one city to another city I want to show in alert to the user with the message that you are now in "CityName" would you like to see data from this city?
I have tabbed application and I have presented the splash screen as follow in the app delegate class.
SplashViewController *controller = [[SplashViewController alloc] initWithNibName:nil bundle:nil];
tabBarController.view.frame = [[UIScreen mainScreen] bounds];
controller.tabBarController = self.tabBarController;
[application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
[window addSubview:controller.view ];
//[window addSubview:tabBarController.view ];
[self.tabBarController presentModalViewController:controller animated:YES];
[window makeKeyAndVisible];
[controller release];
Now when I show the alert screen it crash the application with "EXC_BAD_ACCESS" message and the stack trace show that _buttonClick is released in UIAlertView class.
Please advise what should I do, I also tried with UIActionSheet but the same problem with this thing too.
I think there is some problem with the model thing with the current view (SplashView).
Thanks in advance.
Are you trying to display your UIAlertView inside of your SplashViewController viewDidAppear? If not, I would try that first. I would also make sure you have your UIAlertView clickedButtonAtIndex method setup properly to try and trap what is going on.
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Your Location Has Changed"
message:#"Your location has changed since you last opened opened THEAPP. Would you like to refresh your data?" delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
alert.tag = 1;
[alert show];
[alert autorelease];
Then for the clickedButtonAtIndex method:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
//--NSLog(#"You clicked button #%i",buttonIndex);
if (alertView.tag == 1){
if (buttonIndex == 0) {
//--NSLog(#"CANCEL");
} else if (buttonIndex == 1) {
//--NSLog(#"OK");
}
}
}
Doing all of this on a splash screen should be fine as long as you take into account the HIG's requirements for using the users location. Hope this helps!
I resolve this issue, the problem was that my Splash View was a modeled view and invoked by
[self.tabBarController presentModalViewController:controller animated:YES];
what I did that I shifted the data downloading to another view controller and there I can show alerts, and can handle that

Exception in iPhone app : Modal transition is already in progress

I have what I believe is a fairly simple application at the moment based on a few tutorials cobbled together. I'm using XCode 3.2.3 in OSX 10.6.4. It started as a standard iPhone "Window Based Application". Using interface builder I have added a Tab Bar Controller using the O'Reilly video tutorial here:
http://broadcast.oreilly.com/2009/06/tab-bars-and-navigation-bars-t.html
In the first Tab I have a standard UIView with two buttons. Both call the same function to display a UIImagePickerController:
-(IBAction) btnPhotoClicked:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
if((UIButton *)sender == btnChoosePhoto)
{
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
I am running the code inside an emulator so only ever click the button called Choose Photo. When the dialogue is released with a photo chosen this function runs:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *mediaUrl;
mediaUrl = (NSURL *)[info valueForKey:UIImagePickerControllerMediaURL];
if (mediaUrl == nil)
{
imagePuzzle = (UIImage *) [info valueForKey:UIImagePickerControllerEditedImage];
if(imagePuzzle == nil)
{
//--- Original Image was selected ---
imagePuzzle = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage];
}
else {
//--- Get the edited image ---
//--- If it was successful the above valueForKey:UIImagePickerControllerEditedImage
//--- would have assigned it already.
}
}
else {
//--- Muppet selected a video
}
// Animate the picker window going away
[picker dismissModalViewControllerAnimated:YES];
ImageViewController *imageViewController = [[ImageViewController alloc] init];
imageViewController.delegate = self;
[self presentModalViewController:imageViewController animated:YES];
[imageViewController release];
}
This is where my problem lies. I've tried many different hacks and iterations but the above code is the simplest to present the problem. When the imageViewController is displayed as a modal dialogue the following exception is thrown:
2010-07-09 15:29:29.667 Golovomka[15183:207] *** Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal
transition from <NewViewController: 0x5915f80> to <ImageViewController: 0x594a350>
while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear
to know the current transition has completed'
How do I cure this? I have tried delays and other tricks but do not really understand how I'm supposed to use viewDidAppear or viewDidDisappear to help me. Also of note is that a very basic application with one view loading the picker then displaying another view with the image in does not produce the error. Any help gratefully received.
To address the specific issue described here, you could add the viewDidAppear method in your class:
-(void)viewDidAppear:(BOOL)animated
{
if (/*just visited ImagePicker*/)
{
ImageViewController *imageViewController = [[ImageViewController alloc] init];
imageViewController.delegate = self;
[self presentModalViewController:imageViewController animated:YES];
[imageViewController release];
}
}
Remove those lines from below your call:
[picker dismissModalViewControllerAnimated:YES];
So, whenever your class self appears (is displayed), it will call viewDidAppear... Since this most likely isn't really what you want all the time, you could add some variables to set/clear that defines whether or not to immediately present the imageViewController when self is displayed. Something like "If coming from image picker, show the imageViewController, otherwise do nothing".
That said, imho, pushing modal views is should generally be done in response to a user action and I would maybe rethink the user experience here - e.g. add a subview instead of pushing a modal view which you could do where your currently have the code - but if you're just playing around with some tutorials that should solve the NSInternalInconsistencyException. :) Cheers!
In iOS 5.0 and above you can use
[self dismissViewControllerAnimated:YES completion:^{
//present another modal view controller here
}];
I ran into this issue quite a few times. I recently started using this simple fix:
When I am going to present a new modal view controller immediately after dismissing another modal view controller, I simply dismiss the first one with argument NO in dismissModalViewControllerAnimated:.
Since the second view is presented with an animation, you hardly notice that the first one goes away fast. And you never get the transitions conflict.
I was having the same problem when i wanted to present an MFMailComposeViewController immediately after dismissing the UIImagePickerController. Heres what i did:
I removed the [imagePicker release]; statement from where i was presenting the image picker and put it in didFinishPickingMedia callback.
I used [self performSelector:#selector(presentMailComposer:) withObject:image afterDelay:1.0f];
Here's my code:
Displaying Image Picker
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
NSArray *media = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
if ([media containsObject:(NSString*)kUTTypeImage] == YES) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[picker setMediaTypes:[NSArray arrayWithObject:(NSString *)kUTTypeImage]];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
//[picker release];
}
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Unavailable!"
message:#"Could not open the Photo Library."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
Image Picker Delegate Callback - didFinishPickingMedia
NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
UIImage *photoTaken = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
//Save Photo to library only if it wasnt already saved i.e. its just been taken
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(photoTaken, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
}
//Pull up MFMailComposeView Controller
[self performSelector:#selector(composeMailWithPhoto:) withObject:photoTaken afterDelay:1.0f];
}
[picker dismissModalViewControllerAnimated:YES];
[picker release];
Display Mail Composer View
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
// Fill out the email fields and Attach photograph to mail
static NSString *imageType = #"image/jpeg";
NSString *imageName = [NSString stringWithString:#"MyCoffeeCup.jpg"];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
[mailPicker addAttachmentData:imageData mimeType:imageType fileName:imageName];
[mailPicker setToRecipients:[NSArray arrayWithObject:#"hello#xische.com"]];
[self presentModalViewController:mailPicker animated:YES];
//[self.navigationController pushViewController:mailPicker animated:YES];
[mailPicker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Unavailable!"
message:#"This device cannot send emails."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}