问题描述
我正在使用openURL发送带有一些链接的电子邮件。该函数如下所示:
I'm using openURL to send an email w/some links. The function looks like this:
//
+ (void) sendEmail:(NSString *) subject withBody:(NSString *)body {
NSString *mailString = [NSString stringWithFormat:@"mailto:?@&subject=%@&body=%@",
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
[mailString autorelease];
}
调用此函数的代码如下所示:
The code that calls this function looks like this:
[AppNameAppDelegate sendEmail:subjectLine withBody:bodyText];
[AppNameAppDelegate sendEmail:subjectLine withBody:bodyText];
无论subjectLine和bodyText是什么,我都会收到如下错误:
No matter what the subjectLine and bodyText, I get an error like this:
Program received signal: "EXC_BAD_ACCESS".
电子邮件实际弹出,所以我知道它正在通过openURL。但到那时我想程序已经崩溃了,所以当你退出电子邮件窗格时它没有恢复。
The email actually pops up, so I know it's making it through that openURL. But by then I guess the program has crashed and so it is not restored when you exit the email pane.
有关为什么会发生这种情况的任何想法?
Any ideas on why this is happening?
问题类似于,但该答案不适用。它看起来更像但是不幸的是,这个问题看起来好像从未解决过。
Issue looks like this but that answer isn't applicable. It looks more like this forum post but unfortunately that issue looks like it was never solved.
更新:删除自动释放的mailString时(根据StackOverflow中的说明)它没有改善这种情况。
UPDATE: When removing the autoreleased mailString (per the instructions in the StackOverflow ticket mentioned above) it does not improve the situation.
//
+ (void) sendEmail:(NSString *) subject withBody:(NSString *)body {
NSString *mailString = [NSString stringWithFormat:@"mailto:?@&subject=%@&body=%@",
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
}
设置malloc_error_break断点似乎没有做任何事情。输出仍然如下所示:
Setting a malloc_error_break breakpoint does not seem to do anything. The output still looks like this:
AppName(1424,0x3e9097c8) malloc: *** error for object 0x16fdf0: double free
*** set a breakpoint in malloc_error_break to debug
推荐答案
NSString *mailString = [NSString stringWithFormat:...
已经返回自动释放的字符串 - 您不得向其发送任何自动释放消息
already returns autoreleased string - you must not sent any autorelease messages to it
这篇关于那个mailto怎么样:openURL可能导致这个malloc崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!