我没有编程经验。
我试图做一个简单的iOS应用程序(只是尝试一些教程),作为“sendmail”
简单的界面只有1个按钮,按下时,它会打开MFMailComposeViewController窗口。
这就是代码。
ViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <MessageUI/MessageUI.h>
@interface ViewController : UIViewController <MFMailComposeViewControllerDelegate>
-(IBAction)showPicker:(id)sender;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(IBAction)showPicker:(id)sender
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObject:@"example@example.com"];
[picker setToRecipients:toRecipients];
[picker setSubject:@"TEST SUBJECT"];
[self presentViewController:picker animated:YES completion:nil];
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
在iPhone和iPad模拟器上,它就像一个魅力。 但是当在设备上进行测试时,它会发出信号SIGABRT并显示为main.m部分的证据:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
附近有“线程1 - 信号SIGABRT”。
任何提示?
提前感谢所有人。
答案 0 :(得分:-1)
要尝试两件事:
清理文件&lt; SHIFT+CMD+K
&gt;
从您的设备中卸载该文件,然后尝试使用已清理的文件
答案 1 :(得分:-1)
在showPicker的开头:添加:
if [MFMailComposeViewController canSendMail]
{
// Your code
}
else
NSLog(@"No mail account configured on device or not supported");