使用UIDocumentInteractionController在共享图像时仅显示whatsapp

时间:2016-08-22 06:55:53

标签: ios whatsapp uidocumentinteraction

根据文档https://www.whatsapp.com/faq/en/iphone/23559013,将.wai和UTI的文件格式设置为net.whatsapp.image只会在应用程序列表中显示Whatsapp,

但它显示其他应用程序,如添加到笔记,信使以及whatsapp选项。

    if let imageData = UIImageJPEGRepresentation(image, 1.0)
    { 
        let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
        let documentsDir: AnyObject = path[0]
        let imagePath = documentsDir.stringByAppendingPathComponent("Main")

        NSFileManager.defaultManager().createDirectoryAtPath(imagePath, withIntermediateDirectories: true, attributes: nil)

        let tempFile = NSURL(fileURLWithPath: imagePath+"/image.wai")
        do
        {
            try imageData.writeToURL(tempFile, options: .DataWritingAtomic)
            self.documentController = UIDocumentInteractionController(URL: tempFile)
            self.documentController.UTI = "net.whatsapp.image"
            self.documentController.presentOpenInMenuFromRect(self.view.frame, inView: self.view, animated: true)
        }
        catch
        {
            // alert

        }
    }

请告知我在这里做错了什么

0 个答案:

没有答案