gpt4 book ai didi

iphone - 使用SMTP发送邮件后,应用崩溃

转载 作者:行者123 更新时间:2023-12-01 18:22:25 25 4
gpt4 key购买 nike

在我的iPhone应用程序中,我使用SMTP来发送电子邮件。在发送邮件时,它们都能正常工作。但是有时在邮件发送后,应用突然崩溃,并显示以下错误消息

 <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");


}

请告诉我我在哪里做错了

最佳答案

我知道我回答这个问题有点晚了。但可能会帮助别人。所以去。

我遇到了同样的问题,这就是我解决的方法。我唯一要做的就是添加对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");
}

希望这可以帮助。

关于iphone - 使用SMTP发送邮件后,应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16397120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com