I'm basically taking a screenshot of a view, saving it to my camera roll , getting the NSURL path and exporting to Whatsapp
//Create the UIImage
UIGraphicsBeginImageContext(view.frame.size)
view.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
//Save it to camera roll round 2
var library = ALAssetsLibrary()
library.writeImageToSavedPhotosAlbum(image.CGImage, metadata: nil, completionBlock: {
(path:NSURL!, error:NSError!) -> Void in
if NSThread.currentThread() == NSThread.mainThread(){
println("\(path)")
var controller = UIDocumentInteractionController()
controller.delegate = self
controller.UTI = "net.whatsapp.image"
controller.URL = path
controller.presentOpenInMenuFromRect(CGRectZero, inView: self.view, animated: true)
}
})
I'm getting this error :
Assertion failure in -[UIDocumentInteractionController setURL:], /SourceCache/UIKit/UIKit-3318.16.21/UIDocumentInteractionController.m:1024
But according to Apple's Documentation , it has to be a NSURL (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentInteractionController_class/#//apple_ref/occ/instp/UIDocumentInteractionController/URL)
Any ideas?
nil
. Is it? – mattif NSThread.currentThread() == NSThread.mainThread()
. UseisMainThread
. Even better, don't even ask that question; if your goal is to get onto the main thread, step out onto the main thread (withdispatch_async
). – mattdispatch_async
. – matt