There are a lot of errors and problems with the UIPastboard class, so I'm really not surprised that you have problems with something that obviously should work. Honestly, the documentation is not so useful. But try this; this worked for me on a physical device, and it differs from the above methods, which should work, but obviously not for a bunch of people.
guard let imagePath = NSBundle.mainBundle().pathForResource("OliviaWilde", ofType: "jpg") else { return } guard let imageData = NSData(contentsOfFile: imagePath) else { return } let pasteboard = UIPasteboard.generalPasteboard() pasteboard.setData(imageData, forPasteboardType: "public.jpeg")
You can use "public.jpeg" or "public.png" if the source file is .jpg; he is still working. I think this only changes the format of the nested thing?
Also, were you trying to add the file extension to your first line of code, where do you create the UIImage? This may make it work.
Obviously, the use of this class is temperamental, and not just in this case of use. Therefore, even if we do the same, the difference in this code is only that we create NSData from the path, and not from UIImage. Lol let me know if this works for you.
source share