我正在尝试制作一个生成文件并填写所有电子邮件字段的应用程序,因此用户只需输入正文。我还让用户可以在原生 iOS 电子邮件应用程序和 Microsoft Outlook 应用程序(如果已安装)之间进行选择。
当我实现此功能以准备要在 native 电子邮件应用程序中发送的电子邮件时,我使用了 MessageUI
框架,可以轻松附加文件,但对于 Outlook 应用程序,我必须使用 URL 方案(ms -outlook://
),似乎没有简单的方法(或根本没有方法)来附加文件。
是否有人通过 Outlook 应用成功地从另一个应用发送了附件?
我基于“总比没有好”发布此答案。我知道使用 iOS 应用程序无法发送带有预附加文件的电子邮件,因此我设法找到了一种方法,至少能够在电子邮件中发送图像文件。
// Create an array of recipients for the email.
NSArray* emailRecipients = @[@"example@email.com", @"example2@email.com"];
// Create a mutable string to hold all of the recipient email addresses and add the first one.
NSMutableString* emailTo = [[NSMutableString alloc] initWithString:emailRecipients[0]];
// Loop through all of the email recipients except for the first one.
for (int index = 1; index < emailRecipients.count; index++)
{
// Add a semicolon and then the email address at the current index.
[emailTo appendFormat";%@", emailRecipients[index]];
}
// Get the email subject from the subject text field.
NSString *emailSubject = @"Your Email Subject";
// Encode the string for URL.
NSString *encodedSubject = [emailSubject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
// Define your image's size
NSString *htmlBody = (@"<div style=\"width:450px;height:797px;\"><img src=\"http://your_website.com/your_image.jpg\" style=\"width:100%;height:100%;\"></div>");
// Encode the string for URL.
NSString* encodedBody = [htmlBody stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
// See if the subject or body are empty.
if (![emailSubject length] || ![emailBody length])
{
// Exit.
return;
}
// Create a string with the URL scheme and email properties.
NSString *stringURL = [NSString stringWithFormat"ms-outlook://compose?to=%@&subject=%@&body=%@", emailTo, encodedSubject, encodedBody];
// Convert the string to a URL.
NSURL *url = [NSURL URLWithString:stringURL];
// Open the app that responds to the URL scheme (should be Outlook).
[[UIApplication sharedApplication] openURL:url];
这很容易发送嵌入在电子邮件正文中的图像文件。您可能需要根据您的图像调整大小。
关于ios - URL 方案附件 Microsoft Outlook 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37304215/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |