OK button of alert does not get clicked when testing on real ios device

Hello,
I am using appium for ios app testing. I am testing on real device , also I am sending values from excel sheet.
When invalid data sent to form, validation alert appears. But OK button cant get clicked. Also appium stops at that point. I have tried following codes =>
1)
WebDriverWait wait = new WebDriverWait(driver,20 );
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
2)
if(!driver.findElements(By.name(“OK”)).isEmpty()) {
WebElement alert1=driver.findElement(By.xpath(“UIAApplication[1]/UIAWindow[1]/UIAButton[1]”));
if(alert1 != null)
{
alert1.click();
}
}
Please suggest solution for this issue.
Thank you.