Hello friends I have used MFMessageComposeViewController to send message for specific mobile number. For that i have used following code:
if(phoneNumber)
{
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = #"Hello";
controller.recipients = [NSArray arrayWithObjects:#"+9876543210", nil];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
}
Here in recipients array i had set one mobile number. Can i set their name in place of the number? Due to privacy reason i don't want to show the mobile number there.
Is it possible? If yes then how can we implement that.
Thanks in advance.
Related
I am new in iOS programming, I know this is too old question but I am confused here about message controller. I want to make a application in which I want to send simple messages.
if I set multiple recipients can any of one can you view all recipients?
if it so,then how can I make a private message for all so that one recipient can't view other recipients?
Here is my code for composing a message for more recipients
- (void)showSMS:(NSString*)file {
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 = #[#"12345678", #"72345524"];
NSString *message = [NSString stringWithFormat:#"Just sent the %# file to your email. Please check!", file];
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipents];
[messageController setBody:message];
[self presentViewController:messageController animated:YES completion:nil];
}
There's a setting in Settings -> Messages which disables group messaging, and all recipients will receive the messages separately. Other than that, you can't do it with MFMessageComposeViewController because there's no bcc option. Your could send the messages one at a time though
I want to send the email from my iOS device programtically using iOS.I am using the below code to send the email but i don't know where to enter from field.From which email id the mail will be sent?
Code for Sending email in iOS
// Email Subject
if(![MFMailComposeViewController canSendMail])
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Your device doesn't support Email!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warningAlert show];
return;
}
NSString *emailTitle = #"Test Email";
// Email Content
NSString *messageBody = #"iOS programming is so fun!";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:#"support#appcoda.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
Just to add, one other thing you can't do using the built-in MFMailComposeViewController class is to send emails silently, without the full-screen "Compose email" view appearing.
In my app, I resorted to sending the email details (To address, Body text, etc) to my app's WCF web service, and getting that to send the email instead.
And, of course, doing it that way, you can choose which From address you wish to use.
You cannot actually set the From field when using the MFMailComposeViewController. What actually happens is the From field will default to whatever email account the user has specified to be used as the default email account on the device in the settings.
After spending some time looking at similar questions on stack overflow, unfortunately none seemed to resolve my issue.
I'm using a UIActionSheet, when the user clicks send email on the action sheet, the following code is called:
if ([MFMailComposeViewController canSendMail]){
NSString *emailTitle = #"bla bla bla";
// Email Content
NSString *messageBody = #"bla bla bla";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:#"test#test.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
[self.view.window.rootViewController presentViewController:mc animated:YES completion:NULL];
NSLog(#"email view opened");
}
else{
UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"No mail account setup on device" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[anAlert addButtonWithTitle:#"Cancel"];
[anAlert show];
}
MFMailComposeViewController opens on my iPhone in portrait mode, but when opening the app in landscape mode on an iPad, nothing happens. No view pops up, nothing at all.
It shows "email view opened" in the NSLog but nothing else.
Thoughts?
Edit The app is portrait ONLY on iPhone, and any orientation for iPad
EDIT AGAIN
After playing around a bit more, if I assign the code to a button, it works fine, only when selecting email from the action sheet is this problem present
Found the answer, this is it :
dispatch_async(dispatch_get_main_queue(), ^ {
// INSERT EMAIL CODE HERE
});
I have the following code:
NSLog(#"Email address is %#",aPayerId);
PayPalPaymentViewController *paymentViewController;
paymentViewController = [[PayPalPaymentViewController alloc]
initWithClientId:kPayPalClientId receiverEmail:kPayPalReceiverEmail payerId:aPayerId payment:payment delegate:self
];
[self presentViewController:paymentViewController animated:YES completion:nil];
The email address prints out fine in the output window. The payment and everything goes through, however the aPayerId data does not get saved.
Any suggestions.
I am sending email via following method:
-(void) sendEmailOpenControllerWithSubject:(NSString *)subject messsageBody:(NSString *) message
{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:subject];
[controller setMessageBody:message isHTML:NO];
[controller setToRecipients:[[NSArray alloc] initWithObjects:currentProspect.email, nil]];
if (controller) [self presentModalViewController:controller animated:YES];
}
I am setting message body subject and recipient but it is likely that user changes these attribute in MailComposer.
What I need:
So I want to get the contents like message body,subject and recipients after the email is sent. As it is possible that user has changed these via mail composer.
Starting in iOS 5, you can register to be notified of changes to the availability of text message sending.
A userInfo dictionary key for the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification
NSString *const MFMessageComposeViewControllerTextMessageAvailabilityKey;
Refer more on Message UI Framework here