I am working on IOS app in which I open login page in SFSafariViewController. And On that login page when the login is successful, a Json response is generated.
I want to get that response and close SFSafariViewController.
In android I did it through Javascript and Javascript interface..
My server side code for android:
<?php
//curl initialize
//Some code
//Curl Execution
$response = curl_exe($ch)
?>
<script>
showAndroidToast("<?php echo $response;?>");
function showAndroidToast(res){
Android.dataResponse(res);
}
</script>
In android.
Android.dataResponse(res) is my javascript interface which i added to my Chrome Custom Tabs (https://developer.chrome.com/multidevice/android/customtabs).
I want similar functionality for my IOS app.I don't know. Is this possible with SFSafariViewController or not?
According to this StackOverflow answer you cannot download files with SFSafariViewController Furthermore there seems to be no delegate to initiate the download of the JSON according to Apple's documentation
Given this information I am pretty sure that your safest bet is to go the WKWebView route even though WebKit has all sorts of limitations on iOS. You could probably use this as a starting point.
I would personally just call my login API's and create a native login form thus circumventing Apple's browsing options altogether. I hope this helps!
EDIT
The OP is actually using FitBit's API and OAuth2 and according to FitBit's Documentation:
For native applications, this means the authorization page must open in the default browser. Native applications can use custom URL schemes as redirect URIs to redirect the user back from the browser to the application requesting permission. iOS applications may use the SFSafariViewController class instead of app switching to Safari. Use of the WKWebView or UIWebView class is prohibited.
Pointers for using FitBit's Authorization Code Grant Flow can be found in their documentation but there is no proper guide. But OAuthSwift supports FitBit so that is probably the easiest way to implement the login. A discussion about a sample integration can also be found here and here.
Related
Most of the people who will access my app will do so from a preinstalled software on their pc that has a browser component built with Microsoft's WebBrowser Control which is just Internet Explorer wrapper.
I want to know if there's a way I can detect, using Javascript, or any other method from inside my website, when it is being rended using this wrapper.
The reason I want to do this is that software was already built and goes to the home page of my site. But I want to redirect them directly to the login screen if they are accessing from that wrapper.
By default the WebBrowser Control uses IE7 so you can check the user agent string (I doubt your other users will be using such an old Internet Explorer version as their browser causing a faulty recognition).
However, this is not a perfect solution, if you can modify the preinstalled software and deliver a new version to people that will be using it you can send a specific header along with the request to determine its origin.
I don't think you can do this accurately. As Samuil stated, you can hack it a bit and maybe catch some of it.
Why not set the default page of your website to be the login page so the user goes to that page regardless?
I'd like to have a single 'Get App' link that auto-detects the user's device type and browser and directs to the appropriate location (iTunes, Google Play, or website sign-up). I am currently using Onelink.to, but it has the following limitations:
if you're on iOS using a non-Safari browser (like Chrome) you end up looking at a bunch of raw JSON because it doesn't know to launch the App Store app. In this case, I'd prefer to direct to the iTunes website or better yet, deep link into the App Store app.
if using the link on your own site and a user is on a device that redirects to a different page of your own website, it complicates setting up event-based goals in Google Analytics
Are there any good JavaScript solutions that handle the App Store redirect while excluding this action on browsers that don't support the iTunes headers?
Thanks!
You can use javascript navigator.userAgent and parse it to detect the device. Then just generate the link according to it.
Here is an example for ios detection:
Detect if device is iOS
I have a typical modern web-app, regularly shared on Twitter.
I recently noticed that, when opening our web-app in the Twitter internal browser, localstorage is deactivated, which breaks our app.
How could I break out of the Twitter internal browser and open the page in the default Android browser?
I haven't tried this but just a suggestion. You could take a look at this and give it a try.
At the end of the article, it says that the external app won't be invoked if triggered without a user gesture but I believe that the limitation won't be there in case of the In-App browser.
Well, I think it isn't quite easy to say Android via a WebView to open the Chrome Browser as this in-app browser could be a lot different.
What you could try, as mentioned in the article Here is to trigger a click on an anchor which is calling an "pseudo" intent and add the fallback_url .
There isn't much details provided but it could be a possible hack / workaround.
In your HTML
...
And with JS:
$(".open_me").trigger("click");
According to the article
Now the URL will get you to zxing.org if the app could not be found, or the link was triggered from JavaScript without user gesture
(or for other cases where we don’t launch an external application.)
If you're lucky it will open the fallback_url, but as mentioned before it is a WebView which isn't the same as the Chrome Browser, therefore it is possible that nothing happens.
You can use a iFrame in your HTML like this:
<iframe src="url.com" width="900" height=400"></iframe>
I am currently working on a custom uri-scheme (protocol) in google chrome and require a method to automate some testing (and development) of this protocol purely from within the chrome browser.
For example. If a redirect/anchor link points to this example uri
testuri://thismessage/additionaldata
then I would like to to redirected back into JS somehow. I.e. with a call to say
function protocolMessage(data) { ... }
I have explored the use of 'navigator.registerProtocolHandler' but that requires the use of 'web+testuri', which isn't an option (unless someone knows of a setting that can be used to turn this off).
I have investigated using a chrome custom extension to capture the uri under webNavigation but it doesn't capture anything but http(s) schemes. And I cannot see any functions that would allow me to register a custom scheme directly either.
Further investigation led me to try calling out to a system application (using custom uri-schemes that call native executables) and this partly works but now i'm stuck on how to redirect that message back into the current page/tab's javascript.
I also had a look at NaCL (Pepper API's) but that doesn't seem to allow registration of custom schemes either.
I am hoping for a better solution than calling out and back into the browser, but if not can anyone shed any light on a good solid reusable solution?
Any ideas?
Thanks in Advance
To my knowledge, no, sadly.
All Chrome APIs work with "supported schemes" and you can't add one.
web+custom: is also an inflexible limitation.
If you have a system application, you can talk to it by either providing a WebSocket server in the application, or working with Native Messaging.
The problem with native messaging is that Chrome has to initiate the connection to a new instance of the Native host. So you'll need to be able to handle the native app being invoked separately for protocol handling and for messaging.
Instagram has some cool hooks that can be used to open the app from a web url.
e.g. instagram://camera
But when a user doesn't have instagram installed, the browser doesn't know how to handle the url. Is there a way for me to detect if the user has instagram installed (in javascript)?
In Objective-C the [[UIApplication sharedApplication] canOpenURL:url] expression may be used to detect whether a URL is handled by any app in the system. If you use PhoneGap or some similar framework, then look for this method. If you have only a webapp, then I'm pretty sure that this is impossible.
The issue with a web app is that it is sandboxed like a web page, it cannot reach outside of the browser. However, it seems to be possible that you can detect the presence with a timing based method. That is, if the app is not installed, the user will return to, or not be able to leave at all the browser within a certain, relatively short time. Thinking along these lines I found this solution: Check if URL scheme is supported in javascript
You may be able to build a solution using this approach, but the "Cannot Open Page" alert box will always be thrown at your users. Though, this IMHO is not really annoying if you handle it correctly on the web app side.
UIApplication has a method canOpenURL: that you can use to check.
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"instagram://camera"]]) {
}