在应用程序电子邮件中收到SIGABRT消息

时间:2011-06-20 01:44:04

标签: objective-c xcode

我正在尝试向我的应用添加一个联系人按钮,允许用户在应用中向我发送电子邮件,但是当我测试该功能时,我收到了SIGABRT消息。我知道按钮在界面构建器中正确连接,我已将messageUI框架添加到我的应用程序中。下面是我的代码的副本。

AboutMain.m

#import "AboutMain.h"
#import <MessageUI/MessageUI.h>


@implementation AboutMain

- (void)viewDidLoad
{
    [super viewDidLoad];
}  


-(IBAction)showEmail:(id)sender {
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"email@gmail.com", nil]];
        [composer setSubject:@"Question"];
        [composer setMessageBody:@"I have a question," isHTML:NO];
        [self presentModalViewController:composer animated:YES];
        [composer release];
    }
    else
        [composer release];
}


-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    if (error){
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:[NSString stringWithFormat:@"Error:%@",[error description]]delegate:nil cancelButtonTitle:@"dismiss"otherButtonTitles:nil];
        [alert show];
        [alert release];
        [self dismissModalViewControllerAnimated:YES];

    }

    else{
        [self dismissModalViewControllerAnimated:YES];
    }


}

AboutMain.h

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




@interface AboutMain : UIViewController <MFMailComposeViewControllerDelegate> {

}
-(IBAction)showEmail:(id)sender;


@end

输出:

This GDB was configured as "x86_64-apple-darwin".Attaching to process 4176.
2011-06-19 22:30:01.987 DominickGameApp[4176:207] -[UIViewController showEmail:]: unrecognized selector sent to instance 0x7035780
2011-06-19 22:30:01.990 DominickGameApp[4176:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController showEmail:]: unrecognized selector sent to instance 0x7035780'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x010675a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x011bb313 objc_exception_throw + 44
    2   CoreFoundation                      0x010690bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00fd8966 ___forwarding___ + 966
    4   CoreFoundation                      0x00fd8522 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x0036f4fd -[UIApplication sendAction:to:from:forEvent:] + 119
    6   UIKit                               0x003ff799 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x00401c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    8   UIKit                               0x004007d8 -[UIControl touchesEnded:withEvent:] + 458
    9   UIKit                               0x00393ded -[UIWindow _sendTouchesForEvent:] + 567
    10  UIKit                               0x00374c37 -[UIApplication sendEvent:] + 447
    11  UIKit                               0x00379f2e _UIApplicationHandleEvent + 7576
    12  GraphicsServices                    0x0151b992 PurpleEventCallback + 1550
    13  CoreFoundation                      0x01048944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    14  CoreFoundation                      0x00fa8cf7 __CFRunLoopDoSource1 + 215
    15  CoreFoundation                      0x00fa5f83 __CFRunLoopRun + 979
    16  CoreFoundation                      0x00fa5840 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x00fa5761 CFRunLoopRunInMode + 97
    18  GraphicsServices                    0x0151a1c4 GSEventRunModal + 217
    19  GraphicsServices                    0x0151a289 GSEventRun + 115
    20  UIKit                               0x0037dc93 UIApplicationMain + 1160
    21  DominickGameApp                     0x00002690 main + 102
    22  DominickGameApp                     0x00002621 start + 53
    23  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
sharedlibrary apply-load-rules all
Current language:  auto; currently objective-c
(gdb) 

2 个答案:

答案 0 :(得分:3)

  

2011-06-19 22:08:59.902   DominickGameApp [3661:207]    - [UIViewController showEmail]:无法识别的选择器发送到实例   0x702a7c0

问题是您要将showEmail方法发送到UIViewController, not an instance of AboutMain`的实例。

您确定在Interface Builder中正确设置了类吗?如果通过代码实例化,请确保您实例化AboutMain

的实例

某些东西没有被连接起来。确保在崩溃之前没有控制台消息,并且正确配置了xib文件。

答案 1 :(得分:0)

MessageUI框架的import语句不正确。尝试将其更改为:

#import <MessageUI/MessageUI.h>

<强>已更新 IBActions应声明为:

-(IBAction)showEmail:(id)sender

您缺少(id)发件人部分。添加它然后再回到我们身边。