Get completion event from default warning dialog? - ios

what I thought should be simple, doesn't seem so simple...
I have a BT application, so if BT is off on launch, the default warning "Turn On Bluetooth to Allow...", which has the options "Settings" and "OK" as the options. Since this is a default dialog, how do I get the button index clicked?
I am working with the iOS 8 SDK, so I assume this dialog is making use of the new UIAlertController, which now uses a completion block instead of a delegate method.

Related

Custom dialog for enabling push notifications (iOS)

Is it possible to present a custom dialog and not present the default dialog "(AppName) Would Like to Send You Notifications" (seen below)? So when the user presses the custom dialog button "Enable Notifications" it allows notifications w/o presenting the default dialog? I dont want to present the user two dialogs.
No this is not possible, the dialog is coming from iOS and not your app.
And there is a good reason for it, security. The dialog is present by the system not you app. This is done so you can hack it so the user always accepts.

XCUITest: Auto-Accepting System-Alerts. Need more fine grained control

I have read that addUIInterruptionMonitorWithDescription could be used to accept / tap on a particular button in a system alert. On recently trying some test code out, I was doing the following:
Adding a Photos Alert
Adding a Calendar Alert
Adding a Location Alert.
On the simulator, I was surprised to find that the Calendar and Location prompt automatically had their "Allow" buttons tapped. For the Photos prompt, the "Don't Allow" was hit. My question is - is there no need for addUIInterruptionMonitorWithDescription anymore? I tried using it for tapping on the dialogs but it didn't do anything. Even when I tried to hit another button on the alerts, I didn't see it working. How do I tap on the individual buttons on a system alert her?
If there is an alert on screen, and none of your interruption handlers handle it, XCTest will dismiss it for you if you are using Xcode <9.1.
To gain control of the alerts, you should create an interruption handler for each alert, returning true from the closure when (and only when) you have handled the alert that handler was intended for.
If the test tries all your alert handlers or receives a true return value from any of your handlers, and there is still an alert on screen, XCTest will handle the alert itself.

Delegates not available on BLE Authentication

I am able to read and write data from my iOS app(Central). Just after Delegate connectPeripheral:periphal is called, OS gives an alert asking for authentication PIN with two buttons "Cancel" and "Pair".
I am not able to get any notification when user presses "Cancel" or "Pair" button. I am also not able to detect if the pairing is successful or not.
self.peripheral.state always returns 2 (connected)
I have done some research to handling Cancel event of pairing popup but unfortunately apple doesn't provide any delegate to handle it.

Need info on handling system notification on iPhone in automation

We initiate pairing with iPhone,
On iPhone a notification “Do you want to pair with this device” with 2 buttons “Pair” and “cancel” is displayed.
I need to click on this “Pair” button.
I notice that this notification displayed is not part of the any mobile (iPhone) application instead its system notification.
With the current tool, I am unable to click on this “Pair” button, hence can you please suggest an automation tool for iPhone which can perform click on this “Pair” button displayed as part of system notification?
its true you can not click buttons on alert and notification with inbuild automation. automation have inbuild functionality which cancel notification and alert by click on cancel
If you are using Instrument tool provided by apple then also it is possible to tap on "Pair". Only thing you need to do is register a callback for alert before your alert come. So limitation with this is if your alert come at starting point only then it is not possible with this tool but if this alert comes in between then definitely you can tap on "Pair".
You can see in UIAutomation doc hon how to register a callback for alert.
If not able to then I can help you more.

UI Automation onAlert method not being called on simulator

Upon initial launch of my app, I get a permissions alert asking if I will allow the app to use my current location. My onAlert method successfully dismisses the alert on my device. When I run it on the simulator, it never gets called. Other internal alerts are handled by the onAlert method on the simulator. The permission alert coming from SpringBoard is not handled on the simulator. Any ideas?
UIATarget.onAlert = function onAlert(alert)
{
var title = alert.name();
UIALogger.logMessage(title);
return false;
}
This problem happens because the alert you're seeing comes from the system itself -- before the app actually launches and your automation environment is initialized.
To see this happen, add a debug line before the function definition for UIATarget.onAlert:
UIALogger.logDebug("Now setting up the alert function");
UIATarget.onAlert = function onAlert(alert) {}
Next, Reset Content and Settings... on your simulator and re-run your automation. You should notice that the debug line will not appear until after you manually dismiss the alert about using the current location.
I do not see how this would be fixable from javascript code. You have to delay the alert until the app has properly launched, or follow the example shown in this answer.
If default handler is not working for you, then you can simply use 'return true' instead of the 'return false' so that you can manually dismiss the popover.
Before 'return true' statement you can write some statement for tapping the button (dismiss button) you wish to.
I had the same problem with an app that presents an alert immediately after launching. When I logged the element tree, I could see the additional alert window, and I could let UIAutomation tap the OK button in the alert. But the alert handler was never called.
The reason was that the alert appeared before UIAutomation was set up properly to handle it. If I delayed the presentation of the alert, UIAutomation did catch it.

Resources