I'm building an App for iPad (in Swift) that allow the user to read qr/barcode with an external reader connected via Bluetooth.
As a very first implementation, I put on view an hidden UITextField and make it firstResponder. The problem with this implementation is that I can't hide the keyboard and I can't find a way to achive this. The keyoboard is displayed in a minimal mode, but is not enough, I need to completely remove it from the screen.
My goal is: reading barcode from the external reader without show the keyboard on screen.
Thanks.
Try adding
textField.inputView = UIView()
textField.inputAssistantItem.leadingBarButtonGroups = []
textField.inputAssistantItem.trailingBarButtonGroups = []
Related
I am trying to take screenshot of every screen during iphone app automation on a simulator. Along with the screenshot I also want to extract all strings in the that particular view before taking a screenshot using xcode. Is there a way to do that? Purpose is to send these screenshots and strings for validation to another tool.
This can be done using Web Driver Agent(WDA) provided by facebook. It does provide all the functionalities you need for your app.
Here is link to github repo for it:
https://github.com/facebook/WebDriverAgent
Please have a look at it. It might help you achieving your goal.
If you are using the XCUITest framework for your automation, you can use XCUIScreen.main.screenshot() to get a screenshot of the current state.
To fetch all text currently on screen you can use XCUIApplication().descendants(matching: .textField) or .buttons or .any or whatever you expect to be on the screen, and extract the text from the element
let descendants = XCUIApplication().descendants(matching: .textField)
foreach descendant in descendants { descendant.label /*do something*/ }
You need to set an Accessibility Identifier on the view elements for this to work.
I am practicing a notes app, in which I use NSAttributedString to store the words and photo inputted in this app.
Now I am trying to implement the image tapping behavior like what the Notes app does in iOS 9.x, in which if the added photo is tapped, the screen turns to another mode, like the screenshots below.
screenshots of the Notes App in iOS 9.x
After searching Google and Stackoverflow, I found the textView:shouldInteractWithTextAttachment:inRange: method of NSAttributedString may be used to catch the tapping image behavior. However, this results in the words and photo not editable because it is necessary to make self.myTextField.editable = NO in order to enable the method above. Maybe it is possible to make a button to switch betweenself.myTextField.editable = NO and self.myTextField.editable = YES, but I'm still hope to implement what the notes app (in which there is no such a switch button) does in iOS 9.x.
I've just moved from android to iOS with swift.
android provides tools namespace that supports this kind of requirement. I just use tools:text="fake string" so that the string only appears on the IDE screen.
When it comes to iOS storyboard, while I'm drawing layout with storyboard, one question is remaining in my mind.
Can I have a fake string that only appears on the storyboard but not on iOS screen?
Please let me know if I can use the same feature in iOS programming.
No, there is no fake text available. The text which you are setting in storyboard for a label will display while you are running the application. You can create reset/change this text in viewDidLoad of the corresponding view controller by creating an outlet of the label. Like
self.label.text = "New text"
Here is my very simple code for creating a UITextView.
UITextView *textView = [[UITextView alloc] initWithFrame:self.view.bounds];
textView.editable = NO;
textView.text = #"Using iOS 3.0 and later, VoiceOver is available to help users with visual impairments use their iOS-based devices. The UI Accessibility programming interface, introduced in iOS 3.0, helps developers make their applications accessible to VoiceOver users. Briefly, VoiceOver describes an application’s user interface and helps users navigate through the application’s views and controls, using speech and sound. Users familiar with VoiceOver in Mac OS X can leverage their experience to help them quickly come up to speed using VoiceOver on their devices.";
[self.view addSubview:textView];
Given that I could not possibly do anything wrong here I am just wondering if this is an expected behaviour or a bug perhaps somebody also faced:
With voiceover enabled I expect the entire text view to be “highlighted” on tap, then its accessibilityLabel to be read to a user and after they double tap, the entire text view’s text to be read.
But what is happening is that a small portion of the text view is highlighted (usually 2 lines), accessibilityLabel is not read, but the first “highlighted" line and the first letter (!) of the second line are read instead and only after a user double taps the entire text is read.
Especially reading the first letter in the second highlighted line confuses me. Plus shouldn’t accessibilityLabel be always read in the beginning?
This looks like a big to me but Apple has always paid so much attention to accessibility, so I’m having doubts if I should report it, may be the meant it to be this way.
Another question: is there a way to achieve the following behaviour (without subleasing UITextView) when voiceover is enabled: user taps UITextView -> accessibilityLabel and the entire text are read?
In case someone else has this problem here is the answer:
textView.accessibilityTraits = UIAccessibilityTraitStaticText;
Combining the other two answers from this post has the desired effect. i.e.
textView.isAccessibilityElement = true
textView.accessibilityTraits = .staticText
Also if you are setting the attributedText property on the UITextView make sure you DO NOT set the accessibilityLabel (on the UITextView). Doing so will cause VoiceOver (Xcode 12.5, iOS 14.4.2) to read the text twice.
textView.isAccessibilityElement = true
This Works
We are using a BT device, which acts as a keyboard, to talk to the iPad.
We want this bluetooth device to talk to 1 field in our app. (Which is on it's own view)
All other textFields/areaFields we want to display the virtual keyboard.
Is this possible?
Whenever the BT device is paired it disabled the on screen keyboard.
We thought of turning bluetooth off before the view with the 1 field that needs its input from the device is displayed and then turning it back on when the view is removed, but this has 2 problems. The iPad will not automatically connect to the device and there is no way to turn bluetooth off without using private API's.
This is a related question:
Force on screen keyboard to show when bluetooth keyboard connected
that has not yet got a satisfactory answer.
Any help will be greatly appreciated
Cheers
Phil
Erica Sadun found a way of bringing back the keyboard by sending a GraphicsServices event. Post: http://www.tuaw.com/2010/06/02/hacksugar-bringing-back-the-on-screen-keyboard/ see link to source code. Sending GSEvents might not be AppStore ready, but maybe worth a try.
Phil,
I'm not sure if you've discovered the External Accessory Framework but that is probably your best bet to get what you're after and have an app that will be accepted in the store. I'm currently working through some similar issues and I think this is how I'll be able to detect which of our supported devices the user is using.
https://developer.apple.com/library/ios/#documentation/ExternalAccessory/Reference/ExternalAccessoryFrameworkReference/_index.html
EAAccessoryManager looks like it may give you back a list of attached devices. That's exactly what I'm looking for. It should allow me to then take the correct path to connect to the devices.
This may give you back what you're interested in...
#import <ExternalAccessory/ExternalAccessory.h>
- (void)_getAttachedDevices;
{
EAAccessoryManager* accessoryManager = [EAAccessoryManager sharedAccessoryManager];
if (accessoryManager)
{
NSArray* connectedAccessories = [accessoryManager connectedAccessories];
NSLog(#"ConnectedAccessories = %#", connectedAccessories);
}
}
Hope this helps.