How to get the gif which copied from safari from UIPasteboard - ios

I am trying to get the copied gif from UIPasteboard, but what's the pasteboard type going to be? The com.compuserve.gif or kUTTypeGIF. Should I use
- valueForPasteboardType: or just use image property to get the gif?

This works for me:
UIPasteboard.generalPasteboard().setData(myGifData as! NSData, forPasteboardType:"com.compuserve.gif")

I think one of the proper way to store images in pasteboard is as NSData.Then reconstruct UIImage from NSData.

Related

How to pass imageView as source to QuickLook preview

After picking an image from UIImagePickerController, I am trying to pass that imageView as a source to QuickLook preview which requires URL as a data source.
I am not interested to write the image into any document storage to create a URL, which will create a copy image again in the disk.
Note:
I am using a scanner SDK where it will return a UIImage as a result, so i need to use that UIImage for QuickLook preview.
Any suggestion to achieve this?
You might want to checkout this method (https://developer.apple.com/documentation/uikit/uiimagepickercontrollerdelegate/1619126-imagepickercontroller). One of the arguments to this method is an 'info' dictionary which can be used to get the image URL. Use the key 'imageURL'.

Image picker crash - iOS Swift

I have some code that will select an image from either the user's photo library or from their camera and display it in an image view. I'm accessing the photo URL from the following line of code:
let pickedPhotoURL: URL = (info["UIImagePickerControllerImageURL"] as? URL)!
This works perfectly when accessing a photo from the user's library. However, I'll always get a nil value at this line why trying to access the photo via the camera. Anyone have any ideas / suggestions?
It's because that value isn't set for a camera. Use UIImagePickerControllerOriginalImage (or edited image if you are using that).
That key gives you a UIImage -- if you need a URL, you need to save it somewhere.
Also, don't use strings, there are keys defined for you.

How to run a animated Gif directly by assigning it to Wkinterfaceimage using watchkit in Xcode?

Here is my doubt !!!
How to run a animated gif image directly by getting dynamically from url / NSdata and assigning it to Wkinterfaceimage ???
i am working on the applewatch app development from past few days it's so great.Currently i'm working on the GIf Images assigning to the imageview. I successfuly done by adding the series of images statically in xcode and running it by assigning to Wkinterfaceimage.
Right now, Watchkit does not support to run the GIF image. So although you can download the GIF Image from url but you can't show up on the watchkit interface. to show the gif file, we have split gif file to severals images and after that we can start animated the image instead of show gif file.
Download GIF image from URL to NSData type. Then, Pass that NSData object to WKInterfaceImage setImageData method.

How to create custom keyboard extension with images on it in Objective-C?

I am having an app in which I want to create my own custom keyboard.
In this custom keyboard, I want to put images.
Users can access this keyboard from anywhere in the device.
I want it like this Link.
I want to make a keyboard like this
I have searched a lot on this and I know there are lots of tutorials but most of those are in swift and another are not with keyboard extension.
I want proper guidance or any link of tutorial for this.
Any help would be highly appreciated.
Thanks...
So I got my answer from the below link which is a very nice tutorial in objective C.
Custom keyboard with extensions in objective c for ios8
Now, like I needed, if anyone wants to add custom images in it, you can just copy the image to the clipboard and paste the image where its needed.
For copying the png files, use the below code.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *imageName = [NSString stringWithFormat:#"%ld",(long)sender.tag];
NSString *newPathName = [[NSBundle mainBundle]pathForResource:imageName ofType:#"png"];
NSData *data = [NSData dataWithContentsOfFile:newPathName];
[pasteboard setData:data forPasteboardType:#"public.png"];
This public.png comes from http://www.escape.gr/manuals/qdrop/UTI.html
You can choose any extension type you want to.
The pasteboard type changes as per the image extensions.
Important note: For image sending, the Apps which gives an access to paste the image copied from clipboard, only from those apps images will be sent.
I did it with the above solutions. Hope it helps someone else also.
Thanks...
This question is several years old now, but if anyone has the same needs today, I have created a Swift library that helps you create keyboard extensions that support characters, operations like backspace, newline etc. as well as images. It also has support for copying images to the pasteboard and saving them to the photo album.
If you need a library like this, feel free to check it our here:
https://github.com/danielsaidi/KeyboardKit

How do you copy an animated gif to clipboard from a keyboard?(iOS 8)

I'm making a custom keyboard in which you can copy an gif to clipboard when pressing a button.
I'm not getting to work so far. Even though I've tried the following
-(void)doWhenButtonPressed {
[UIPasteboard generalPasteboard].image = [UIImage imageNamed:#"my.gif"];
}
Now it does not copy anything, which I think is kind of strange, because it does copy the image when i it with this line in a normal application. So what am i doing wrong?
PS: I have even checked that I can actually acces 'my.gif' by adding it programmatically to a button...
PPS: And the method -(void)doWhenButtonPressed is called as well.
Okay so I finally found the answer myself :)
You have to set "RequestsOpenAccess" to "YES" in your Info.plist. Then you can copy an image to clipboard!
Here is the demo code in Swift 3.0.
let pb = UIPasteboard.general
let data = NSData(contentsOfURL: url)
if data != nil
{
self.pb.setData(data!, forPasteboardType: kUTTypeGIF as String)
}
You dont really need the "RequestOpenAccess" to be enabled to actually copy paste into a UITextView.
You just need to load your image into the UIPasteBoard general object and then you can paste it into a UITextView by long pressing and then choosing paste.

Resources