Flipping Safari and back to iOS app - ios

I am trying to build an iOS app that can do single sign on using Safari. For example, I would like my app to go to https://example.com and then get some token from there and then switch back to the iOS app with that information for me to use in the app.
Currently, I tried using URL Schemes but if from within the app I try to
[[UIApplication sharedApplication] openURL:[NSURLvURLWithString:#"DevTest://example.com"]];
it is not going away from my app. It is not flipping to safari, but if I use https://example.com as the URLWithString, it flips to Safari, but I don't know on how to do the callback from Safari.
Thanks for your help!

You need to create a link on your website example.com that will start with DevTest://, then when user taps on that link in Safari your app will be started. Don't forget to register "DevTest://" URL scheme in info.plist of your app and implement appDelegate methods for URL launching, see here:
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html

Related

ios app open safari in background

I have an app that logs you in via opening safari and redirecting you back to the app - however on "Log out" I need to open safari in order to log you out - is there a way to do this in the background instead?
For Log in:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[DataService loginURL]]];
However, I would like to not have to do the same for Logout - and simply get safari to run in the background or something similar. The problem is that the cookies are saved, and I need to get rid of them. Can I get safari to open a website without having to open Safari through the application?
Can you open Safari in the background? I'm pretty certain that the answer to that is no. In any case, if your main concern is to delete the cookies then you may not get the chance - the user could just kill the app, and the cookies would sit in Safari.
Is it an option to use a UIWebView or WKWebView to perform authentication? So rather than taking them off to Safari, the user would see the browser content actually inside the app.
That might improve the user experience, and you'd get a lot more control. For example, you could point the web view to your log out url when the time came for it. That might save you some cookie hassles too.
Besides which, I think openURL: is now deprecated because it was involved in some shenanigans.

Grab URL From iOS Safari

My issue is I need to find a way where I can have my action extension run in Safari and open up the website currently being viewed in Safari in my app (my app is a special web browser).
Here's a screenshot:
When the rED extension is clicked, the extension opens up "rED://" which is my custom URL scheme. This launches the app and everything works fine.
However, I want the extension to grab the URL of the webpage being viewed in safari and open that website in my app, so the URL scheme call would look something like "rED://google.com".
What sort of code/methods would I need to implement, and in which .m file would it go in?
Apple provides a method on NSExtensionContext for opening apps via URLs, however that only works for Today extensions (verified by an Apple employee at https://stackoverflow.com/a/24709883/3943258). This technically isn't currently possible.

URL Schema in iPad for Kiosk type WebApp - Need to have Callback

Developing a Kiosk Type of the Application for iPad.
So Application flow is like i have one WebApp which runs like Kiosk(i.e it is full screen app)
and now i have one Button which Call my Native App 'CameraApp', takes an photo and upload to web.
NOW, wanted to return back to same Kiosk App or Open another URL in Kiosk already running in Background(this is either inactive or background running App).
I want to start that App in stack from the Current Stack in IOS. Is it Possible, How to Achieve it?
Background is a WebApp(Kiosk Mode) which invokes native App, now i want to jump back to the Old App. Tell me any workaround of achieving the same.
Help me out in Same. THanks!!
Is your WebApp being delivered in an iOS app or just in Safari on the iPad?
If it is an app then you can register a custom URL scheme for it and then invoke that from the camera app.
If it is just Safari then you can just launch the http: URL and return that way.
If you are using a custom URL scheme to launch your camera app you can even use that to pass information on the URL that it should return to.
Either way, the URLs can be actioned with [[UIApplication sharedApplication] openURL:url];
According to this answer you can't control the full-screen presentation from the client side - your web site needs to use the appropriate meta tag - see "Hiding Safari User Interface Components"

FBSessionLoginBehaviorWithNoFallbackToWebView opens safari if no app is installed

I want to log the user into my app with Facebook using (in this order) these methods:
The account stored in settings (via the Accounts Framework)
Switching to the Facebook App
Displaying my own UIWebView inside the app (and sending the requests
manually)
If one method doesn't work, I want to fallback to the next.
The problem I'm having is that
[self.fbsession openWithBehavior:FBSessionLoginBehaviorForcingWebView
completionHandler:
opens Safari or shows a popup that I can't customise.
I absolutely need to follow this order because I use a webview for other social networks (ie Twitter, LinkedIn and GooglePlus).
Is there any way to manually open the Facebook App for the Oauth flow ?
To manually check if the Facebook app is installed you can use:
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://requests"]]

URL shemes for apps

I wanted to open Facebook and Twitter apps from my app. I find very simple way like:
NSURL *url = [NSURL URLWithString:#"fb://profile"];
[[UIApplication sharedApplication] openURL:url];
And there are many others url for open different page of Facebook. How can I check if Facebook app exist on iPhone? What happens if the application is not install on device? Now I try to use this method on iOS Simulator but nothing happened. It's bug of iOS Simulator? Only tomorrow I will have chance to check on device.
You can check if a URL would likely open ahead of time using the canOpenURL method of UIApplication.
http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/canOpenURL:
Also! You can pass values for the facebook page you'd like. This Stack Overflow includes a link to a wiki with all the variations:
Launching Facebook and Twitter application from other iOS app
If you know the URL scheme that the other app is using (e.g. fb:// for the Facebook app), you can first ask whether your UIApplication object can open such URLs in the first place, with canOpenURL:. You can use this, for instance, to decide whether to display a link at all, or whether to direct the user to Safari (with a normal web URL) instead.
As third-party apps cannot be installed on the Simulator as far as I know, the only way to test compatibility with them is on an actual device.

Resources