UIPasteboard containing images AND text- pasting into Mail - ios

Since iOS8, the behaviour of Mail with the pasteboard seems to have changed.
I am trying to copy both images and text from my app, in a format that I can paste into the Mail app.
A UIPasteboard containing both images and text will only paste the images into Mail. A pasteboard containing one or the other works fine.
I create a dictionary for each text and image element, add them all to an array, then set pasteboard.items to the array. This method has worked for a year or two.
My guess would be that Mail now takes the "best" data in the pasteboard, and assumes that the text was included only as a fallback (such as a text description).
Has anyone else observed the same problem, and is there a workaround?

When I tried to add some text and a image to the UIPasteboard a few days ago, I found that ONLY the image was added to the UIPasteboard.
UIPasteboard.generalPasteboard().string = text
UIPasteboard.generalPasteboard().image = image
I use the code above then check UIPasteboard.generalPasteboard().string was nil, I firmly sure that my text wasn't nil. So, this may be a bug.

Related

Uploading photos to e-Mail from Swift

I am writing an app that has a simple form with a photo upload tool, the user uploads their photo to the form and it is displayed in an image view, i then want that image to be in the blank e-Mail that opens up upon clicking submit. I am using the following code to try and achieve this:
let messageBody = "\n\nPhoto: \(imageView.image!)"
The photo gets uploaded and shows in the image view fine but the email displays the following where the image is supposed to be " size {1334, 70} orientation 0 scale 1.000000"
Any help would be greatly appreciated!
Your code (or my previous answer) won't work because you are converting the image to a string (messageBody). And it basically shows you a string of information about the image. So your only option is to write the message in HTML (and set isHTML to true). The good news is that it isn't too hard.
I think the code below should work.
let messageBody = "<html><body>Photo:<img src=\"yourImage.png\"></body></html>"

Image copied to clipboard is cropped when pasted

I'm building a keyboard extension in Swift (Xcode 7.0.1, iOS 9.0.2). Since images cannot be directly inserted into the text field, I'm using UIPasteboard to copy the image from the app and then the user would paste manually into the text field. I have already modified info.plist to give the app full permission. I initially tried
UIPasteboard.generalPasteboard().image = UIImage(named: "1.png")
but I would receive the error
changing property masksToBounds in transform-only layer, will have no effect
I wasn't able to find anything to fix this error and nothing would be pasted into the clipboard. I then tried
let image = UIImage(named: "1.png")
let data = NSData(data: UIImagePNGRepresentation(image!)!)
UIPasteboard.generalPasteboard().setData(data, forPasteboardType: "public.png")
This works perfectly for larger images, but smaller images are cropped on the right side.
1) Is there a way to programmatically resize the image as a UIImage before I send it to NSData?
2) Has anyone else experienced this issue or know why it's occurring? I'd ideally like the photos being pasted to be small but this is obviously problematic.
Thanks.
I haven't found a proper solution, but adding some transparent padding to the right edge of the image is an effective workaround.

Adding custom text to UITextField buffer

Background: I have got a custom alert part of the HomeKit API. I'd like to allow the user to paste the code requested rather than inputting it manually.
Whenever there is text in the buffer it is possible to paste it by tapping on the textfield. How can I add custom text (from my App) to "this" buffer so the "paste" option appears?
You can populate the iPhone clipboard using below code. Put this code to a suitable place in your code.
UIPasteboard *clipboard = [UIPasteboard generalPasteboard];
clipboard.string = #"<Assign Some value>";

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

Trouble in Internationalisation, iOS

I need to internationalize some of the labels in a screen; do I need to localize the whole screen?
One more doubt, I have taken a string file and pulling the value of the keys from that file directly from that file using NSLocalizedString, then also do I need to localize the screen or it will by default get localized?
Thanks in advance.
you need not to localize the whole screen.
for two label only, on viewdidLoad
self.lbe1.text = NSLocalizedString(#"Label1", nil)
self.lbe2.text = NSLocalizedString(#"Label2", nil)
your second doubt is not clear to me.
You have to create the localize file. Then label you can use the localized id. Then you don't need to worry the whole screen or particular screen or particular text. Because whatever you can change. If you want more info refer this link
http://www.raywenderlich.com/64401/internationalization-tutorial-for-ios-2014

Resources