Email, SMS, camera, and image library usage

Source: Internet
Author: User

Email, SMS, camera, and image library usage

-First import the MessageUI. framework

Ii. import the header file # import And the proxy FMailComposeViewControllerDelegate,

MFMessageComposeViewControllerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate

III. H file

#import 
 
  #import 
  
   @interface ViewController : UIViewController
   
    @property (strong, nonatomic) IBOutlet UIButton *Email;@property (strong, nonatomic) IBOutlet UIButton *note;@property (strong, nonatomic) IBOutlet UIButton *camera;@property (strong, nonatomic) IBOutlet UIButton *mapDepot;- (IBAction)mailDelivery:(id)sender;- (IBAction)noteDelivery:(id)sender;- (IBAction)useTheCamera:(id)sender;- (IBAction)galleryUse:(id)sender;
   
  
 


Iv.. m file

-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIImageView * imageView = [[UIImageView alloc] init]; imageView. frame = CGRectMake (100, 20,120,120); imageView. backgroundColor = [UIColor greenColor]; imageView. tag = 101; [self. view addSubview: imageView];}-(void) didReceiveMemoryWarning {[super didReceiveMemoryWarning]; // Dispose Any resources that can be recreated .} // send email-(IBAction) mailDelivery :( id) sender {// determines whether the device can send emails. Class mailClass = (NSClassFromString (@ "MFMailComposeViewController"); NSString * feedbackMsg; if (! MailClass) {feedbackMsg = @ "the current system version does not support sending emails in the application"; UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @ "prompt" message: feedbackMsg delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alertView show];} else if (! [MailClass canSendMail]) {feedbackMsg = @ "You have not set an email account"; UIAlertView * alertView = [[using alloc] initWithTitle: @ "message: feedbackMsg delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alertView show];} else {[self sendFeedBackMail] ;}}// send SMS-(IBAction) noteDelivery :( id) sender {BOOL judge = [MFMessageComposeViewController canSendText]; if (judge) {MFMessageComposeViewController * Picker = [[MFMessageComposeViewController alloc] init]; picker. messageComposeDelegate = self; // recipient picker. recipients = @ [@ "186 ********"]; // content picker. body = @ "nice to meet you! "; [Self presentViewController: picker animated: YES completion: nil];} else {UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @" prompt "message: @ "the system does not have this function! "Delegate: nil cancelButtonTitle: @" OK "otherButtonTitles: nil]; [alertView show] ;}// use the camera function-(IBAction) useTheCamera :( id) sender {// UIImagePickerControllerCameraDeviceRear rear camera // callback front camera BOOL isCamera = [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceRear]; if (! IsCamera) {NSLog (@ "no camera"); return;} UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init]; imagePicker. sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker. delegate = self; // edit mode imagePicker. allowsEditing = YES; [self presentViewController: imagePicker animated: YES completion: nil];} // use gallery-(IBAction) galleryUse :( id) sender {UIImagePickerController * imagePick Er = [[UIImagePickerController alloc] init]; imagePicker. sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePicker. delegate = self; [self presentViewController: imagePicker animated: YES completion: ^ {}] ;}# pragma mark -------------- use the camera photo // select the photo-(void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info {NSLog (@ "% @", I Nfo); UIImageView * imageView = (UIImageView *) [self. view viewWithTag: 101]; // UIImagePickerControllerOriginalImage: original image // UIImage * image = [info objectForKey: UIImagePickerControllerOriginalImage]; imageView. image = image; [picker dismissViewControllerAnimated: YES completion: NULL];} // cancel album-(void) imagePickerControllerDidCancel :( UIImagePickerController *) pi Cker {[picker failed: YES completion: NULL] ;}# pragma mark -------------- send SMS --------------- (void) messageComposeViewController :( timer *) controller didFinishWithResult :( MessageComposeResult) result {NSString * title = @ "email sending reminder"; NSString * msg; switch (result) {case MessageComposeResultCancelled: msg = @ "SMS canceled! "; [Self alertWithTitle: title msg: msg]; break; case MessageComposeResultSent: msg = @" The message is sent successfully! "; [Self alertWithTitle: title msg: msg]; break; case MessageComposeResultFailed: msg = @" SMS sending failed! "; [Self alertWithTitle: title msg: msg]; break;} [self dismissViewControllerAnimated: YES completion: nil];} # pragma mark -------------- send an email ----------------- (void) sendFeedBackMail {// whether to create a mail BOOL judge = [MFMailComposeViewController canSendMail]; if (judge) {// create a mail MFMailComposeViewController * pick = [[MFMailComposeViewController alloc] init]; // Title [pick setSubject: @ "feedback"]; // email address NSArray * address = [N SArray arrayWithObject: @ "Please fill in your mailbox"]; [pick setToRecipients: address]; // content NSString * message = @ "Hello! "; Pick. mailComposeDelegate = self; [pick setMessageBody: message isHTML: NO]; // return [self presentViewController: pick animated: YES completion: NULL];} // proxy-(void) mailComposeController :( MFMailComposeViewController *) controller didFinishWithResult :( MFMailComposeResult) result error :( NSError *) error {NSString * title = @ "email sending reminder"; NSString * msg; switch (result) {case MFMailComposeResultCancelled: msg = @ "mail Cancel! "; [Self alertWithTitle: title msg: msg]; break; case MFMailComposeResultSaved: msg = @" the email is saved successfully! "; [Self alertWithTitle: title msg: msg]; break; case MFMailComposeResultSent: msg = @" the email is sent successfully! "; [Self alertWithTitle: title msg: msg]; break; case MFMailComposeResultFailed: msg = @" email sending failed! "; [Self alertWithTitle: title msg: msg]; break;} [self dismissViewControllerAnimated: YES completion: NULL];}-(void) alertWithTitle :( NSString *) _ title _ msg :( NSString *) msg {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: _ title _ message: msg delegate: nil cancelButtonTitle: @ "good" otherButtonTitles: nil]; [alert show];}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.