MFMessageComposeViewController - empty recipients and body - ios

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

Related

How to get editable text in MFMessageComposeViewController

How to get edited text message in MFMessageComposeViewController
if ([MFMessageComposeViewController canSendText]) {
// for appear message view
MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];
messageVC.messageComposeDelegate = self;
messageVC.body = messageString;
messageVC.recipients = #[#"53645454", #"5445454545"];
// prepare message view for send Message
[self presentViewController:messageVC animated:NO completion:NULL];
}

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];
}];
}

How to send the SMS using number in an array?

I have stored the contact numbers in an array and then passed this array to message controller like the below code and printed the value of controller.recipients and its showing null.
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
NSArray *arr = [NSArray arrayWithArray:selContacts];
controller.recipients = arr;
NSLog(#"received:- %#",controller.recipients);
controller.messageComposeDelegate = self;
controller.body =#"https://itunes.apple.com/in/app/Click Here to Download!";
if([MFMessageComposeViewController canSendText])
{
[self presentModalViewController:controller animated:YES];
}
if(![MFMessageComposeViewController canSendText])
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Your device doesn't support SMS!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warningAlert show];
return;
}
NSArray *recipents = #[#"+919999999999"];
NSString *message = #"Enter message here!";
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipents];
[messageController setBody:message];
// Present message view controller on screen
[self presentViewController:messageController animated:YES completion:nil];

MFMessageComposeViewController - Remove 'Buddy Name'

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];

MFMessageComposeViewController not working

I have a simple method that gets one argument and then sends a message. It is not working.
Code:
- (void)sendSMS:(NSString *)text {
MFMessageComposeViewController *viewController = [[MFMessageComposeViewController alloc] init];
viewController.body = text;
viewControllerM.mailComposeDelegate = self;
[self presentViewController:viewController animated:YES completion:nil];
}
What's wrong?
You need to set the delegate:
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"YO";
controller.recipients = [NSArray arrayWithObjects:#"5625555555", nil];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}

Resources