send picture + text in iMessage in ios programatically? - ios

is there any possibility to send picture + text in iMessage in ios programatically?
if it is possible can anyone help me?

Yes you can do it , its same like doing for mail just do this
#import <MessageUI/MFMessageComposeViewController.h>
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.recipients = [NSArray arrayWithObject:#"123456789"]; // your recipient number or self for testing
picker.body = #"test from OS4";
NSData*imageData=[NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:#"image" ofType:#"png"]];
[picker addAttachmentData:imageData typeIdentifier:(NSString *)kUTTypePNG filename:#"image.png"];
[self presentModalViewController:picker animated:YES];

Related

want to share app only by email in iOS using UIActivityViewController

So basically I want to share the content only through mail and I do not want to show the option of message. Could you help me out with that. Also I want to set the subject of the email through the code and also the recipient of the email through the code
You can put this in the method for a button tap or something like that.
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = controller;
[mailViewController setSubject:subject];
NSMutableArray *emails = [[NSMutableArray alloc] init];
[emails addObject:address];
[mailViewController setToRecipients:emails];
mailViewController.navigationBar.translucent = NO;
mailViewController.navigationBar.tintColor = [UIColor whiteColor];
mailViewController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName : [UIColor whiteColor]};
[controller presentViewController:mailViewController animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}];
}

Send email with material from tableview or NSmutableDictionary

In my app, I have a tableView whose material is from my NSmutableDictionary. When I push a button, I want to send these material to a email.Here is the code for sending email:
//Below to send email
- (IBAction)showEmail:(id)sender {
// Email Subject
NSString *emailTitle = #"Course Planner of iBcChem";
// Email Content
NSString *messageBody = #"Please check my course plan";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:#"xxxxx#gmail.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];//want to fix here
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
}
Here is my question:
How can I add my material to the messageBody please? Can I use the method similar to show my dictionary like below in my messageBody please?
NSLog(#"Dictionary: %#", [_sectionContents description]);//test dictionary here
Where _sectionContents is my dictionary.
You can attach you dictionary by the same code which you have written.
Here is the code for you.
NSString *emailTitle = #"Course Planner of iBcChem";
NSString *messageBody = #"Please check my course plan";
NSDictionary *dci = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:#"1",#"2", nil] forKeys:[NSArray arrayWithObjects:#"A",#"B", nil]];
NSArray *toRecipents = [NSArray arrayWithObject:#"xxxxx#gmail.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:dci.description isHTML:NO];
[mc setToRecipients:toRecipents];
[self presentViewController:mc animated:YES completion:NULL];
In simulator mail delegate will take some time to load the Body part of mailcomposersheet. The body will look like.
{
A = 1;
B = 2;
}
Enjoy Coding !!

Missing message body and image attachment in MFMailComposeViewController

In my app, I have a button that when pressed, will present an MFMailComposeViewController that is pre-populated with a subject, message body, and a jpg. However, I am noticing some strange behavior. Often the MFMailComposeViewController appears with the message body and image attached, but other times, it will appear without the message body and image attachment, though the subject is always properly presented. I am running my app on iOS 8. My code is below. Any suggestions/advice will be much appreciated.
- (void)emailButtonPressed:(id)sender {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"My Subject"];
[picker setMessageBody:[NSString stringWithFormat:#"My Message Body"] isHTML:YES];
NSData *imageData = UIImageJPEGRepresentation(self.image, 1.0);
NSString *fileName = #"myFileName";
fileName = [fileName stringByAppendingPathExtension:#"jpeg"];
[picker addAttachmentData:imageData mimeType:#"image/jpeg" fileName:fileName];
[self presentViewController:picker animated:YES completion:nil];
}

MFMailComposeViewController not populating recipients in ios 5

I'm trying to send mail to list of email array that I receive from database, when I send the recipient list gets populated in iOS 7 but when I tried in iOS 5 the recipient list doesn't get populated. Any Idea why? This is my mail function
-(void)sendEmailToContacts:(NSArray *)fList withText:(NSString *)emailText withTag:(NSInteger )tag
{
if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.view.tag=tag;
NSString *htmlBody =[NSString stringWithFormat:#"%#",_currentAdd.contentUrl,addtext];
[mailComposer setMessageBody:htmlBody isHTML:YES];
[mailComposer setSubject:_currentMail.subject];
mailComposer.mailComposeDelegate = self;
[mailComposer setToRecipients:fList];
[self presentViewController:mailComposer animated:YES completion:nil];
}
else
{
NSLog(#"Device is unable to send email in its current state.");
}
}
My fList (recipient list) is an NSArray, this is a sample output of my fList
(
"john#gmail.com",
"mary#gmail.com",
"akhil#gmail.com",
"tester#gmail.com"
)
Recipients are expected as immutable array. check your array type
NSArray *usersTo = [NSArray arrayWithObject: #"raja#apple.com"];
[mailComposer setToRecipients:usersTo];
Try this one.
NSArray *fList = [NSArray arrayWithObjects:#"raja#apple.com",#"john#gmail.com",#"mary#gmail.com",#"akhil#gmail.com",#"tester#gmail.com", nil];
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.view.tag=tag;
NSString *htmlBody =[NSString stringWithFormat:#"%#",_currentAdd.contentUrl,addtext];
[mailComposer setMessageBody:htmlBody isHTML:YES];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:_currentMail.subject];
mailComposer.delegate = self;
[mailComposer setToRecipients:fList];
[self presentViewController:mailComposer animated:YES completion:nil];
-(void)sendEmailToContacts:(NSArray *)fList withText:(NSString *)emailText withTag:(NSInteger )tag
{
if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
//mailComposer.view.tag=tag;
NSString *htmlBody =[NSString stringWithFormat:#"%#",_currentAdd.contentUrl,addtext];
[mailComposer setMessageBody:htmlBody isHTML:YES];
[mailComposer setSubject:_currentMail.subject];
mailComposer.mailComposeDelegate = self;
[mailComposer setToRecipients:fList];
[self presentViewController:mailComposer animated:YES completion:nil];
}
else
{
NSLog(#"Device is unable to send email in its current state.");
}
}
Apparently the issue was with setting tag if I try to set the tag before setToRecipients line it will not show the recipients list in iOS 5, it will work if the setting tag line is commented out or set after setToRecipients.

iOS: How can I open my own file format(like .own) in code

I write a file named "test.own" to Document path, and I get its URL.
Now I have a button and what I want is to open an options sheet dialog in which there is Email or others to send or open my file when I click the button.
Is there anyway to achieve this ?
Thanks in advance!
When the file is selected do this.
- (IBAction)showFileOptions:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select a option"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"email file",#"open file"];
[actionSheet showInView:self.view];
}
Write delegate to handle the actionSheet:
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex
{
if (buttonIndex == 0) {
//email
[self emailDocument];
}
else if (buttonIndex==1)
{
//open file
}
}
Emailing document:
-(void)emailDocument
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Your own subject"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#"first#example.com"];
NSArray *ccRecipients = [NSArray arrayWithObjects:#"second#example.com", #"third#example.com", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:#"fourth#example.com"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
// Attach your .own file to the email
//add conversion code here and set mime type properly
NSData *myData =[NSData dataWithContentsOfURL:[NSURL urlWithString:pathToOwnFile]];
[picker addAttachmentData:myData mimeType:#"SETMIMETYPEACCORDINGLY" fileName:#"example.own"];
// Fill out the email body text
NSString *emailBody = #"PFA";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
For e-mail, all you need to do is present the MFMailComposeViewController view and then you can add your ".own" custom document via that view controller's addAttachmentData:mimeType:fileName: method.
(I would link to Apple's documentation except Apple's documentation website appears to be down as I am typing this).
As for the other part of your question, other apps normally use the UIDocumentInteractionController to display a "Open in..." dialog, except the other apps need to know how to open your custom document (which they won't be able to do if your app isn't too big or famous or if somebody else -- who is not -- you authored it).

Resources