iOS調用系統發送短信和郵件分享

 

//發送郵件
-(void)sendMail:(NSString*)subject content:(NSString*)content{
   
   MFMailComposeViewController*controller = [[[MFMailComposeViewControlleralloc]init]autorelease];
   if([MFMailComposeViewControllercanSendMail])
    {
        [controllersetSubject:subject];
        [controllersetMessageBody:contentisHTML:NO];
        controller.mailComposeDelegate=self;
        [selfpresentModalViewController:controlleranimated:YES];
    }
}

#pragma mark - MFMailComposeViewControllerDelegate
//郵件完成處理
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
   
    [selfdismissModalViewControllerAnimated:YES];
   
   if(result ==MessageComposeResultCancelled)
       NSLog(@"Message cancelled");
   elseif(result ==MessageComposeResultSent)
       NSLog(@"Message sent");
   else
       NSLog(@"Message failed"); 
   
}

 

 

// 發送短信
- (void)sendSMS:(NSString*)bodyOfMessage recipientList:(NSArray*)recipients
{
   MFMessageComposeViewController*controller = [[[MFMessageComposeViewControlleralloc]init]autorelease];
   if([MFMessageComposeViewControllercanSendText])
    {
        controller.body= bodyOfMessage;
        controller.recipients= recipients;
        controller.messageComposeDelegate=self;
        [selfpresentViewController:controlleranimated:YEScompletion:^{
           
        }];
    }
}
//處理髮送完的響應結果
- (void)messageComposeViewController:(MFMessageComposeViewController*)controller didFinishWithResult:(MessageComposeResult)result
{
    [selfdismissModalViewControllerAnimated:YES];
   
   if(result ==MessageComposeResultCancelled)
       NSLog(@"Message cancelled");
   else if(result ==MessageComposeResultSent)
       NSLog(@"Message sent");
   else
       NSLog(@"Message failed");
}
相關文章
相關標籤/搜索