HKTextview emoji detection - ios

I'm having an issue. I am using the Hakawai framework in an app so that I can have mention support (#username).
The issue I've run into is that the textfield I am using is not registering the case where there is no text and a user types an emoji into the textview. As we are using HKWTextView, I believe the textViewShouldChangeTextInRange delegate method is never called, even if implemented. The only replacement I can think to use is :
- (void)textView:(HKWTextView *)textView didChangeAttributedTextTo:(NSAttributedString *)newText
originalText:(NSAttributedString *)originalText
originalRange:(NSRange)originalRange;
in HKWTextView, but that's still not picking up on emojis being typed in when no other text has.
The functionality I would like is:
- Text view is empty
- user types in anything, emoji included
- textview width shortens, "Post" button appears.
Right now, typing emojis into the empty text view will not make the post button appear. However, it's worth mentioning that once the emojis are typed in, if there is more than one, deleting one of them WILL make the post button appear. I'm at a bit of a loss here.

I found the answer to this - It turns out that HKWTextView does some rewiring of the UITextView delegate methods that are fired. Try handling the input in the UITextView delegate method textViewDidChangeSelection. That method will be fired when an emoji is typed.

Related

iOS 8 Keyboard Extension Detecting first responder change

I'm writing a keyboard extension for iOS (hence overriding UIInputViewController) and I'm trying to figure out how to detect when the first responder changes. Is this even possible?
My motivation is that when the user selects a different text input field (while the keyboard is active) the style of the keyboard might need to change to suit the attributes of that input. This can happen when there are several text fields displayed on a UI and the user first selects one (causing the keyboard to be initialized) then the user selects another with different attributes (keyboard doesn't know it).
I've looked through the methods exposed by UIInputViewController and the delegates it implements but nothing I've seen really fits the bill. The closest thing I've found is selectionDidChange on UITextInputDelegate.
I found the best way to get this information is to override the UITextInputDelegate textDidChange method (UIInputViewController implements UITextInputDelegate). It turns out that textDidChange is called whenever the user switches the input text field (first responder), or when the text changes for some reason (luckily not when it is your keyboard that initiated the change).
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
That should tell you when it expects to become firstResponder. A couple things to keep in mind;
*This will only be called when a UITextFied is the thing becoming firstResponder. If some other object decides to, this won't be called. It'll probably call the method below.
-(BOOL)becomeFirstResponder
*Your class must conform to the UITextFieldDelegate and all of your UITextFields must set their delegates to self. Without that they won't call shouldBeginEditing on your class.

How to implement a UITextField similar to email Text Field in MFMailComposeController

In MFMailComposeController, once we start typing, the list of email addresses is shown. Once we select, the TextField displays the name of the user with a small Oval background. Then we can continue typing. If we want to delete it, then pressing backspace selects the oval background and on second backspace the email address is deleted. How can this be implemented.
I am not interested in the search part. I am fine with Implementing it. But I am more interested in getting the TextField working as in the MFMailComposeController. The way the blue oval background is set for already typed in emails.
Thanks
If you simply want to search through a set addresses,strings or whatever you can implement UISearchDisplayController and you will getyour job done.Here's the link on UISearchDisplayController iPhone.
Else , if you want to have youown you have will have to have a UITextField with a UITableView and you will have to implement the delegates method of UITextField to get the autocomplete feature searching through tableview's datasource.Implement your logic using delegates of UITableView and UITexField.
you can use many open source implementation one name from them is TITokenFieldView.

custom input view keyboard functionality

I wanted to ask a quick question just to make sure I am not missing anything simple before I implement a more difficult method. I need to create a custom keyboard for an iPhone application. This I have already done by creating a view with the buttons, using a custom input view and it displays exactly like it should. Now most of the buttons are standard numbers which need to update a UITextField in the screen that called the keyboard. Does anyone know a simple way to do this? I assume there has to be a built in function that the keyboard uses to send the information but I haven't been able to find any reference to it. Otherwise I will have to go the more difficult route. If anyone has a simple way to do this I would appreciate it. I haven't worked with custom keyboards before.
You won't be able to do it the same way that Apple does it, as their keyboard is basically an input device, globally.
I recommend you just append the data in your button press multiplex method. Here's an example:
NSString *appendThisText = #"subtitle";
self.myTextView.text=[NSString stringWithFormat:#"%#%#", self.myTextView.text, appendThisText];
Custom keyboards are simpler than you realise.
UITextField conforms to the UITextInput protocol. That's a bit of a red-herring because this protocol provides all the really complex stuff like selecting text and so on. But UITextInput itself conforms to UIKeyInput. This is your friend.
The key UIKeyInput methods are:
- (void)insertText:(NSString *)text;
- (void)deleteBackward;
Your keyboard class should have a delegate (which points to the textfield that the keyboard is operating on) and you simply call these methods to insert and delete text.

Setting UITextView's editable to NO always resigns FirstResponder. Can be avoided?

My app basically lets you send a piece of text. When the user taps send, I would like to disable the text view which contains the text so the user can't edit it anymore as the text is being sent. It seems though that setting either enableUserInteraction or editable to NO always resigns the first responder (basically the keyboard is dismissed) which is a behavior I don't want. I want to keep the keyboard displayed. Is there anyway around this? Thanks in advance.
While I don't really understand why you think it's a good idea to keep the keyboard on screen if there's nothing to edit, you can achieve this by having a hidden UITextField and making that first responder.
If the UITextView's delegate method textView:shouldChangeTextInRange:replacementText: returns NO, its contents will not be changed.

Curious Warning Message on UITextView

Has anyone run across this warning message building for the iPhone?
More importantly do you understand how to fix it?
"unsupported configuration data detection and editable"
It's seems to be the UITextView that is complaining.
Here's a screenshot.
The problem is that you have that textview set both to editable + to detect/autolink phone numbers, events, addresses, etc. a text area can either be editable and not detect/autolink text, or it can autolink text but not be editable.
Your settings for that textview should look like:
or
but not like:
I think in your scenario, the text input is only used to input text, nothing more. Then when it get's presented back, the "presenting text view" will take care of detecting the potential information... dates, events, etc.
To be more precise : in a simple app scenario, a user types in some text (let's say an event input text view - with no detection necessary at this point). Then when it get's eventually presented back to him or another user (let's say the detail view of the event), the text will be presented back in a "non-editable" text view that in turn will be able to have detections.
I know this question is a little old, but this is how I resolved it;
In Interface Builder I have Links Detection selected, and Editable Behaviour not selected.
Then, in my ViewController, I implemented the UITextView - (BOOL)textViewShouldBeginEditing:(UITextView *)textView { } delegate method and return NO.
It removed the warning and prevents the user from being able to edit the UITextView's content.

Resources