MFMessageComposeViewController - Remove 'Buddy Name' - ios

I'm using the MFMessageComposeViewController to allow my users to send out app download invites to their friends. I want to load the View Controller with the recipients field blank, so the user can add whoever they wish. When I use the code below, a recipient 'Buddy Name' displays. How can I remove this?
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
if ([MFMessageComposeViewController canSendText])
{
messageController.body = #"My app text...";
messageController.recipients = [NSArray arrayWithObjects:#"", nil];
messageController.messageComposeDelegate = self;
[self presentViewController:messageController animated:YES completion:nil];
}

This can remove the Buddy Name:
messageController.recipients = nil

Just remove the following line
messageController.recipients = [NSArray arrayWithObjects:#"", nil];

Related

MFMessageComposeViewController - empty recipients and body

MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]){
controller.messageComposeDelegate = self;
controller.body = #"Hi! Check out this app i'm using to swap goods!";
controller.recipients = #[#"0932223223"];
[self presentViewController:controller animated:YES completion:nil];
}
Message composer open but recipients and message body are empty (image below).
Image

How to make recipients in MFMessageComposeViewController using a variable

I'm trying to use the MFMessageComposer to pre-fill sms for the user. I am trying use a variable that is stored in a mutable array and use that number to pre-fill the phone number. However it doesn't work with the code below at the recipient part. I've tried changing it to a string, adding it to the array. The phone just doesn't do anything.
However if I do a manual number using #[#"123132131235"]; for the recipients it would work.
- (IBAction)smsSend:(id)sender {
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
[controller setMessageComposeDelegate:self];
if([MFMessageComposeViewController canSendText])
{
controller.recipients = [[NSArray alloc] initWithObjects:[Detail valueForKey:#"Phone"], nil];
NSLog(#"%#",[Detail valueForKey:#"Phone"]);
controller.body = #"Hello testing";
[self presentViewController:controller animated:YES completion:NULL];
} else {
NSLog(#"cannot send");
}
}
}
Please help me.
Cheers,
Tony.
Try this:
- (IBAction)smsSend:(id)sender
{
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
[controller setMessageComposeDelegate:self];
if([MFMessageComposeViewController canSendText])
{
controller.recipients = [NSArray arrayWithObjects:[Detail valueForKey:#"Phone"], nil];
controller.body = #"Hello testing";
[self presentViewController:controller animated:YES completion:NULL];
}
else
{
NSLog(#"cannot send");
}
}
}
The only change I have made is recipient array allocation. Recipient array is not the array that you own so instead of [NSArray alloc] you should directly initialise array with objects.
initWithObject returns an array with a retain count of 1, i.e. you own the array and you must release it at some point to prevent memory leaks.
arrayWithObject returns an autoreleased array so you do not have to worry about releasing it when you don't need it anymore (but if you store it in an instance variable, you should retain it to prevent the autorelease pool from freeing it)

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 !!

MFMessageComposeViewController wrong focuse on the field

I was implementing possibility to invite friends via SMS and small problem occur. Problem is connected with wrong focus on the field.
Image below describe problem :
And as it is possible to see focus is before word "кому:" but not after.
So could some one help me please to understand how it is possible to set proper focus in the MFMessageComposeViewController.
Code that show SMS view is below:
if ([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
[messageController setBody:#"I'm on Memry, come join me! =) \n https://itunes.apple.com/us/app/memry/id735465896?mt=8"];
messageController.navigationBar.titleTextAttributes = #{
NSForegroundColorAttributeName: [UIColor blackColor],
};
messageController.messageComposeDelegate = self;
[self.view.window.rootViewController presentViewController:messageController animated:NO completion:nil];
[messageController release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Memry"
message:#"Your device does not support SMS"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
[messageController setRecipients:#[#"+86 15011582532"]];
[messageController setBody:#"I'm on Memry, come join me! =) \n https://itunes.apple.com/us/app/memry/id735465896?mt=8"];
messageController.navigationBar.titleTextAttributes = #{
NSForegroundColorAttributeName: [UIColor blackColor],
};
messageController.messageComposeDelegate = self;
[self.view.window.rootViewController presentViewController:messageController animated:NO completion:nil];
add some default value in recipients.

Resources