So I know that i would have to use the MFMailComposeResultSent. (At least I think that's what i'm supposed to use) This is the code that i have and it sends the email and everything fine but the mail composer stays up.
EDIT: Here is my code
if ([condition isEqual: #"Excellent"] && [MFMailComposeViewController canSendMail]) {
NSString *emailBody = [NSString stringWithFormat:#"Product:%# Make:%# Year Manufactured:%# Description:%# Condition:Excellent Email:%#",inputProduct,inputMake,inputYear,inputDescript, inputEmail];
NSArray *recipient = [NSArray arrayWithObject:#"LoveShackElectronics#gmail.com"];
MFMailComposeViewController *SuperLovedEmail = [[MFMailComposeViewController alloc]init];
[SuperLovedEmail setTitle:emailTitle];
[SuperLovedEmail setToRecipients:recipient];
[SuperLovedEmail setMessageBody:emailBody isHTML:NO];
[SuperLovedEmail setUserActivity:false];
[self presentViewController:SuperLovedEmail animated:YES completion:nil];
}
else {
UIAlertController *emailAlert = [UIAlertController alertControllerWithTitle:#"Oh No!" message:#"Your Phone is not able to send an email currently or you have not chosen a condition. Please make sure you have chosen a condition and that you are signed in through Mail" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *emailAlertAction = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * emailAlertAction) {}];
[emailAlert addAction:emailAlertAction];
[self presentViewController:emailAlert animated:YES completion:nil];
}
You need to set the mailComposeDelegate property of your SuperLovedEmail object to be self, then handle the didFinishWithResult message, like this:
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[controller dismissViewControllerAnimated:true completion:nil];
}
You might find it useful to evaluate the MFMailComposeResult to see whether sending actually happened.
Related
I want to import file from file list.I have used UIDocumentMenuViewController to display and select file. It shows blank screen when open iCloud.
I have created UIDocumentMenuViewController which show all types of files.
UIDocumentMenuViewController *documentPickerMenu = [[UIDocumentMenuViewController alloc]
initWithDocumentTypes:#[#"public.item"]
inMode:UIDocumentPickerModeImport];
documentPickerMenu.delegate = self;
[self presentViewController:documentPickerMenu animated:YES completion:nil];
I have implemented delegate methods.
- (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker{
documentPicker.delegate = self;
[self presentViewController:documentPicker animated:YES completion:nil]; }
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
if (controller.documentPickerMode == UIDocumentPickerModeImport)
{
// Condition called when user download the file
NSData *fileData = [NSData dataWithContentsOfURL:url];
// NSData of the content that was downloaded - Use this to upload on the server or save locally in directory
//Showing alert for success
dispatch_async(dispatch_get_main_queue(), ^{
NSString *alertMessage = [NSString stringWithFormat:#"Successfully downloaded file %#", [url lastPathComponent]];
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:#"UIDocumentView"
message:alertMessage
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:#"Ok" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
});
} }
I have images on iCloud.I have tried same thing by creating UIDocumentPickerViewController instead of UIDocumentMenuViewController but same issu.I am not able to identify issue can anyone have any idea?
I am trying to pull up a Mail compose view controller after pushing a button from a UIAlertController. In simulator, I get the normal crash and error message I always get in Simulator when trying to open mail, but in app, I get nothing. No controller, no crash, nothing. Here is the code.
[actionSheet addAction:[UIAlertAction actionWithTitle:#"Email" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self emailThem];
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];
-(void) emailThem {
NSLog(#"EMAIL");
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:#"To P3 Media"];
[mail setMessageBody:#"Replace this text with your message for all the information you would like on P3 Media." isHTML:NO];
[mail setToRecipients:#[#"p3media2014#gmail.com"]];
[self presentViewController:mail animated:YES completion:NULL];
}
What is the problem?
Try This Code
[actionSheet addAction:[UIAlertAction actionWithTitle:#"Email" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self emailThem];
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];
-(void) emailThem {
NSLog(#"EMAIL");
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:#"To P3 Media"];
[mail setMessageBody:#"Replace this text with your message for all the information you would like on P3 Media." isHTML:NO];
[mail setToRecipients:#[#"p3media2014#gmail.com"]];
dispatch_async(dispatch_get_main_queue(),^{
[self presentViewController:mail animated:YES completion:NULL];
});
}
I am trying to send a message through Xcode programmatically but when I click the send button it opens the message sending box. But I want to send message directly without opening message box. Is this possible in iOS Xcode or not? Please help me.
but don't want open sending message box.
the code is
- (IBAction)sendSMS:(id)sender
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"Hello this is anup";
controller.recipients = [NSArray arrayWithObjects:#"7026144009", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result)
{
case MessageComposeResultCancelled:
NSLog(#"Cancelled");
break;
case MessageComposeResultFailed:
{
NSLog(#"faild");
UIAlertController *alrt=[UIAlertController alertControllerWithTitle:#"my apps" message:#"unknown error" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
//do something when click button
}];
[alrt addAction:okAction];
break;
}
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
ya it is possible on that your scenario no need of MFMessageComposeViewController, just one webservice is enough, send the two (#"Hello this is anup",#"7026144009") to your backend , the backend developer send the SMS to that particular number using SMTP Server option.
Choice -2
if you want to handle in your own use some thirdparty SDK like skpsmtpmessage, it work like same SMTP.
You can't programatically send a message without the user's content.
The most you can do is open the messages app and if the user decides to send it, he can send it.
You can't programatically send a message without the user's consent. The most you can do, is open the messages app and if the user decides to send it, he can send it.
(IBAction)sendingMessage:(id)sender {
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"SMS message here";
controller.recipients = [NSArray arrayWithObjects:#"+919015156562", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
And:
(void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
[self dismissViewControllerAnimated:YES completion:nil];
}
I have seen a nice feature in the iOS App Scanner Pro. This app allows to send scanned documents as email attachments via the original mail app from Apple but without leaving the Scanner Pro app. I ask me how did they do it? Is there a special API call?
implement MFMailComposeViewControllerDelegate like this:
#interface YourViewController<MFMailComposeViewControllerDelegate >
Then where you want to instantiate this email viewcontroller just do the following:
if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
[mailController setMailComposeDelegate:self];
[mailController setSubject:#"Mail Subject!"];
[mailController setMessageBody:#"Here is your message body" isHTML:NO];
[mailController setToRecipients:[NSArray arrayWithObject:#"yourrecipent#domain.com"]];
NSData *imageData = UIImageJPEGRepresentation(imageToUpload, 1.0f);
if(imageData.length)
{
[mailController addAttachmentData:imageData mimeType:#"image/jpeg" fileName:#"Your_Photo.jpg"];
[self presentModalViewController:mailController animated:YES];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Invalid Image" message:#"The image couldn't be converted." delegate:nil cancelButtonTitle:nil otherButtonTitles:#"Okay", nil];
[alert show];
}
}
Last implement mailComposerViewController delegate method
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
// or you can check for the status first and implement different task if you wish
}
You can use UIActivityViewController, for example:
UIImage *image = [UIImage imageNamed:#"image_file_name"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[image] applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
it gives user even more options, than just send email.
Yes, the so called UIActivityViewController. You use it like this:
NSArray *itemsToShare = #[[NSString stringWithFormat:#"This is a string that is sent via mail as well."], NSURLtoTheFileToSend];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact]; // Here you can say what you dont want to give the opportunity to share.
activityVC.completionHandler = ^(NSString *activityType, BOOL completed) {
if (completed) {
UIAlertView *alert = [[UIAlertView alloc] init];
alert.title = #"Export successfull";
[alert show];
[alert performSelector:#selector(dismissWithClickedButtonIndex:animated:) withObject:nil afterDelay:1];
}
};
[self presentViewController:activityVC animated:YES completion:^{}];
I get to the Mail program fine, and when I press "Send" I hear the swoosh sound and Mail closes and returns me to my app, but the actual mail isn't sending.
Here's the code I'm using to mail. Any ideas about what I'm doing wrong?
(I'm using iOS6, on an actual device, not the simulator.)
-(void)openMail {
//Open Mail program and create email with haiku attached as image.
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:[NSString stringWithFormat:#"subject"]];
UIImage *myImage = [self createImage];
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailer addAttachmentData:imageData mimeType:#"image/jpg" fileName:#"xxxxx"];
NSString *emailBody = #"I thought you might like this haiku from the xxxxx iPhone app.";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:NULL];
}
//Unless it's not possible to do so, in which case show an alert message.
else
{
self.alert = [[UIAlertView alloc] initWithTitle:#"I'm sorry." message:#"Your device doesn't seem to be able to email this haiku. Perhaps you'd like to tweet it or post it on Facebook instead?" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[self.alert show];
}
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:Nil];
}
It looks like it's actually a problem between my server and the iOS 6.1 update. I'll leave this up in case other people have the same problem. If the issue is fixed and my email STILL won't send, then I'll post another question.