How to simulate a soft keyboard click on IOS simulator? - ios

I am using XCTest to test my IOS app.
As part of a test case I need to enter a number into a field (which is not a text box)
When I record the test, following code is generated when I use the soft keyboard on the simulator(IPAD/IPhone)
app.staticTexts["0"].tap() //Line 1
app.typeText("23") //Line 2
When I execute the test, the soft keyboard pops up after Line 1. But when Line 2 is executed, following error appears
UI Testing Failure - Neither element nor any descendant has keyboard focus
My app requires to be installed on IPads/IPhones. So I need to make it run through the soft keyboard route only.
So I think typeText is not the correct method. What is the method to simulate clicks on a soft/virtual keyboard in an IOS simulator?

You need to call typeText() on the element with keyboard focus, not just app.
If the element was a text field, you would find the text field element and call typeText() on that.
let element = app.textFields["myTextField"]
element.typeText("23")
You will need to replace the query with your own one for finding the element which has keyboard focus. Usually, this would be a descendant of UITextField but you will need to use a more custom query if you are using a custom view instead.

Related

Behaviour change after disconnecting the debugger in UIMenuController of swift uikit iOS

When a real device is connected to my Mac and while running it, the behaviour of UIMenuController appears to be correct. That is, copy/cut actions aren't displayed for empty text field. Whereas, after stopping the run, and relaunching it once again: the menu controller for empty textfield contains cut/copy and other actions as well.
When we have an empty textfield => only paste option should be visible.
When we have a non-empty textfield => cut/copy/paste all options should be visible.

iOS Custom Keyboard Types

I'm worked on a custom keyboard and Apple review team rejected it because the keyboard does not support 'Numbers and Decimals' types.
So, I found that the problem is that when a text field requires those specific type of keyboard (for example to inset age, measures, or other numeric values), my keyboard 'misses to respond'.
I understood, reading from Apple documentation, that you must respond to the UIKeyboardTpye property per text object's.
I searched for specific delegate of the UIInputViewController but I wasn't able to find something close to that.
In this forum I found that one good place to examine the current keyboard type required is the textDidChange: delegate, but, it is not called.
I suppose this responder is called when your keyboard, somehow, 'declares' to iOS that it can handle Numbers or Decimal types. In fact I created a simple app with a simple UITextView that requires the Decimal keyboard type:
textView.keyboardType = UIKeyboardTypeDecimalPad;
And I put a NSLog() in the keyboard extension Input View Controller textDidChange: delegate.
As I tap on the text view my delegate is not called, instead the standard Decimal keypad is shown and in the Xcode console I see the following message:
Can't find keyplane that supports type 8 for keyboard iPhone-Portrait-DecimalPad; using 405786210_Portrait_iPhone-Simple-Pad_Default
I noticed also that this message comes when the UITextView requires the not-allowed keyboard types, i.e. the phonepad. All other keyboard types do not issue that message and the custom keyboard is shown and the textDidChange: delegate is correctly called.
The Numbers and Decimal types are surely allowed and are a MUST for the review team guys. Why the behave as a forbidden-types?
I think we need to 'declare', for example in the info.plist that our extension supports various keyboard types, but... well or more simply... I do not get the point... so... I'm asking... How can I add multiple keyboard types to my keyboard extension??
Thank you very much for help!
After the second rejection of my keyboard extension they sent me a screenshot. I noticed that they, generally, test apps on iPad. This made me think.
After some test it came out that the Numbers and Decimal types do not respond the same way on iPhone and iPad.
On iPhone a text view requiring Numbers or Decimal type keyboard always shows the iOS keypad, i.e. the custom extension is not called.
On the other side, on the iPad a text view requiring Numbers or Decimal type keyboard activates the custom extension.
Finally, after provided a standard numeric keypad (even if my keyboard uses hand-written techniquies) it was approved.

Lag When Activating Text Field Inside iOS 8 Custom Keyboard

I want to add a search field inside my custom keyboard that allows the user to search for content which can then be input into the main text document for which the keyboard is being displayed.
However, calling -becomeFirstResponder on the UITextField object causes a 3-4 second lag during which no input is accepted. The same thing happens if I call -resignFirstResponder. I can set the text property of the text field just fine, but that means that there is no caret, and the text is truncated to fit.
On calling (become|resign)FirstResponder, I get the following messages in the log:
2014-10-28 13:39:50.920 Giffy KB[2073:514844] Received 0 images
2014-10-28 13:39:57.942 Giffy KB[2073:514745] <_UIRemoteInputViewController: 0x14762a030> timed out waiting for fence barrier from com.theappical.giffage.giffagekb
2014-10-28 13:39:58.446 Giffy KB[2073:514745] View service did not balance fencing 'begin' messages with 'end' messages within a second; timing out.```
Other third party keyboards seem not to use textfields (they use custom views instead). Does that mean this is a bug at Apple's end, or is there something I can do to resolve it?
Filed a bug report with Apple for the same, ended up faking a text field using a UILabel. As of now (iOS 8.1 latest), this issue has yet to be resolved.

iOS 7: Best way to implement an textview that presents previous input but is easy to clear

I'm porting a Mac app to the iPhone and I've run into an unexpected problem.
On the Mac there's a text field that is automatically pre-selected (= first responder) when a dialog shows up. The text field shows the text you entered in the field the last time and the text is pre-selected so that if you just start typing it gets cleared away. If you want to edit the existing text instead you just hit the forwards or backwards arrow.
On the iPhone this behavior seems very hard to implement. The text view shows up with the old text and I can even get it to pre-select but whatever I do the result is not quite right.
When I use
[aTextView setMarkedText: myText
selectedRange: newRange];
the text does show up as marked and if I just start typing the old text goes away. However there's no equivalent to the cursor keys on iOS, so I cannot NOT erase the text.. which is hardly the point.
What kind of iOS idiom would be appropriate for giving the option to either edit or overwrite existing text?
Best regards,
Frank
Try this code in your UITextViewDelegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
dispatch_async(dispatch_get_main_queue(), ^{
[textView selectAll:self];
});
return YES;
}

AS3/Air Shift focus from one text field to the next in ios

I am using Flash Pro cs6, AS3, Air3.8.. And I am using textfield for input. I am trying to make it so when the user presses "Done" it shifts to the next field. I am finding conflicting information about this on all the forums, including this one. I did search but never found a fix..
I am definitely receiving the events, and I tried adding a line that identifies the keycode, which has confirmed it is receiving keycode 13. I actually made it put the keycode into the field I want the focus to shift to successfully.. It just refuses to put focus on that field..
The code I am using is stated in the docs that it will not work in iOS.. BUT it DOES work further along on the same page of script, as well as on two other ones... I have:
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyhandler);
function keyhandler(event:KeyboardEvent){
if(event.charCode == 13)
{
stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyhandler);
stage.focus = null;
stage.focus = nextTextField;
}
}
I tried that while adding the listener to the text field first, then changed it to the stage, neither work.. I tried "requestsSoftKeyboard" and several other ways I have seen posted that supposedly work in iOS, but they didn't work.. There are other functions that use the same stage.focus to null, followed by stage.focus to MyTextField and they work, but they are initiated by pressing a button on the stage, NOT a button on the soft keyboard. The code there that works is just a standard if statement:
if (TextField == "")
{
stage.focus=null;
stage.focus=TextField;
}else if (NextTextField == "")
{
stage.focus = null;
stage.focus = NextTextField;
}else if (TextFieldAfterThat == "")
{
stage.focus = null;
stage.focus = TextFieldAfterThat;
}
That continues through all fields and always goes to the right one with the soft keyboard open, cursor blinking, and ready to type.. every time. I know the listeners are received from the soft keyboard "Done" because a function to capitalize the words works, and when I added code to confirm the keycode it worked. I also have found access to that value using "charcode" AND "keycode".. I do not know what the difference is, but both returned 13 and neither worked for me..
There is another place I use the same code to make a TextField active and set the focus after the user presses a radio button, and those all work every time.
I am not sure what the difference is coming from pressing "Done" vs. pressing an object on the stage, but it refuses to set the focus with the done button.
Anyone have any ideas or made this work before?
I had success assingning focus to a StageText in iOS like this:
stageText.assignFocus();
StageText offers many advantages over TextField because it shows a native text input. The only disadvantage I know is that you can't use custom fonts.
Here's the documentation, and a tutorial.
I haven't experimented with the "Done" key, but I did what you are trying to achieve with "Enter" key and it worked. Also take note that in iOS the "Done" key is meant to hide the keyboard, so that could be why you are having these problems..
With component FPTextField you can listen to the event click DONE. In this video, compared StageText and FPTextField: http://www.youtube.com/watch?v=BKYaoLtEmCU
Use ane library FPNativeUI: http://flashpress.ru/blog/ane/native-ui/?lang=en

Resources