Iphone 应用程序在设备中的电子邮件上崩溃
我在我的iPhone应用程序中添加了一个“Email”功能,它在iPhone上崩溃了,但在模拟器上工作。请告诉我为什么它会在设备上崩溃 这是密码Iphone 应用程序在设备中的电子邮件上崩溃,iphone,email,mfmailcomposeviewcontroller,Iphone,Email,Mfmailcomposeviewcontroller,我在我的iPhone应用程序中添加了一个“Email”功能,它在iPhone上崩溃了,但在模拟器上工作。请告诉我为什么它会在设备上崩溃 这是密码 -(IBAction)sendMail{ MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; controller.mailComposeDelegate = self; [controller setSubj
-(IBAction)sendMail{
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"Contact"];
[controller setToRecipients:[NSArray arrayWithObject:@"Contact@BettorsSidekick.com"]];
[controller setMessageBody:@"" isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;
{
if (result == MFMailComposeResultSent) {
NSLog(@"It's away!");
}
[self dismissModalViewControllerAnimated:YES];
}
试试这个
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
if(controller && [MFMailComposeViewController canSendMail]){
controller.mailComposeDelegate = self;
[controller setSubject:@"Contact"];
[controller setToRecipients:[NSArray arrayWithObject:@"Contact@BettorsSidekick.com"]];
[controller setMessageBody:@"" isHTML:NO];
[self presentModalViewController:controller animated:YES];
}
if (controller) {
[controller release];
}
试试这个
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
if(controller && [MFMailComposeViewController canSendMail]){
controller.mailComposeDelegate = self;
[controller setSubject:@"Contact"];
[controller setToRecipients:[NSArray arrayWithObject:@"Contact@BettorsSidekick.com"]];
[controller setMessageBody:@"" isHTML:NO];
[self presentModalViewController:controller animated:YES];
}
if (controller) {
[controller release];
}
使用此代码可以很好地工作
-(IBAction)Btn_EmailPressed:(id)sender{
if (![MFMailComposeViewController canSendMail]) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Email cannot be configure." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
return;
}else {
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate=self;
[picker setToRecipients:nil];
[picker setSubject:@"Email"];
[picker setMessageBody:nil isHTML:NO];
NSArray *toRecipients = [[NSArray alloc] initWithObjects:lblSite.text,nil];
[picker setToRecipients:toRecipients];
[self presentModalViewController:picker animated:YES];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)mailController didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
NSString *msg1;
switch (result)
{
case MFMailComposeResultCancelled:
msg1 =@"Sending Mail is cancelled";
break;
case MFMailComposeResultSaved:
msg1=@"Sending Mail is Saved";
break;
case MFMailComposeResultSent:
msg1 =@"Your Mail has been sent successfully";
break;
case MFMailComposeResultFailed:
msg1 =@"Message sending failed";
break;
default:
msg1 =@"Your Mail is not Sent";
break;
}
UIAlertView *mailResuletAlert = [[UIAlertView alloc]initWithFrame:CGRectMake(10, 170, 300, 120)];
mailResuletAlert.message=msg1;
mailResuletAlert.title=@"Message";
[mailResuletAlert addButtonWithTitle:@"OK"];
[mailResuletAlert show];
[mailResuletAlert release];
[self dismissModalViewControllerAnimated:YES];
}
使用此代码可以很好地工作
-(IBAction)Btn_EmailPressed:(id)sender{
if (![MFMailComposeViewController canSendMail]) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Email cannot be configure." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
return;
}else {
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate=self;
[picker setToRecipients:nil];
[picker setSubject:@"Email"];
[picker setMessageBody:nil isHTML:NO];
NSArray *toRecipients = [[NSArray alloc] initWithObjects:lblSite.text,nil];
[picker setToRecipients:toRecipients];
[self presentModalViewController:picker animated:YES];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)mailController didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
NSString *msg1;
switch (result)
{
case MFMailComposeResultCancelled:
msg1 =@"Sending Mail is cancelled";
break;
case MFMailComposeResultSaved:
msg1=@"Sending Mail is Saved";
break;
case MFMailComposeResultSent:
msg1 =@"Your Mail has been sent successfully";
break;
case MFMailComposeResultFailed:
msg1 =@"Message sending failed";
break;
default:
msg1 =@"Your Mail is not Sent";
break;
}
UIAlertView *mailResuletAlert = [[UIAlertView alloc]initWithFrame:CGRectMake(10, 170, 300, 120)];
mailResuletAlert.message=msg1;
mailResuletAlert.title=@"Message";
[mailResuletAlert addButtonWithTitle:@"OK"];
[mailResuletAlert show];
[mailResuletAlert release];
[self dismissModalViewControllerAnimated:YES];
}
如果您没有在iphone设备中配置任何电子邮件帐户,这可能是崩溃的原因,因为当您调用mfmailcomposer时,它将在模拟器上工作,但在设备上会失败,结果将是崩溃,因此请配置设备上的邮件,然后尝试上面的代码。如果您没有在iphone中配置任何电子邮件帐户设备可能已损坏,这可能是崩溃的原因,因为当您调用mfmailcomposer时,它将在模拟器上工作,但在设备上会失败,结果将是崩溃,因此请配置设备上的邮件,然后尝试上面的代码。是否有任何崩溃消息可以帮助我们?是否要发布错误消息?请在解除之前尝试清除mailComposeDelegateMailControlleran任何可以帮助我们的崩溃消息?是否要发布错误消息?请在解除MailController之前尝试清除mailComposeDelegate