cocoa - 使用 Apple Scripting Bridge 和 Mail 发送附件会导致消息背景变黑

标签 cocoa xcode macos scripting-bridge

当我使用 Apple Scripting Bridge 发送带有附件的消息时,消息的背景设置为黑色,这是一个问题,因为文本也是黑色的。有问题的代码是:

MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];

/* create a new outgoing message object */
MailOutgoingMessage *emailMessage =
[[[mail classForScriptingClass:@"outgoing message"] alloc]
 initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
 emailSubject, @"subject",
 [self composeEmailBody], @"content", nil]];

/* add the object to the mail app  */
[[mail outgoingMessages] addObject: emailMessage];

/* set the sender, show the message */
emailMessage.sender = [NSString stringWithFormat:@"%@ <%@>",[[[mail accounts] objectAtIndex:playerOptions.mailAccount] fullName],[[[[mail accounts] objectAtIndex:playerOptions.mailAccount] emailAddresses] objectAtIndex:0]];
emailMessage.visible = YES;

/* create a new recipient and add it to the recipients list */
MailToRecipient *theRecipient =
[[[mail classForScriptingClass:@"to recipient"] alloc]
 initWithProperties:
 [NSDictionary dictionaryWithObjectsAndKeys:
  opponentEmail, @"address",
  nil]];
[emailMessage.toRecipients addObject: theRecipient];

/* add an attachment, if one was specified */
if ( [playerInfo.gameFile length] > 0 ) {

    /* create an attachment object */
    MailAttachment *theAttachment = [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties:
                                     [NSDictionary dictionaryWithObjectsAndKeys:
                                      playerInfo.gameFile, @"fileName", nil]];

    /* add it to the list of attachments */
    [[emailMessage.content attachments] addObject: theAttachment];
}
/* send the message */
[emailMessage send];

背景颜色的实际更改发生在倒数第二行,即:

[[emailMessage.content attachments] addObject: theAttachment];

上面的代码部分基本上取自 Apple 的 SBSendMail 示例代码。在这个阶段,我实际上只进行了与应用程序中的数据集成所需的更改。如果我在从 Apple 新鲜下载后构建并运行 SBSendMail 示例,则执行同一行后消息背景也会更改为黑色。附加哪种类型的文件、位于何处、使用哪台计算机或操作系统似乎并不重要。

这可能是 Apple 脚本桥中的一个错误,但有人遇到过这个问题并找到解决方案吗?另外,有人知道是否可以使用脚本桥更改 MailOutgoingMessage 实例的背景颜色吗?

最佳答案

我不认为问题出在你的代码中。我认为这是最近出现的一个错误。对这个问题的快速谷歌搜索发现了这个:http://discussions.apple.com/thread.jspa?threadID=2453797&start=0&tstart=0

关于cocoa - 使用 Apple Scripting Bridge 和 Mail 发送附件会导致消息背景变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3050525/

相关文章:

objective-c - 在这种情况下,文档是什么?

ios - 使iphone 6应用程序适应iphone 4s屏幕分辨率

macos - 本地主机与 0.0.0.0 在 Mac OS 上使用 Docker

ios - 我的堆栈跟踪到哪里去了?

Xcode "ld: library not found [...] for architecture x86_64"

node.js - 无法在我的 React 项目中使用 npm 添加 node-sass 我正在我的 mac 上进行开发

macos - NSTableRowView 背景颜色仅在 subview 周围绘制

objective-c - 为什么我的 Cocoa 绑定(bind)损坏了?

c# - 创建跨平台Windows,Mac OS X应用程序

objective-c - 跨线程事件信号(Obj-C)的同步/等待设计?