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];
}
Related
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];
}
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
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];
}];
}
I want to choose video from PhotosAlbum, follows this code, NOW I can choose video but can not go delegate method:
imagePickerController:didFinishPickingMediaWithInfo:
I don't know why, any help is appreciated.
UIImagePickerController*m_pPickerController = [[UIImagePickerController alloc] init];
[m_pPickerController setEditing:NO];
m_pPickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
m_pPickerController.delegate = self;
m_pPickerController.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
m_pPickerController.delegate = self;
m_pPickerController.videoQuality=UIImagePickerControllerQualityTypeLow;
[self presentViewController:m_pPickerController animated:YES completion:^{
m_pPickerController.delegate = self;
}];
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];