Can the click method in XCUIElement be used outside of the testing framework? - ios

I would like to click an element without user input. I see it's possible in XCUIElement which is a part of the XCTest framework to ensure things are working correctly, and I'm aware of various other testing frameworks that support E2E testing with simulated clicks. But is it possible to trigger this in production outside of testing? E.g. How app remotes work for a TV - pressing a button on the app will move right, left, or click an object on the TV (only remove the TV from this question and have it target the OS it's running on)

It seems accessing other apps might not be possible - https://developer.apple.com/forums/thread/698795?login=true
But they did recommend a way to programmatically click a button that was found in another stack overflow post here - how to programmatically fake a touch event to a UIButton?

Related

XCTest force touch automation

We just implemented force touch in to our app where user can access few of the app features directly through force touch pop up. So just wondering whether XCTest in Xcode support force touch automation Something similar to this. So what I'm trying to do is forceTap on the our app icon and make the test to tap one of the options as shown linked image. Thanks in advance.

Can you hide app widgets from appearing under the 3D touch quick actions?

I'd like to remove my apps Today Widget from appearing when 3D touching the app icon on the home screen because showing the quick actions and the Today Widget just doubles up the actions app provides (seen in screenshot). Is there anyway to hide widgets from the 3D touch quick actions using the Info.plist or some other method?
Thanks
So, if you have multiple homescreen widgets, you can set UIApplicationShortcutWidget to determine which one should be shown. I haven't been able to find a way to disable them altogether from appearing in the 3d touch shortcut menu.
One option you may be able to try (this works for me on the simulator) is to set this value in your Info.plist to the value of nil.
<key>UIApplicationShortcutWidget</key>
<string>nil</string>
Your other option is to create a different widget, with more useful functionality, perhaps such as showing the currently running timer, or other stats.
Apple released this has a new feature, where user can see the handy information when force touching the App icon for shortcut items. I presume we cannot remove widget during 3D touch quick actions.
Unfortunately, there's now way to hide app widget. If you set UIApplicationShortcutWidget to nil, your app will get rejected.

How can I click buttons in Control Center?

I'm a newbie when it comes to Swift and UITesting. I have a test case that must turn off the internet connection of the device but since I can't do that, I tried to access the control center by swiping the bottom most element available in the app
let app = XCUIApplication()
app.buttons["Device"].swipeUp()
app.buttons["Device"].swipeUp()
Now that shows the control center, but when I try to click the airplane mode or the Wi-Fi button, it fails.
app.otherElements["Airplane Mode"].tap()
app.otherElements["Wi-Fi"]
See Screenshot Here
Please help me how to do that or if not, a workaround to turn on or off the internet connection of my device, thanks!
There is no reliable way to do this using UI Testing. In UI Testing you can see the view hierarchy of only App under test.
Control Center is outside your App, so you do not have access to its view hierarchy.
If you would like to really do this, one way is it hard code the coordinates and then perform tap actions. Since UI Testing does not have a mechanism to specify coordinated directly, best way to do this is using coordinateWithNormalizedOffset(normalizedOffset: CGVector).

Custom iOS Floating Button

I've been looking around on the internet and there doesn't seem to be much in the way of conversation (or I'm asking the wrong question - I'm new at Objective-C and iOS both) about creating a custom Assistive Touch-like button in iOS.
I would like to access my app from a launcher application and then float a button that would let me go back into said launcher from anywhere in my app. The floating Assistive Touch button scheme seems perfect - has anyone made something like that?
[EDIT]
In response to the meaningful questions - I wasn't clear enough (again, apologies - inexperienced here).
I have three apps: App Gatherer, App Target 01, App Target 02.
App Gatherer will be able to launch multiple apps via URL. Once it does that, and the new app opens, I'm wondering if I can have a floating button that can be moved around and clicked seperate from the UI of the Target App like the Assistive Touch button. The purpose of the floating button is to get me back out of any Target Apps - it's totally separate - to the Gatherer App.
I don't have any implementation - I'm just trying to map it out and see if it's even possible. Am I in the wrong place to ask that?
when u open a app using url from AppGatherer. Then in the Target app there is only 1 way of going back to appgatherer and that is using a url again but this time opening AppGatherer. So the custom floating button will have to be implemented inside the AppTarget and when the person clicks that button AppGatherer is opened via URL Scheme. There is no other way around. You cant have a floating universal button. You will have to implement the floating button inside every AppTarget application seperately. Plus it goes without saying that button will have to be implemented in every seperate view you have within the AppTargt application.
And in order to make a floating button you will need to keep above all other views plus handle its dragging within the onDrag methods and etc.

Are there any other iOS system sounds available other than 'tock'?

I have implemented an alternative keyboard on my first iPhone app. I would like to play a sound when a button is pressed. The default click sound when the standard keyboard is pressed would be fine, but I don't know how to get that sound.
In this answer I found how to play a 'tock' sound:
Playing system sound without importing your own
I got this to work easily enough but it is a very loud sound. I've searched Stack Overflow and the Xcode help for available iOS system sounds other than 'tock' and I can't find them.
Are there other built-in sounds, maybe even the default keyboard sound, that I can use?
Prior to, and since posting this question almost 2 weeks ago I have searched high and low for a method to make the keyboard click sound work in my app. I have attempted to implement and understand Apple's documentation on custom input views. I butchered my app in many ways attempting to make it work and created several test projects. I tried to interpret how to do this from various other sources on the web. All to no avail. I have finished my app all but for this last function.
I finally hit on a simple answer towards the end of this IPhone Dev SDK form question/post. The ultimate answer is easy and can be done in a few seconds with these easy steps.
Link the 'AudioToolbox.framework' to your project (Click on your project's Target, select 'Build Phases' and under the 'Link Binary with Libraries' item click the + button and add the framework.
Add the following to the header file of the class where you want to implement the click:
#import <AudioToolbox/AudioToolbox.h>
Add the following line of code in the implementation file of your class wherever you want the keyboard click sound to appear:
AudioServicesPlaySystemSound(0x450);
THAT'S IT! AND IT WORKED!!! HALLELUJAH!
According to Paul in the other forum this has the following downside:
"keyboard keys won't be affected by the iOS user preference for keyboard sound on/off."
But when I turn the volume up or down on my iPhone or if I mute the iPhone, the keyboard click sounds do go up and down or are muted as would be expected. Given that I found it impossible to implement keyboard clicks "UIInputViewAudioFeedback" as documented, I'm happy to have anything work.
P.S. If anyone has a link to an actual project that I can download, build and run on my iPhone to see EXACTLY how to properly implement: "UIInputViewAudioFeedback" I'd be happy to give it a look. But so far I've found none, nor any step-by-step newbie style instructions on how to make it work.
[Sept 30, 2012 UPDATE:] I'm happy to say that my app was accepted into the app store using this method. Here it is: https://itunes.apple.com/app/fine-tip-tip-calculator/id563429225
...Dale
Try UIDevice's playInputClick:
[[UIDevice currentDevice] playInputClick];
From the documentation:
Use this method to play the standard system keyboard click in response to a user tapping in a custom input or keyboard accessory view. A click plays only if the user has enabled keyboard clicks in Settings > Sounds, and only if the input view is itself enabled and visible.
Make sure you adopt the UIInputViewAudioFeedback protocol in your input view class, and implement the enableInputClicksWhenVisible delegate method to return YES, as per the documentation.
EDIT - For implementation of delegate methods, check out Apple's documentation on custom input views.

Resources