How to add a attachment in outlook programatically swift 3

半世苍凉 提交于 2019-12-22 09:23:08

问题


I have opened the outlook app and send a file in it. I am able to open the outlook and set the To,Subject and Body but not sure how to attach file in the document directory The file is at path

  var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
    let documentsDirectory = paths[0]
    let fileName = "supportdata.log"
    let logFilePath = (documentsDirectory as NSString).appendingPathComponent(fileName)

let scheme : String = "ms-outlook://compose?tosupport@tech.com&subject=Support data &body=Please find the attached file" 
     if let url = URL(string: scheme) {
        UIApplication.shared.open(url, options: [:], completionHandler: {
            (success) in
            if (success)
            {
                print("Open \(scheme): \(success)")
            }                     
        })
    }

回答1:


Sadly, it is not possible. There are two main issues:

  1. You are deeplinking to an app, meaning sending an on-device message to another app that is effectively the same as a normal URI with a GET method parameterized string. String only, no major data/files can be sent. The URL Scheme below is for reference. And it is the same as what you're using; though I think you are missing an '=' in your ms-outlook:// string.

    ms-outlook://compose?to=%@&subject=%@&body=%@

  2. iOS is pretty strict with app sandboxes, you cannot pass local files to other apps unless they are on the same app/file domain (e.g. you're the owner of both apps). There are a few alternatives that work in a watered-down format, but are not relevant for this scenario. Here's the thing, even if you could, Microsoft would need to support this file attachment feature, which it doesn't. Sadly, there's nothing we can do about it on our side... other than asking Microsoft to add the feature.

However, if you want to do this in the apple mail app, that's certainly doable.



来源:https://stackoverflow.com/questions/46204740/how-to-add-a-attachment-in-outlook-programatically-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!