0

전자 메일 및 SMS 기능을 구현하는 을 구현했지만 이메일과 SMS를 보낼 수 없습니다. 응용 프로그램이 충돌합니다MFMailComposerViewController가 전자 메일을 보내지 않음

잘. . . 는 내가 시뮬레이터 에서 실행하고 있지만, 다음과 같이

내 인터페이스 코드가 충돌 안 년대 AlertView 를 표시해야합니다 : - 다음과 같이

#import <UIKit/UIKit.h> 
#import <MessageUI/MessageUI.h> 

@interface MessagingVC :UIViewController<MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate,UITextFieldDelegate,UITextViewDelegate> 
- (IBAction)sendEmail:(id)sender; 
- (IBAction)sendSMS:(id)sender; 
@property (retain, nonatomic) IBOutlet UITextField *EmailToTxtField; 
@property (retain, nonatomic) IBOutlet UITextField *PhoneToTxtField; 
@property (retain, nonatomic) IBOutlet UITextView *massageBodyTxtView; 
@property (retain, nonatomic) NSMutableArray *toRecipentsEmail; 
@property (retain, nonatomic) NSMutableArray *toRecipentsPhone; 
@property (retain, nonatomic) MFMessageComposeViewController *MessageCompVC; 
@property (retain, nonatomic) MFMailComposeViewController *MailCompVC; 
@end 

내 구현 코드는 다음과 같습니다 - 내가 sendEmail 클릭

#import "MessagingVC.h" 

@interface MessagingVC() 

@end 

@implementation MessagingVC 
@synthesize toRecipentsEmail,toRecipentsPhone,MailCompVC,MessageCompVC; 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 
- (BOOL)textView:(UITextView *)txtView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { 
    if([text rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet]].location == NSNotFound) { 
     return YES; 
    } 

    [txtView resignFirstResponder]; 
    return NO; 
} 

-(BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 

    if (textField == _EmailToTxtField) 
    { 
     toRecipentsEmail = [NSMutableArray arrayWithArray:[textField.text componentsSeparatedByString:@","]]; 

    } 
    if (textField == _PhoneToTxtField) 
    { 
     toRecipentsPhone = [NSMutableArray arrayWithArray:[textField.text componentsSeparatedByString:@","]]; 
    } 
    [_EmailToTxtField resignFirstResponder]; 
    [_PhoneToTxtField resignFirstResponder]; 
    NSLog(@"toRecipentsEmail Count == %d",[toRecipentsEmail count]); 
    return YES; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    _massageBodyTxtView.delegate = self; 
    _EmailToTxtField.delegate = self; 
    _PhoneToTxtField.delegate = self; 
    toRecipentsPhone = [[NSMutableArray alloc] init]; 
    toRecipentsEmail = [[NSMutableArray alloc] init]; 

    // Do any additional setup after loading the view. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (void)dealloc { 

    [_EmailToTxtField release]; 
    [_PhoneToTxtField release]; 
    [_massageBodyTxtView release]; 
    [toRecipentsEmail release]; 
    [toRecipentsPhone release]; 
    [MailCompVC release]; 
    [MessageCompVC release]; 
    [super dealloc]; 
} 
- (void)viewDidUnload { 

    [self setEmailToTxtField:nil]; 
    [self setPhoneToTxtField:nil]; 
    [self setMassageBodyTxtView:nil]; 
    [self setToRecipentsEmail:nil]; 
    [self setToRecipentsPhone:nil]; 
    [self setMailCompVC:nil]; 
    [self setMessageCompVC:nil]; 
    [super viewDidUnload]; 
} 
- (IBAction)sendEmail:(id)sender { 


self.MailCompVC = [[MFMailComposeViewController alloc] init]; 
NSString *emailTitle = @"Subject"; 
MailCompVC.mailComposeDelegate = self; 
[MailCompVC setToRecipients:toRecipentsEmail]; 
[MailCompVC setMessageBody:_massageBodyTxtView.text isHTML:NO]; 
[MailCompVC setSubject:emailTitle]; 

[self presentViewController:MailCompVC animated:YES completion:nil]; 


} 
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
switch (result) 
{ 
    case MFMailComposeResultCancelled: 
     NSLog(@"Mail cancelled"); 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mail cancelled" message:@"Mail cancelled" delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil]; 
     [alert show]; 
     [alert release]; 
     break; 
    case MFMailComposeResultSaved: 
     NSLog(@"Mail saved"); 
     UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Mail saved" message:@"Mail saved" delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil]; 
     [alert1 show]; 
     [alert1 release]; 
     break; 
    case MFMailComposeResultSent: 
     NSLog(@"Mail sent"); 
     UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Mail sent" message:@"Mail sent" delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil]; 
     [alert2 show]; 
     [alert2 release]; 
     break; 
    case MFMailComposeResultFailed: 
     NSLog(@"Mail sent failure: %@", [error localizedDescription]); 
     UIAlertView *alert3 = [[UIAlertView alloc] initWithTitle:@"Mail sent failure" message:[NSString stringWithFormat:@"%@",[error localizedDescription]] delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil]; 
     [alert3 show]; 
     [alert3 release]; 
     break; 
    default: 
     break; 
} 

// Close the Mail Interface 
[self dismissViewControllerAnimated:YES completion:NULL]; 
} 

- (IBAction)sendSMS:(id)sender { 

self.MessageCompVC = [[MFMessageComposeViewController alloc] init]; 
MessageCompVC.messageComposeDelegate = self; 
[MessageCompVC setBody:_massageBodyTxtView.text]; 
[MessageCompVC setRecipients:toRecipentsPhone]; 
[self presentViewController:MessageCompVC animated:YES completion:nil]; 
} 
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result 
{ 
switch (result) 
{ 
    case MessageComposeResultCancelled: 
     NSLog(@"Message cancelled"); 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message cancelled" message:@"Message cancelled" delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil]; 
     [alert show]; 
     [alert release]; 
     break; 
    case MessageComposeResultFailed: 
     NSLog(@"Message Failed"); 
     UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Message Failed" message:@"Message Failed" delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil]; 
     [alert1 show]; 
     [alert1 release]; 
     break; 
    case MessageComposeResultSent: 
     NSLog(@"Message Sent"); 
     UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Message Sent" message:@"Message Sent" delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil]; 
     [alert2 show]; 
     [alert2 release]; 
     break; 
    default: 
     break; 
} 


[self dismissViewControllerAnimated:YES completion:nil]; 

} 

하지만, 톤 내가 무슨 일을하고 있는가 말해주십시오이 출력

2013-10-31 12:57:14.095 MyApp[325:c07] toRecipentsEmail Count == 2 
2013-10-31 12:57:21.952 MyApp[325:c07] -[__NSMallocBlock__ countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xf2ad5e0 
2013-10-31 12:57:21.953 MyApp[325:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSMallocBlock__ countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xf2ad5e0' 
*** First throw call stack: 
(0x1d65012 0x1a9ce7e 0x1df04bd 0x1d54bbc 0x1d5494e 0x346343 0x346523 0x59fde 0x1ab07055 0x9e42c0 0x9e4258 0xaa5021 0xaa557f 0xaa46e8 0xa13cef 0xa13f02 0x9f1d4a 0x9e3698 0x27d1df9 0x27d1ad0 0x1cdabf5 0x1cda962 0x1d0bbb6 0x1d0af44 0x1d0ae1b 0x27d07e3 0x27d0668 0x9e0ffc 0x2882 0x27b5) 
libc++abi.dylib: terminate called throwing an exception 
(lldb) 

와 응용 프로그램이 충돌? 나는이 문제이지만, 코드, 라인에서 그냥 배열의 오토 릴리즈 사본을 반환합니다

toRecipentsEmail = [NSMutableArray arrayWithArray:[textField.text componentsSeparatedByString:@","]]; 

그래서 그냥 시도 여부를 확실히 모르겠어요

답변

1

self.toRecipentsEmail = [NSMutableArray arrayWithArray:[textField.text componentsSeparatedByString:@","]] ; 

toRecipentsEmail 속성을 합성 했으므로이 작업을 수행하면 배열 복사본이 유지됩니다.

+0

Holi 쓰레기. . . 그것은 정말로 트릭을했다. . . :) thanks –

+0

당신은 오신 것을 환영합니다 .. :) – HRM