iOS URL Scheme Microsoft Outlook App

前端 未结 2 770
醉酒成梦
醉酒成梦 2021-01-04 18:31

This seems impossible to find, unless perhaps there isn\'t one for it. But anyone know (if there is one) the iOS URL Scheme for opening the Microsoft Outlook Mobile App rig

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 18:53

    Swift

    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
    }
    

    Usage

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

    Note that:

    1. Don't forget to tell iOS you are going to call ms-outlook. (Add it to LSApplicationQueriesSchemes in info.plist, Otherwise, You will get an clear error message in console if you forget it)

    2. Also don't forget to check if the app actually exists before trying to open the url. (canOpenURL is here to help)

提交回复
热议问题