Sending mail , sms , and phone call from iphone using programatically. It is very easy to do this here i am giving you complete code snippest so using it you can achive your solution.
First of all Add MessageUI framework in your project.
After it add header file in header file messageviewcontroller.h
Send Mail:
Send SMS:
Make Phone Call:
when you run application it will show you like..
First of all Add MessageUI framework in your project.
After it add header file in header file messageviewcontroller.h
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
Now just add three buttons in your xib file and create their action events. and add delegate like
@interface MessageViewController : UIViewController <MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate>Step 1:
Send Mail:
- (IBAction)btnEmail_Clicked:(id)senderStep 2:
{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:[NSArray arrayWithObject:@"devang9978@gmail.com"]];
[controller setSubject:@"Email,SMS,Phonecall"];
[controller setMessageBody:@"http://www.studyoverflow.org" isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
}
Send SMS:
- (IBAction)btnMessage_Clicked:(id)senderStep 3:
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:+919978562737"]];
}
Make Phone Call:
- (IBAction)btnCall_Clicked:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:+919978562737"]];
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultFailed:
NSLog(@"Failed");
break;
case MessageComposeResultSent:
NSLog(@"Send");
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}// this snippest code for checking message is sent,failed or cancelled
when you run application it will show you like..
Send Email on devang9978@gmail.com for any help regarding iphone.
MessageviewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
@interface MessageViewController : UIViewController <MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate>
{
}
- (IBAction)btnEmail_Clicked:(id)sender;
- (IBAction)btnMessage_Clicked:(id)sender;
- (IBAction)btnCall_Clicked:(id)sender;
@end
MessageViewController.m
#import "MessageViewController.h"
@implementation MessageViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Message sending";
}
- (IBAction)btnEmail_Clicked:(id)sender
{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:[NSArray arrayWithObject:@"devang9978@gmail.com"]];
[controller setSubject:@"Email,SMS,Phonecall"];
[controller setMessageBody:@"http://www.studyoverflow.org" isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
}
- (IBAction)btnMessage_Clicked:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:+919978562737"]];
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultFailed:
NSLog(@"Failed");
break;
case MessageComposeResultSent:
NSLog(@"Send");
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
if (result == MFMailComposeResultSent) {
NSLog(@"sent");
}
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)btnCall_Clicked:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:+919978562737"]];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
Now you can achieve your solution to send mail or sms and phone call.
Iphone Developer
Devang Patel
0 comments:
Post a Comment