Sending images with iOS 8 custom keyboard? - ios

I've been developing a custom keyboard for iOS 8, but stumbled upon a problem trying to send images using the keyboard. I did some research and it seems like there isn't a simple way to do this with UITextDocumentProxy because only NSStrings are allowed.
Am I either overlooking any simple ways to use a custom keyboard to send images and/or is there any way to work around this issue?
Thanks in advance

Apparently, you are not the only person to try a keyboard like this. If you look at the animated GIF on the site, the keyboard uses copy/paste to add the image to the messages.
The UIKeyInput Protocol, which is inherited by UITextDocumentProxy, has the following function:
func insertText(_ text: String) //Swift
- (void)insertText:(NSString *)text //ObjC
These only take a String or an NSString, as you already know. Because there are no other methods to insert content, it can be assumed that, currently, there is no other way.
Right now, I would suggest that you adopt a similar usage. When the user taps on the image, add it to the UIPasteboard. Maybe present a little banner on top of the keyboard saying, "You can now paste" or something, but that would be up to you to decide.

Related

Is there a way around Apple's UITextField Emoji bug?

So, Apple has a bug right now where if you type an Emoji into a UITextField, it will shift the text down. In fact, if you type enough emojis and then backspace, it'll shift the text even further down from where it was supposed to be. I confirmed this by trying UITextFields in Twitter, Snapchat and other apps.
Here is a video of my app displaying the bug.
Use this: textField.clipsToBounds = false
It prevents the textField to move when editing. Even when you try to edit it again.
(Tested on iPhone 6, iOS 10.0)
I don't think their would be a way around this, as it just seems that the emoji is changing the margin of the text inside of the UITextField.

Custom Keyboard in iOS 8

iOS 8 lets us create our own custom keyboards.
Is it possible to make a custom keyboard output anything other than unattributed NSStrings?
Can I make a keyboard that outputs images to say the Messages app, or is it impossible?
No, this would be too difficult since most UITextField / UITextView can only handle NSString object.
As described in the UITextDocumentProxy only NSStrings are allowed.
UITextDocumentProxy is the communication object used by UIInputViewController. UIInputViewController seems to be the base for creating custom keyboards.
Also have a look at App Extension Programming Guide
- Custom Keyboard
You can create a twitter-style workaround: when the user selects an image, you upload it to your server and send a shortened url in reponse. this shortened url will be inserted to the text view of the host app and good luck :)

How to show Emoji like skype in ios sdk

I am creating Chat Application. I want enable emoji symbols like skype in my application even thought the
Settings -> General ->Keyboard -> Add New Keyboard ->Emoji
Was not enabled in device.
I need to display the emoji like the above image. Please suggest me some ideas
Yes you can.
Directly assign emoji characters in control.
I have used \ue231 characters emoji as bullet in UITextView and UILabel.
lbltest.text=#"\ue231 Check this out!";
You can refer this link for getting supported emoji characters.
You try them. I think it useful.
http://code4app.net/ios/custom-emoji-keyboard/51395bee6803fa8427000000
http://code4app.net/ios/TSEmojiView/501229bd6803faa052000000

When is -[UITextInput selectionRectsForRange:] called?

I have an app with a custom text editor that implements the UITextInput protocol. In iOS 6, Apple added one new required method to the protocol:
- (NSArray *)selectionRectsForRange:(UITextRange *)range
I've implemented this, but I can't seem to find a way to trigger it. At least in the way my app works, it seems to never get called by the text system. Does anyone know what it's used for?
This method is only used by subclasses of UITextView. This is the only method that would give you the system selection and loupe. This is what I was told at WWDC.
I am working on my own DTRichTextEditor as well and I implemented it nevertheless, maybe one day we get the selection/loupes also for our own UIViews that are not derived from UITextView.

Initial VoiceOver selection

I'm adding VoiceOver support to my app. So far, so good, but I'd really like to be able to specify which element is the first one spoken after a UIAccessibilityScreenChangedNotification. I haven't seen a way to do this. Making something the summary element doesn't really seem to do it. Am I missing something?
This has always been perfectly possible to do.
Just write something along the lines of:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification,
self.myFirstElement);
}
#end
This works for both UIAccessibilityScreenChangedNotification and UIAccessibilityLayoutChangedNotification.
Now for Swift 5
override func viewDidAppear(_ animated: Bool) {
UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged,
argument: myFirstElement)
}
I don't think there is an API value that specifies an order of reading, other than using Summary Element value on startup - it is by design.
So you would have to test the order and default for the UIKit elements or any custom controls, because it depends on your design. You can also mark items as non-accessible elements so they won't be 'read', accessible elements read by default, and containers for accessible elements to allow you to better control your intended interactions. I don't know if making the item selected will help.
I take it you are already using the Accessibility Inspector to test your application before testing on iOS.
If you are needing some background on the subject, Rune's Working With VoiceOver Support and Gemmell's Accessibility for Apps may be worth reading.
What about using UIAccessibilityAnnouncementNotification?
This technique worked for me.
VoiceOver will announce the value of the first element in the accessibleElements array. This can be sorted to suit your needs.

Resources