ios app open safari in background - ios

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.

Related

iOS open broswer from and App and close it at some point and return to the App?

I have an request but I don't know if it is possible. I need to open a browser from my App (which I know that is possible and I know how to do). Then after some browsing and navigation in the browser it will land at a page which I can control. In that moment I need to close the browser and go back to my application.
Is it possible to do that? And if can you provide me some lead how to do that?
you can use URLScheme in you info.plist
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007899
for test you can open your app form other app also
with
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"yourScHeme://"]];
Instead of opening browser from your application, you can use UIWebview to load web content so that no need to do transition from your app to browser.
Here is tuturial which may help you.
http://iosdeveloperzone.com/2013/11/17/tutorial-building-a-web-browser-with-uiwebview-revisited-part-1/

Close in app browser after a redirect

We have an ad partner that is redirecting users to the app store after an ad in our app is tapped. We load an in-app browser which does the redirect. Nothing in the browser ever loads, it is just a white screen. Once the user returns to our app they are looking at that empty browser. Is there anyway to dismiss or close that browser once the redirect is completed?
We don't have any control over the server side.
What kind of in-app browser you are using in your app? Like a library or an UIWebView? If it's an UIWebView, there's a callback method when the webpage is loaded (and probably, redirected the link):
- (void)webViewDidFinishLoad:(UIWebView *)webView;
If you're using a library, I'm pretty sure it also has a method like that.
I fixed this by skipping the in-app browser and used Safari instead. App store re-directs are happening without showing the browser window and all the other ads are working as expected.
Plus I got to delete a bunch of old code.

Flipping Safari and back to iOS app

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

Opening apps and closing Safari tabs on iOS

We have an App that accepts donations and per Apple's guidelines (item 21.2) we can't do this in-app, it must open a webpage in Safari to perform the donation. We've got that bit working fine, and we can actually automatically invoke the App post donation and put the user right back where they left off. The trouble is that the Tab in Safari persists when the user returns to Safari later.
Is there a way to open an app from a webpage while simultaneously closing said webpage in Safari?
So apparently the way to do it is via Javascript. You can set the window location and then immediately close the window.
e.g.
window.location = "myapp://?stuff";
window.close;

Open sites using UIWebview ONLY is safari access is allowed..how to check

I have searched the web and all my books and references but I'm not finding what I am looking for.
Because of the type of app built I need to restrict access to the UIWebView "stuff" if the user has Safari restricted.
Is there a way to check is safari has been restricted on the iPhone and if so examples...sites, references?? I'd like to be able to check and give an alert for those users and for others users just load the pages. Everything is working for me BUT I don't know how to check if it's been restricted.
Thanks in advance.
The best I've found is to use the following:
BOOL safariAvailable = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"http://test"]];
In iOS 6.0 it seems that apple changed this behavior (which worked in 5.x) :(
Only way I've found is to actually try to open the URL, and then watch for resignActive notification on your application delegate. If you fail to get it shortly after calling, then it's likely safari isn't present. Ugh.

Resources