Only show whatsapp when sharing an image using UIDocumentInteractionController

According to the documentation https://www.whatsapp.com/faq/en/iphone/23559013 , setting the file format to .wai and UTI to net.whatsapp.image will show only Whatsapp in the application list.

But another application is shown, such as Add to Notes, Messenger, and 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

        }
    }

Please suggest if I am doing something wrong here

+4
source share

Source: https://habr.com/ru/post/1652004/


All Articles