iOS에서 메일과 문자 보내기

프레임워크 가져오기


MessageUI 가져오기framework

메일을 보내다


우선h 파일에서 다음 작업을 수행합니다.
#import <MessageUI/MFMailComposeViewController.h>
다음 에이전트 구현: MFMailComposeViewController Delegate
- (void)businessContactWithMail
{
    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
    if (mailClass != nil)
    {
        // We must always check whether the current device is configured for sending emails
        if ([mailClass canSendMail])
        {
            MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
            picker.mailComposeDelegate = self;
            [picker setToRecipients:[NSArray arrayWithObject:@""]];
            [picker setSubject:[NSString stringWithFormat:@""]];
            
            UIDevice *device = [UIDevice currentDevice];
            
            NSString *content=[NSString stringWithFormat:@""];
            [picker setMessageBody:content isHTML:NO];
            [self presentViewController:picker animated:YES completion:^{
                
            }];
        }
        else
        {
            [NDUI showAlertWithInfo:@" " title:@" "];
        }
    } else {
        [NDUI showAlertWithInfo:@" " title:@" "];
    }
}
#pragma mark - Mail and SMS delegate
// Dismisses the email composition interface when users tap Cancel or Send.
// Proceeds to update the message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

문자 발송


우선h 파일에서 다음 작업을 수행합니다.
#import <MessageUI/MFMailComposeViewController.h>
다음 에이전트 구현: MFMessageComposeViewController Delegate
- (void)shareWithSMS
{
    Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
	BOOL smsEnabled=NO;
	if (messageClass != nil) { 			
		// Check whether the current device is configured for sending SMS messages
		if ([messageClass canSendText]) {
            MFMessageComposeViewController *smsClident = [[MFMessageComposeViewController alloc] init];
            smsClident.messageComposeDelegate = self;
            
            NSString *messageBody = [NSString stringWithFormat:@""];
            
            [smsClident setBody:messageBody];
            [self presentModalViewController:smsClident animated:YES];
		}
		else {	
			[NDUI showAlertWithInfo:@" " title:@" "];
		}
	}
	else {
		
		[NDUI showAlertWithInfo:@" " title:@" "];
	}
    if(!smsEnabled){
        return;
    }
    
	
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissModalViewControllerAnimated:YES];
}

좋은 웹페이지 즐겨찾기