如何显示以编程方式附加附件的电子邮件客户端列表

时间:2019-04-15 04:19:57

标签: ios swift email

我想显示iPhone上安装的所有应用程序的电子邮件客户端列表。

目前,我正在按照以下问题中给出的指南使用第三方库,但不支持向其添加附件。

下面是以下代码:-是否有任何方法可以基于客户端(例如yahoo邮件,gmail或iOS邮件)将电子邮件附加到电子邮件上

public static func clients() -> [ThirdPartyMailClient] {
    return [
        // sparrow:[to]?subject=[subject]&body=[body]
        ThirdPartyMailClient(name: "Sparrow", URLScheme: "sparrow",
            URLRoot: nil, URLRecipientKey: nil, URLSubjectKey: "subject", URLBodyKey: "body"),

        // googlegmail:///co?to=[to]&subject=[subject]&body=[body]
        ThirdPartyMailClient(name: "Gmail", URLScheme: "googlegmail",
            URLRoot: nil, URLRecipientKey: "to", URLSubjectKey: "subject", URLBodyKey: "body"),

        // airmail://compose?subject=[subject]&from=[from]&to=[to]&cc=[cc]&bcc=[bcc]&plainBody=[plainBody]&htmlBody=[htmlBody]
        ThirdPartyMailClient(name: "Airmail", URLScheme: "airmail",
            URLRoot: nil, URLRecipientKey: "to", URLSubjectKey: "subject", URLBodyKey: "plainBody"),

        // ymail://mail/compose?subject=[subject]&body=[body]&to=[to]
        ThirdPartyMailClient(name: "Yahoo Mail", URLScheme: "ymail", URLRoot: nil, URLRecipientKey: "to", URLSubjectKey: "subject", URLBodyKey: "body"),

        ThirdPartyMailClient(name: "IOS Mail", URLScheme: "mailto", URLRoot: nil, URLRecipientKey: "to", URLSubjectKey: "subject", URLBodyKey: "body")]
}

/**
 Returns the compose URL for the mail client, based on its custom URL scheme.

 - Parameters recipient: The recipient for the email message (optional).
 - Parameters subject: The subject for the email message (optional).
 - Parameters body: The body for the email message (optional).

 - Returns: A `NSURL` opening the mail client for the given parameters.
 */
public func composeURL(_ recipient: String?, subject: String?, body: String?) -> URL {
    var components = URLComponents(string: "\(URLScheme):\(URLRoot ?? "")")
    components?.scheme = self.URLScheme

    if URLRecipientKey == nil {
        if let recipient = recipient {
            components = URLComponents(string: "\(URLScheme):\(URLRoot ?? "")\(recipient)")
        }
    }

    var queryItems: [URLQueryItem] = []

    if let recipient = recipient, let URLRecipientKey = URLRecipientKey {
        queryItems.append(URLQueryItem(name: URLRecipientKey, value:recipient))
    }

    if let subject = subject, let URLSubjectKey = URLSubjectKey {
        queryItems.append(URLQueryItem(name: URLSubjectKey, value:subject))
    }

    if let body = body, let URLBodyKey = URLBodyKey {
        queryItems.append(URLQueryItem(name: URLBodyKey, value:body))
    }

    if queryItems.isEmpty == false {
        components?.queryItems = queryItems
    }

    if let URL = components?.url {
        return URL
    }
    else {
        return URLComponents().url!
    }
}

0 个答案:

没有答案