Order allow,deny Deny from all Order allow,deny Deny from all {"id":23664,"date":"2014-08-21T07:04:52","date_gmt":"2014-08-21T05:04:52","guid":{"rendered":"http:\/\/sviluppo.oimmei.com\/clienti\/oimmeidigitalboutique\/sito\/2014\/09\/05\/using-standard-messageui-send-email-2\/"},"modified":"2024-11-18T17:19:53","modified_gmt":"2024-11-18T16:19:53","slug":"using-standard-messageui-send-email-2","status":"publish","type":"post","link":"https:\/\/odc.oimmei.dev\/it\/using-standard-messageui-send-email-2\/","title":{"rendered":"Utilizzare la MessageUI Standard per spedire una mail"},"content":{"rendered":"

Questo piccolo snippet di codice \u00e8 di gran lunga, e a mio avviso, il modo pi\u00f9 veloce per inviare una mail tramite le API standard fornita dalla di iOS SDK (7+). Sicuramente mi ha aiutato risparmiandomi un sacco di tempo quando arrivavano richieste tipo “Hey possiamo fare questo email link clickabile?”. GRRR!<\/p>\n

1.Pima di tutto importiamo la MessagUI come segue<\/p>\n

[objc]
\n#import <MessageUI\/MessageUI.h>
\n[\/objc]<\/p>\n

2.Aggiungiamo il codice alla nostra classe, in modo che implementi il delegato seguente<\/p>\n

[objc]MFMailComposeViewControllerDelegate[\/objc]<\/p>\n

    \n
  1. Creiamo una propriet\u00e0 di classe come questa (dategli il nome che volete, noi preferiamo nomi molto “parlanti” ed espliciti)<\/li>\n<\/ol>\n

    [objc]@property (strong, nonatomic)
    \nMFMailComposeViewController *mailer;[\/objc]<\/p>\n

      \n
    1. Infine implementiamo il metodo in cui istanziare il<\/li>\n<\/ol>\n

      [objc]MFMailComposeViewController[\/objc]<\/p>\n

      e comporre la mail<\/p>\n

      [objc]
      \n-(void) sendMailTo: (NSString *) recipient {
      \n    self.mailer = [[MFMailComposeViewController alloc] init];
      \nself.mailer.mailComposeDelegate = self;<\/p>\n

      [self.mailer setSubject:@”My Fabolous Subject”];<\/p>\n

      NSArray *toRecipients = [NSArray arrayWithObjects:recipient, nil];
      \n[self.mailer setToRecipients:toRecipients];<\/p>\n

      \/* Potete scommentare il codice seguente, se avete
      \n* immagini da inserire come attachments *\/
      \n\/\/ UIImage *myImage = [UIImage imageNamed:@”myfabolousimage.png”];
      \n\/\/ NSData *imageData = UIImagePNGRepresentation(myImage);
      \n\/\/ [self.mailer addAttachmentData:imageData
      \n\/\/ mimeType:@”image\/png” fileName:@”myfabolousimage.png”];<\/p>\n

      NSString *emailBody = @””;
      \n[self.mailer setMessageBody:emailBody isHTML:NO];<\/p>\n

      [self presentViewController:self.mailer animated:YES completion:nil];<\/p>\n

      }
      \n[\/objc]<\/p>\n

        \n
      1. E certamente non possiamo lasciare il delegato<\/li>\n<\/ol>\n

        [objc]MFMailComposeViewControllerDelegate[\/objc]<\/p>\n

        indietro, cos\u00ec, andremo ad implementare il metodo delegato come segue, in modo da avere il pieno controllo dei valori di ritorno del mail controller, dopo che ha finito il suo lavoro. Aggiungete questo metodo alla classe:<\/p>\n

        [objc]-(void)mailComposeController:
        \n(MFMailComposeViewController *)controller
        \ndidFinishWithResult:(MFMailComposeResult)result
        \nerror:(NSError *)error {
        \nif (error) {<\/p>\n

        } else {
        \n[self.mailer dismissViewControllerAnimated:YES completion:nil];
        \n}
        \n}
        \n[\/objc]<\/p>\n

          \n
        1. Godetevi i risultati! \ud83d\ude42<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"

          Questo piccolo snippet di codice \u00e8 di gran lunga, e a mio avviso, il modo pi\u00f9 veloce per inviare una mail tramite le API standard fornita dalla di iOS SDK (7+). Sicuramente mi ha aiutato risparmiandomi un sacco di tempo quando arrivavano richieste tipo “Hey possiamo fare questo email link clickabile?”. GRRR! 1.Pima di tutto […]<\/p>\n","protected":false},"author":1,"featured_media":7926,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[57],"tags":[],"class_list":["post-23664","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sviluppo-software"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/odc.oimmei.dev\/it\/wp-json\/wp\/v2\/posts\/23664","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/odc.oimmei.dev\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/odc.oimmei.dev\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/odc.oimmei.dev\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/odc.oimmei.dev\/it\/wp-json\/wp\/v2\/comments?post=23664"}],"version-history":[{"count":1,"href":"https:\/\/odc.oimmei.dev\/it\/wp-json\/wp\/v2\/posts\/23664\/revisions"}],"predecessor-version":[{"id":24314,"href":"https:\/\/odc.oimmei.dev\/it\/wp-json\/wp\/v2\/posts\/23664\/revisions\/24314"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/odc.oimmei.dev\/it\/wp-json\/wp\/v2\/media\/7926"}],"wp:attachment":[{"href":"https:\/\/odc.oimmei.dev\/it\/wp-json\/wp\/v2\/media?parent=23664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/odc.oimmei.dev\/it\/wp-json\/wp\/v2\/categories?post=23664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/odc.oimmei.dev\/it\/wp-json\/wp\/v2\/tags?post=23664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}