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.
Related
- (IBAction)showEmail:(id)sender {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController* composeVC = [[MFMailComposeViewController alloc] init];
composeVC.mailComposeDelegate = self;
// Configure the fields of the interface.
[composeVC setToRecipients:#[#"address#example.com"]];
[composeVC setSubject:#"Hello!"];
[composeVC setMessageBody:#"Hello from California!" isHTML:NO];
// Present the view controller modally.
[self presentViewController:composeVC animated:YES completion:nil];
// composeVC.modalPresentationStyle = UIModalPresentationPageSheet ;
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
}
It always goes in the else condition even when tested on real device. please help. this works in other Xcode versions
I want to get email clients into an Action and when I click on an email client the email should send from that particular client. Can anyone tell me how to implement it?
Please click on this for image
It should look like above image.
Hope this will helps you.
UIActionSheet* sheet = [[[UIActionSheet alloc] init] autorelease];
sheet.title = #"Add Accounts";
sheet.delegate = self;
[sheet addButtonWithTitle:#"iCloud"];
[sheet addButtonWithTitle:#"Google"];
[sheet addButtonWithTitle:#"Yahoo"];
if (condition)
[sheet addButtonWithTitle:#"XYZ"];
sheet.cancelButtonIndex = [sheet addButtonWithTitle:#"Cancel"];
then you have to create method for itemclick from actionsheet , you have to open mail app using following code
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController * emailController = [[MFMailComposeViewController alloc] init];
emailController.mailComposeDelegate = self;
[emailController setSubject:subject];
[emailController setMessageBody:mailBody isHTML:YES];
[emailController setToRecipients:recipients];
[self presentViewController:emailController animated:YES completion:nil];
[emailController release];
}
// Show error if no mail account is active
else {
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:#"Warning" message:#"You must have a mail account in order to send an email" delegate:nil cancelButtonTitle:NSLocalizedString(#"OK", #"OK") otherButtonTitles:nil];
[alertView show];
[alertView release];
}
Note, if you want to send the email from within your app itself, you can use the MFMailComposeViewController.
Apple doesnt provide an API to fetch the clients. You will have to design the ActionSheet icons on your own, and in the MFMailComposeViewController on tap of "From" field, you will have to auto populate the field with the suitable email ID.
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];
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:^{}];
My problem is i have a view with a label, wherein, the data on label is coming from web service and on tapping it mail box should appear.In a nutshell it is a mailLabel.
Similarly on the same view i have a custom cell which too has another mail label and the same thing should happen,but the mail address will be different and dynamic.
Q1) do i need to include only one method of mail for this to handle.
Q2) If yes then how and if no then what is the procedure.
i have used a second method for this and called this in cellForRow like
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITapGestureRecognizer *mgmtMail1LblGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(mail1LblTappedForCC:)];
[cell.managementMemberEmail addGestureRecognizer:mgmtMail1LblGesture];
and method.
- (void)mail1LblTappedForCC:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#""];
NSArray *toRecipients = [NSArray arrayWithObjects:objCCforManagement.managementMemberEmail.text, nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = #"";
[mailer setMessageBody:emailBody isHTML:NO];
mailer.navigationBar.barStyle = UIBarStyleBlackOpaque;
[self presentViewController:mailer animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
where
objCCforManagement is the object of custom class.
How your recognizer will get the to recipient array from
NSArray *toRecipients = [NSArray arrayWithObjects:objCCforManagement.managementMemberEmail.text, nil];
Use recognizer.view to get your label text or get value from objCCforManagement on the basis of label.text. Or particular tag set to label like label.tag=cellRowIndex etc in cellForRow method
Code ----
cell.managementMemberEmail.tag=indexPath.row;
Your mail1LblTappedForCC method is unable to find which row value or objCCforManagement is to be inserted as recipient. thats why it is showing blank.
Get your email on the basis of row tag by setting it to label.
- (void)mail1LblTappedForCC:(UITapGestureRecognizer*)recognizer
{
if ([MFMailComposeViewController canSendMail])
{
UILabel *labelOnWhichItisClicked=(UILabel*)recognizer.view;
CustomCellForExhibitorDetailVC *cell=(CustomCellForExhibitorDetailVC*)[managementTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:labelOnWhichItisClicked.tag inSection:0]];
NSLog(#"mail to is == %#",cell.managementMemberEmail.text);
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#""];
NSArray *toRecipients =[NSArray arrayWithObjects:cell.managementMemberEmail.text,nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = #"";
[mailer setMessageBody:emailBody isHTML:NO];
mailer.navigationBar.barStyle = UIBarStyleBlackOpaque;
[self presentViewController:mailer animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}