Hello,
I tried some example that provides in the web for sharing an image to Whatsapp.
The same codes of function in Objective-C works fine. It can show the action sheet for selection of the WhatsApp and I can select one of the contact to share.
The same codes in Swift, it can show the action sheet for selection of the WhatsApp but after selecting the WhatsApp icon, it did nothing and it cannot show me the WhatsApp apps to be for selecting the contact.
The following is my Swift code:
import UIKit
class ViewController: UIViewController {
var controller: UIDocumentInteractionController = UIDocumentInteractionController()
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func doShare(sender: AnyObject) {
let iconImage = UIImage(named: "icon")
let savePath = NSHomeDirectory().stringByAppendingString("Documents/whatsAppTmp.wai")
UIImageJPEGRepresentation(iconImage!, 1.0)?.writeToFile(savePath, atomically: true)
let imageURL = NSURL.fileURLWithPath(savePath)
print("Image path :\(savePath)")
controller.UTI = "net.whatsapp.image"
controller.URL = imageURL
controller.presentOpenInMenuFromRect(CGRectZero, inView: self.view, animated: true)
}
}
I tested it in iOS 9.
Any expert can teach if there is some problem or something I missed?
Best reards,
Eric