Get Safari's last redirected URL to my main UIviewcontroller - iphone

In my app, I call Safari to open (UIApplication delegate), Safari comes into foreground and there are some url redirections.
At last, there's a url that I want to save in my main application.
How can I get this url and how can I return to my main app?

Short answer: You can't. Apple does not allow 3rd party applications to access any information about recent URL's visited in Safari and so on.

You can't, because Safari is now open and your app is now closed. In addition, the iPhone is sandboxed so you are probably not allowed to access Safari's information anyway.
Instead, I would recommend instead using a UIWebview. It allows the user to access the web from inside of your app. The current URL open in the UIWebView is located at myWebView.request.URL.absoluteString;
EDIT: This is not an example of multitasking. Your program can not run in the background unless it is making a VoIP call, checking location, or receiving push notifications.

Related

Open an app when clicking on a url iOS

I'm wondering if there is a way to open an app when clicking on a link in safari (or other browser) in iOS.
My app posts the name of a location, a screenshot on Twitter/Facebook which also has a link. I need to detect when the user clicks that link if he is on a pc or iOS device. If they're not on iOS device I want to continue to the linked page otherwise I want to open the app and also take take that location name as a parameter when opening it.
If the app has registered a custom URL scheme the device will open the particular app when it's asked to open a URL of a particular scheme.
This stems from the CFBundleURLSchemes key of your apps infoPlist. Apple's documentation has all the information you need to get started.
To register a URL type for your app, include the CFBundleURLTypes key
in your app’s Info.plist file. The CFBundleURLTypes key contains an
array of dictionaries, each of which defines a URL scheme the app
supports. Table 6-2 describes the keys and values to include in each
dictionary.
See more here at the iOS Programming Guide: Advanced App Tricks under 'Communicating with Other Apps' section.
Edit
In order to support the specific functionality of your question you need to go one step deeper.
Your first link needs to be a standard web URL.
The page presented from the first URL needs to detect the device and forward the user onto a second URL that will open the app on the device, with whatever parameters you want to forward to the app.
So - what you're going to have to do is build some sort of device detection into the page that your first URL points to. On that page, detect the device, then conditionally forward the user onto the second URL that will be the custom URL of your particular app.
It's possible to do this device detection, and detect if they have the app installed on their device with some of the newer HTML5 features supported by mobile browsers, but your question is themed around opening apps with URLs in iOS and the main native iOS hooks you need to support opening apps (with parameters and all) is in the documentation above.

Return to app from safari

In my application, I redirect the user to the safari browser when he/she taps on a button, which in turn closes the application and opens the safari browser. There is no problem in that. It works fine. The thing is when the user quits the safari browser, I want to redirect the user back to the application, not the home screen. Any idea please...
If you control the website that you are redirecting them to, then you can place a link on the site using custom URL which I describe in more details below. But if it's a site you don't control, you can have the user surf within your app using the UIWebView.
For an iOS app, you can create custom URL schemes that your app register with the system. Then on the web page you would create a link using that custom URL. That is how Apple launches the telephone.app or the mail.app from mobile safari.
For example: Let say your app is call BigBadApp. You custom URL would be: bigbadapp:// Now, you could create a link to your app would be: Launch BigBadApp You can pass any kind of information back to your app using the custom URL and your app will handle that information in the app delegate. For iOS 4.2 and later: application:openURL:sourceApplication:annotation:. The name of old delegate on earlier version of iOS is application:handleOpenURL:
For more information see check Apple Implementing Custom URL Schemes.
Also iOS developer:tips has a tutorial on Launching Your Own Application via a Custom URL Scheme.
You can't. When you redirect someone out of your application the only way to get back is using the task switcher or opening your application from the home screen again.
If you want to keep the user in your application you could open the web pages in a webview within your application
use UIwebViewController . that represent web link within app . so that your app wont be in back ground and add back button in navigation bar on click back button navigate to back screen . i guess it would be better
i would launch an in app browser...
this is a good uiviewcontroller subclass that has most of the browser functions already implemented. its very easy to use.
https://github.com/samvermette/SVWebViewController

Can i start a iPhone app by an iframe?

Id like, if possible, just create an App for iphone by and URL, like http://keepyourlinks.com/browser.php
my go it's to make a browser inside a browser....
possible?
Yes it is, our app uses a browser inside the native application to view a web site. We also setup encryption and session variables so that we can check if they are logged in and validate that they are on the iPhone app and not in a browser.
You can use a UIWebView in your XIB and pass it a URL.

How can I detect whether a user has installed a specific iPhone app via JavaScript?

I'd like to build a mobile Web app that:
If my iPhone app is already installed, launches it by redirecting to a URL handled by the app
If my iPhone app is not installed, displays a web page encouraging users to download it from the App Store
The problem is, I don't know how to detect whether the app is installed before redirecting. Does anyone know a trick for doing this? Maybe a JavaScript hack of some sort, leveraging the App registered URL in an iframe or similar?
You very likely can't do this. Even in a native app, all you can call is UIApplication's canOpenURL: method, which just tells you if some app will open the URL, not which one. I have no idea if this function is exposed in JavaScript; very likely not (I wouldn't want malicious javascript probing my phone for which URLs it can open).

Attach XCode Debugger

I'm developing an iPhone app that needs a web login.
As usual I call
[[UIApplication sharedApplication] openURL:loginURL];
This close the app and calls the login page inside Safari.
Once logged, the app is opened once again using a callback address and the iPhone URL registration feature.
The question here is:
Since the app is closed when I call Safari, the debug stops. How can I continue the debug?
Thanks
You can, however, get XCode to connect to an application the next time it's launched. You bring up the inspector on your executable and check the "Wait for next launch/push notification" box. This is explained in more detail here.
The other alternative would be to use a UIWebView inside your app rather than switching to Safari.