XCUITest - How to simulate locking of the device - ios

I am writing XCUITests for my app in Swift, and I was wondering if it's possible to simulate the locking and unlocking of a device. I've looked at XCUIApplication methods but there don't seem to be any that allow me to lock the device.

This is not possible at the moment.

According to this answer, there's a private method on XCUIDevice that you can call to lock the screen as follows:
XCUIDevice.shared.perform(NSSelectorFromString("pressLockButton"))

I'm not sure but may be it is possible to do via some magic sentence like:
let siri = XCUIDevice().XCUISiriService // available since SDK 10.3
siri.activate(voiceRecognitionText: "siri, please lock my device")

Related

How to launch app automatically on recieve local notification without click on notification ios

I want to launch my application without any click on notification.Is it possible in ios?
No, you can not do it, maybe this can be done on jaibreak devices but it's can not be done on original devices.
It is impossible as of now in iOS devices.
Even it is possible, it is considered as a bad user experience practise.

Detecting Apple Watch in iOS 8

I have some events that should only be fired off if a user has an Apple Watch. Is there a way to detect whether a watch is paired? I'm not sure if I can use the shared app group to detect the Apple Watch extension or maybe I can use bluetooth?
The best you an do is set a BOOL to true in shared NSUserDefaults the first time the Watch app is run and then check for that value in your iOS app. All indications on the dev forums and publicly have been that there isn't a way to programatically know if a Watch has been paired.
This is possible on watchOS2.0+
I tried to give an answer here https://stackoverflow.com/a/44190804/2946782
you can check if connectivity session is supported as described here: How to check whether iPhone and apple watch are connected

Accessing settings in an IOS app

I am trying to create an IOS app in which you assess the settings of the phone and in my case I need to access the mute setting in settings. Can someone please help me figure this out? Mainly i just want to know if you can and how to access the setting of an IOS deviceI do not have any source code yet but I will try to get some up once I get an answer or some help. Thank you
Pretty sure that is not allowed due to sandboxing restrictions.
You cannot accessing the Settings App from your own App, you can however adjust the system volume from an App if that is all you want to do.
Check out MPVolumeView.
https://developer.apple.com/LIBRARY/ios/documentation/MediaPlayer/Reference/MPVolumeView_Class/index.html#//apple_ref/occ/cl/MPVolumeView
What you are specifically writing about is not possible but you will probably find something that answers your use case in this SO question:
How to programmatically sense the iPhone mute switch?
No way to do this easily. If you want to do what you want in a one line way, take a look at this class : http://hoishing.wordpress.com/2014/05/08/mute-checking-in-ios7/

IOS application - reopen application from background mode

Is there a way to reopen my application from background mode ?
No. It is not possible to open an app automatically. However, you can use notifications to let user know about some event related to your app.
Technically it's actually possible but only on jailbroken devices. Use the following function from the SpringBoardServices framework:
SBSLaunchApplicationWithIdentifier(CFSTR("com.mycompany.bundleid"), NO);
On non-jailbroken devices, it's not really possible.

How to check if keyboard is installed on iPad?

How can I programmatically check if a particular keyboard (in my case, Chinese handwriting) is installed on iOS (4.3)?
Short answer: You can't, at least App Store legally with Apple's public APIs.
A little longer answer: This might be possible with a hacked/jailbroken device, but I have never seen methods to accomplish this task.

Resources