в приложении электронная почта получает сообщение SIGABRT - PullRequest
0 голосов
/ 20 июня 2011

Я пытаюсь добавить в приложение кнопку контакта, которая позволила бы пользователю отправить мне электронное письмо в приложении, но когда я тестирую функцию, я получаю сообщение 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 ]

3 голосов
/ 20 июня 2011

2011-06-19 22: 08: 59.902 DominickGameApp [3661: 207] - [UIViewController showEmail]: нераспознанный селектор отправлен в экземпляр 0x702a7c0

Проблема в том, что вы отправляетеметод showEmail для экземпляра UIViewController, not an instance of AboutMain`.

Вы уверены, что правильно установили класс в Интерфейсном Разработчике?При создании экземпляра с помощью кода убедитесь, что вы создаете экземпляр AboutMain.

Что-то не правильно подключено.Убедитесь, что перед сбоем нет консольных сообщений и что файл xib настроен правильно.

0 голосов
/ 20 июня 2011

Ваш оператор импорта для платформы MessageUI неверен.Попробуйте изменить его следующим образом:

#import <MessageUI/MessageUI.h>

ОБНОВЛЕНО IBActions должно быть объявлено как:

-(IBAction)showEmail:(id)sender

Вам не хватает (id) части отправителя.Добавьте это и вернитесь к нам.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...