iOS URL Scheme Microsoft Outlook App

时间:2015-10-17 19:48:39

标签: ios outlook url-scheme

这似乎无法找到,除非也许没有。但是有人知道(如果有的话)iOS URL方案,用于打开Microsoft Outlook移动应用程序,直接使用预定义的TO_EMAIL,SUBJECT和BODY进行撰写屏幕吗?

2 个答案:

答案 0 :(得分:11)

我发现这是一个帮助我IOS Outlook URL Scheme的链接。

由此我得出了这段代码:

// 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 = fieldSubject.text;
// Encode the string for URL.
NSString* encodedSubject = [emailSubject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
// Get the email body from the body text field.
NSString* emailBody = fieldBody.text;
// Encode the string for URL.
NSString* encodedBody = [emailBody 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];

Outlook的URL方案是:ms-outlook:// compose?to=example@email.com& subject = Subject&amp; body = Message

希望这有帮助!

答案 1 :(得分:0)

迅速

func outlookDeepLink(subject: String, body: String, recipients: [String]) throws -> URL {

    enum MailComposeError: Error {
        case emptySubject
        case emptyBody
        case unexpectedError
    }

    guard !subject.isEmpty else { throw MailComposeError.emptySubject }
    guard !body.isEmpty else { throw MailComposeError.emptyBody }

    let emailTo = recipients.joined(separator: ";")

    var components = URLComponents()
    components.scheme = "ms-outlook"
    components.host = "compose"
    components.queryItems = [
        URLQueryItem(name: "to", value: emailTo),
        URLQueryItem(name: "subject", value: subject),
        URLQueryItem(name: "body", value: body),
    ]

    guard let deepURL = components.url else { throw MailComposeError.unexpectedError }
    return deepURL
}

用法

try! UIApplication.shared.open(
    outlookDeepLink(
        subject: "subject",
        body: "body",
        recipients: ["example@email.com", "example2@email.com"]
    )
)

请注意:

  1. 别忘了告诉iOS您将呼叫ms-outlook。 (将其添加到LSApplicationQueriesSchemes中的info.plist中,否则,如果忘记了它,则会在控制台中得到清晰的错误消息)

  2. 也不要忘记在尝试打开URL之前检查应用程序是否确实存在。 (canOpenURL可以为您提供帮助)