在我的iPhone应用程序中,我使用SMTP来发送email.all,在发送邮件时效果很好。但有时在发送邮件后,应用程序会突然崩溃,并显示以下错误消息
<Warning>: Application 'UIKitApplication:com.myid.smtpsample[0x2630]' exited abnormally with signal 11: Segmentation fault: 11
��May 6 17:07:21 Device-3 ReportCrash[13041] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary这是我的代码:
-(void) sendEmail
{
NSData *imagedata=UIImageJPEGRepresentation(image, 0.2f);
SKPSMTPMessage *Message = [[SKPSMTPMessage alloc] init];
Message.fromEmail = @"my email";
Message.toEmail = receiverEmailString;
Message.relayHost = @"smtp.gmail.com";
Message.requiresAuth = YES;
Message.login = @"my email";
Message.pass = @"my password";
Message.subject = @"Details";
Message.wantsSecure = YES;
Message.delegate = self;
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,@"Message Body",kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
NSDictionary *vcfPart= [NSDictionary dictionaryWithObjectsAndKeys:@"image/jpeg;\r\n\tx-unix-mode=0644;\r\n\tname=\"MyPhoto.jpg\"",kSKPSMTPPartContentTypeKey,
@"attachment;\r\n\tfilename=\"MyPhoto.jpg\"",kSKPSMTPPartContentDispositionKey,[imagedata encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
Message.parts = [NSArray arrayWithObjects:plainPart,vcfPart,nil];
[Message send];
}
- (void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error{
NSLog(@"delegate - error(%d): %@", [error code], [error localizedDescription]);
}
- (void)messageSent:(SKPSMTPMessage *)message{
NSLog(@"delegate - message sent");
}请告诉我哪里做错了
发布于 2013-11-29 23:42:12
我知道我回答这个问题有点晚了。但也许能帮到别人。这样就可以了。
我也有同样的问题,这就是我如何解决它的。我唯一需要做的就是添加一个对SKPSMTPMessage对象的强引用,并在发送电子邮件时引用它。就像一种护身符。(哦,还有,我把message = nil;留得很圆滑,这对我来说没有任何问题。)
@interface MyViewController ()
@property (nonatomic, strong) SKPSMTPMessage *Message;
@end
-(void) sendEmail
{
_Message = [[SKPSMTPMessage alloc] init];
_Message.fromEmail = @"my email";
_Message.toEmail = receiverEmailString;
...
[_Message send];
}
- (void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error{
message = nil;
NSLog(@"delegate - error(%d): %@", [error code], [error localizedDescription]);
}
- (void)messageSent:(SKPSMTPMessage *)message{
message = nil;
NSLog(@"delegate - message sent");
}希望这能有所帮助。
发布于 2013-05-06 20:43:53
你在一个方法中创建消息,给它自己作为一个委托(这意味着它将在完成时给你发消息),但是在发送消息之后,当你离开这个方法时,消息被ARC释放。因此,创建一条消息ivar,只有在它告诉你它成功或失败后才将其置零(并在分派到主线程的块中执行此操作,在委托回调中直接置零或释放对象是有风险的)。
另外,对于类实例,请使用小写,对于类对象,请使用大写首字母。
https://stackoverflow.com/questions/16397120
复制相似问题