Switch between WebView and NativeView with Swift - ios

Problem Statement:
I have an a native app which has a G+ single sign-on.
When I click that button, it displays an alert - "application wants to use google.com to sign-in" along with 2 buttons "Continue" and "Cancel"
When I press "Continue" on the alert, it opens a browser inside the app where the account selection page opens. It shows accounts.google.com as the page URL.
Assuming that I've already signed in to Google once before, I want to select / click a particular account from the list of google accounts being displayed there.
After I click the account, the user is navigated to a native screen called "Dashboard".
To automate this, in Appium + Java, I click on the G+ button and then switch the context to webview and then select the account using xpath and then switch back to native view as login is done now and application is back to the native screen.
driver.findElement(By.xpath("XPATH of Native Screen - Google SignIn Button")).click;
driver.switchTo().alert().accept();//Clicks "Continue" Button.
driver.context("WEBVIEW"); //Switch to WebView
driver.findElement(By.xpath("XPATH of intended Account Name HTML control")).click();
driver.context("NATIVEVIEW");
...Then, I perform the other operations that I want to perform on the native app screen.
I want to do the same in XCode + Swift but I'm not finding any way to do it.
Here's what I do
//some code to click on the button
app.buttons["Google Sign In"].tap()
app.alerts["“AppName” Wants to Use “google.com” to Sign In"].buttons["Continue"].tap()
...Now I don't know how to switch to WebView of the App and click on the HTML control that contains the account name and then switch back to native view.
Please help.

Try using this when you click on sign in with google:
GIDSignIn.sharedInstance().signOut()

Related

Unable to load the URL in iOS WebView when the button is clicked for the first time

The mobile app is all about showing a SharePoint website in a WebView. I am trying to get the URL of a third party website on click of a button which is a part of the WebView. Based on this URL, I am trying to show an alert. On the first click of the button, the URL I am looking for, is not loading and hence the alert is not showing up. However, I am able to see the URL for the second click of the button and I'm able to see the alert as well.
Any help would be appreciated.
Thanks in Advance.

Can an iOS app add a website shortcut to the Home Screen?

Could a button in an iOS app trigger a process to add a website shortcut to the device Home Screen?
For example company A releases an app through the App Store. This contains a button to add a shortcut to company A's website on the Home Screen of the phone or tablet.
Cheers.
I was looking to achieve something similar once & I am pretty sure it cannot be done -- iOS simply won't allow it.
You have 3 options for your button action --
Present UIActivityViewController with your website Url (it will the have option to "Add to Reading List", but it won't have "Add to Home Screen")
Present SFSafariViewController with the website Url, you can open an alert view to tell the user to add to bookmarks perhaps. (it will the have option to "Add to Reading List" & "Add to Bookmarks", but it won't have "Add to Home Screen")
Launch Safari & open the website with some parameter triggered javascript code to tell the user to select "Add to Home Screen".
None of them come close to what you want and are not particularly elegant. But I don't see any other way.
(In our case, we just went with launching the Safari)
Here's an old link I found, not much has changed --
iPhone SDK - Add a "Add to Home Screen" button in a UIWebView

iOS App Facebook Login Screen with Logo

I have written an app that uses Facebook login via the FBSDKLoginButton. The login window shows up and the user can login using their Facebook email and passowrd... that all works great!
I am trying to figure out how to make the login window show our company logo but I cannot find this anywhere in the documentation.
Can someone point me in the right direction? I have seen many other iOS Apps that use FB Login and have their logo displayed so I know it can be done.
Here is a screenshot:
You should change the app icon of your Facebook app in order to do that.
Navigate to developers.facebook.com.
Click on My Apps on the top right corner.
Select your app.
Select Settings/Basic from the menu on the left.
Hover over the section called App Icon (which is on the bottom left of the first editable section) and click on the Edit button.

What is the difference between tapping keyboard "Go" button and web page button

TL;DR
I'm trying to understand what is the difference between user tapping "Go" button on software keyboard and tapping "Sign In" button rendered on authentication web page when using SFSafariViewController to authenticate user via Azure or any other OAuth provider.
Description
We're using various OAuth providers (Azure, Keycloack to name a few) to authenticate users to our native iOS application.
We present to a user, browser instance (SFSafariViewController) with login page
This page contains username, password fields and a button to sign in
When user is entering the password - he/she can either use Log In button on the page or Go button on the iOS software keyboard
In both cases login procedure will be triggered and user will be redirected back to proper URL
However, if user taps Go button on the software keyboard, application is not being notified about redirect (universal link logic doesn't work) and redirect URL page is being rendered inside SafariViewController
It happens in various OAuth providers and can be reproduced only on iOS (when using Android software keyboard button, universal link behaves fine)
We're handling this situation right now by creating special redirect page, which contains special link to a user to tap. Something like "Tap here if you're not automatically redirected back to the application". But I was wondering if there is better solution to this and what is the difference from the OS/Browser perspective between user tapping software keyboard button and HTML page element.
Your workaround seems reasonable.
About activating Universal Links when user navigates from keyboard: this case seems to be similar to situation when user types some URL to browser's address bar and tap GO. If user doing this, than the user intent is to stay in browser, not go to the App. So it is logical to not engage Universal Links.
One more way to make better experience for this case:
if user navigated to "special redirect page" on iPhone, try to navigate to customURLScheme URL of your App. At this point you already know that the App is installed on this device.
Trying to navigate to customURLScheme URL will bring up iOS system dialog, like "Do you want to open XYZ App?". Still this seems a bit better than "Tap here if you're not automatically redirected back to the application".
Probably you already found out that "special redirect page" should be located on different domain than "Universal Links enabled domain". Navigating inside the same domain will not engage Universal Links. For reference, App Preview page that we have, serves essentially the same purpose as yours "special redirect page".
This is because Universal Links on iOS cannot be programmatically opened. When you click the "Go" button you're essentially programmatically submitting the input form (You can recreate this yourself by typing in the Universal link into the Safari bar and clicking go, the app will not open). A Universal Link can only be opened when a user intentionally taps on the link itself or a link that redirects to the Universal Link.
Assuming you have control over the OAuth form, I found the following technique to provide a fairly good experience:
<button type="submit"
style="visibility:hidden; height: 0; margin: 0; padding: 0;"
onclick="document.activeElement.blur(); return false;">
</button>
Add this hidden button ABOVE all other submit buttons on your form. When the Go button is pressed, I've observed that it "clicks" the first submit button on the form. This button catches that click, blurs the current input causing the keyboard to be dismissed, and then cancels the form submission. The user then can tap the visible button(s) on the form to complete the process correctly. No need for two flows.
This also allows for users on desktop using the same OAuth form to press Enter to submit the form or to click the buttons.

iPad Safari Home Screen website gets stuck on Facebook Login

I have a website that uses the JavaScript SDK, and I have a facebook login button that calls FB.login() that opens a new tab for the user to log in.
This website is optimized for the iPad, and I made a home screen entry for this website so it could be viewed in full screen, like how this article mentions it:
http://www.viaboxxsystems.de/html-fullscreen-apps-for-the-ipad
My problem is that only in the home-screen-launched, fullscreen version, when I click on the login button, either I see a white screen, or I get the login details screen (but in that case, clicking "Log In" also results in a white screen), and thus I get to a dead end.
How do I make it so the Facebook login goes through and I get redirected back to my website successfully?
Apple’s documentation for this says,
When you use this standalone mode, Safari is not used to display the web content—specifically, there is no browser URL text field at the top of the screen or button bar at the bottom of the screen.
Sounds to me like this might also affect the ability to open popups. If that’s the case, you could maybe use the server-side authentication flow instead.

Resources