通过WhatsApp分享PDF

相逢意气为君饮,系马高楼垂柳边。这篇文章主要讲述通过WhatsApp分享PDF相关的知识,希望能为你提供帮助。
我想直接与WhatsApp共享PDF。
以下是我在ios应用程序中发现WhatsApp中发送文本和图像的链接,但无法找到如何将PDF直接发送到WhatsApp。
Share image/text through WhatsApp in an iOS app
答案您可以使用Share Extension(UIActivityViewController)来共享您的pdf fileURL。请注意,用户必须选择WhatsApp应用程序来共享文件。需要注意的是编辑info.plist并将whatsapp添加到LSApplicationQueriesSchemes数组中,如果您想先检查是否安装了WhatsApp:

通过WhatsApp分享PDF

文章图片

func sharePdfWhatsApp(url: URL) { let whatsappURL = URL(string:"whatsapp://app")! // this will make sure WhatsApp it is installed if UIApplication.shared.canOpenURL(whatsappURL) { let controller = UIActivityViewController(activityItems: [url], applicationActivities: nil) present(controller, animated: true) { print("done") } } }

另一答案首先,您必须以Data格式检索PDF文件。
var pdfDATA:Data!

【通过WhatsApp分享PDF】一旦您获得上述变量的数据,您可以在代码下方运行以通过WhatsApp发送PDF。
self.pdfDATA = https://www.songbingjia.com/android/try? Data.init(contentsOf: yourFilepath) let activitycontroller = UIActivityViewController(activityItems: [self.pdfDATA], applicationActivities: nil) if activitycontroller.responds(to: #selector(getter: activitycontroller.completionWithItemsHandler)) { activitycontroller.completionWithItemsHandler = {(type, isCompleted, items, error) in if isCompleted { print("completed") } } } activitycontroller.excludedActivityTypes = [UIActivityType.airDrop] activitycontroller.popoverPresentationController?.sourceView = buttonItemSize self.present(activitycontroller, animated: true, completion: nil)


    推荐阅读