Can I open my application from Safari using custom URL scheme? - iphone

Hey I was wondering if It is possible to add my own application to the UIActionSheet that opens up in safari when you press the share button on the bottom toolbar. I would like to take the user to my application if that button is pressed.

you may want to look at asking the user to add a bookmark in safari to your app.
Tweetie/Instapaper and Summly have similiar features that pass info using javascript to your app from safari bookmarks.
(correction - Tweetie had, not sure if Twitter still use it)
edit - javascript like this works.
javascript:window.location=%27YOUR_CUSTOM_URL_SCHEME://%27+window.location
this takes the current safari url and passes it to your app and you can handle it in
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url;

No. It is not possible to modify core applications like Safari, or any other application for that matter, from your own app (without using private APIs...).

Related

iPhone SDK - Add a "Add to Home Screen" button in a UIWebView

I have a native iPhone app, which has a UIWebView component to it. I am trying to see if I can replicate the "Add to Home Screen" button that is present in the tab bar options in Safari.
Is this possible inside a UIWebView within a native app?
Thanks!
Brett
[I presume your question is about replicating the action associated with add to home screen, rather than replicating the appearance of the button itself (which being pedantic is what you actually wrote).]
As others have said this isn't possible.
What you could do is programatically launch Safari from within your app and give it the URL of a page to load which is your page.
When your page is loaded it has some sort of animation and shows the user where the add to home screen button is and tell them to press it after clicking a link which is displayed in your web page. When the users click on the link it takes them to whatever page it is that you would like saved to the desktop, and you hope they follow your instructions.
If you register your app to handle a proprietary url scheme the users can get back to your app from within Safari by clicking on a link using your app's url scheme.
The web pages that you seed Safari with must however be remote pages, you cannot give Safari a page in your app's bundle or that your app has downloaded as Safari cannot read pages from your app's sandbox.
The short answer is no, you can't. Apple does not let you.
Here's a similar question which may help you come up with other possibilities:
Javascript for "Add to Home Screen" on iPhone?
If I had to think of a work around off the top of my head, you could create an javascript pop-up which instructs them how to. It could say something like tap this button to go to mobile safari then tap action -> add to home screen.
Execute the Javascript with UIWebView's method:
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
Hope this helps.
You can use UIActivityViewController with your url as the activity items
NSArray *activityItems = #[title, url];
And then you can exclude the activities that you don't want. I think it´s the only way for now.

Objective-C iPhone - Open Multiple URLs in Safari

I know how to open an URL from app in Safari using [[UIApplication sharedApplication] openURL:url];. This is great, but what I need to do is that I have multiple URLs and I want to start Safari with more tabs opened with those URLs.
I tried calling openURL multiple times but it just opens Safari once and other urls are ignored.
Is there any way of opening multiple tabs in Safari from my app?
Thanks.
When you call UIApplication openURL:, your application will be put in the background and will no longer be allowed to perform these operations. I do not think that opening multiple tabs is something that iOS Safari supports. Tabs are probably implemented in a more memory-efficient way (i.e. loading only the tab you see, saving a picture of the others until you switch to them). It would help knowing why you want to open multiple tabs.
Some suggestions:
Open a link to a "launcher" page, which takes you to the page you want
Use UIWebView and implement the tabs yourself
Create a menu of some sorts in your app, opening only one page at once

Disable the Alert Box in UIWebView

I am loading an External web page in the UIWebView. When the web page loads, there is an Alert Box ( with OK and Cancel buttons) with some Suggestion/ Info about the web page. I want to block this Alert Box when the web page loads in the UIWebView component in my iphone app. How can I implement in my code?
Thanks for your reply. I am not in-charge for the external web page(but i could ask the concern web page owner to do the changes with respect to following requirement). The requirement is that the Alert Box (used to tell about my iphone app) could be shown when we view the web page in iPhone Safari browswer , but not in UIWebView in which I am using the same web page) of my iphone app. I am using the same web page url both in iPhone Safari and in my iPhone app with UIWebView. So requirement is show the Alert box when we view the web page in iPHone Safari and don't show the Alert box when we view the same web page in iPhone app (within in UIWebView). Hope I have clearly explained my requirement. Please give any solution for this.
using stringByEvaluatingJavaScriptFromString: method you can change anything you want on the page with any javascript you provide, so you can overload or replace the alert function to do what you want
Are you the one 'in charge' of this external web page? If that's the case, you could do something like this:
Make the UIWebView load externalpage.html?noalert instead of externalpage.html.
Then on externalpage.html you can check whether this query string variable exists, and only show the alert() if it doesn't:
if(!document.location.search || document.location.search.substring(1) != 'noalert') {
alert('Boo!');
}
duplicate: UIWebView: Can I disable the javascript alert() inside any web page?
Since a UIWebView translates all Javascript alerts into native UIAlertViews it is fairly simple to block it on the native end. Looking into UIAlertView.h there is only one public method for showing an alert which is conveniently called: - (void)show;.
#interface UIAlertView (Blocker)
#end
#import "UIAlertView+Blocker.h"
#implementation UIAlertView (Blocker)
- (void)show {
return;
}
#end
You can find the answer here: https://stackoverflow.com/a/21698251/2377378

Launching Safari in-app?

Is it possible to Launch Safari without having the app close? Just like the in-app email compose window.
I'm aware of how to display a webpage in UIWebView. I'd like to use a full web browser, i.e. Safari.
You can use a UIWebView to display web content in your app.
You can create a UIWebView with the URL to display. It will follow any links that the user touches, but that won't give you the address bar, search, navigation buttons, bookmarks or the page (tab) control. Those you'll have to add yourself, but odds are you don't want all of that. (Do you really need Google searches in your app?)
Creating a controller to manage a UIWebView and as much or as little navigation as you need is pretty easy. With a little planning, your custom controller class will also a good thing to keep in your library for the next app.
No you can not make use of the full Safari from within your own application. Your application must terminate for Safari to open.
In iPhone OS 2.0 you also had to terminate in order to send e-mails, so some chance exists that Apple couls open up Safari in the same way for iPhone OS 4.0. Make sure to request it at http://bugreport.apple.com if you are eager.
The second best option currently available is to roll your own "Browser view controller" using UIWebView. Let it have back, forward, stop/reload buttons, and an extra button for opening in Safari if the user is not content. This is how many of the greatest apps our there, like Tweetie, does it.

My links in a WebView fire custom methods, but the iPhone doesn't respond like simulator

I have a WebView that loads a simple html page in my resources folder. The page contains links. When the user touches on a link to a Web site, the iPhone will close my app and open Safari. Since the user may not want to leave my app right now, I use:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
to trap the link touch and show him an alert box, asking him to confirm that he wants to leave my app and go to Safari right now.
Same for an email link, which would close my app and open the user's email program.
However, if I want to similarly trap when the user touches a "tel:402-555-1212" phone call link, it works on the simulator, but on the real device I just get a simple alert box that says "call 4025551212": it clearly is ignoring my custom code for the telephone number link.
Is that a bug? It happens the same way (success on simulator, not on iphone) whether or not I select "detects phone numbers" for the webview in IB. How do I get this to work on the iPhone?
2) And very closely related question: if I click to allow the phone call to happen, when the phone call ends my app returns to its opening page, closing all other views. Is this normal function? There was no memory warning. Did the phone close and then re-open my app? It doesn't do that if click on a link and go to safari: when I close safari my app doesn't open again.
Thanks in advance for any insight.
--Steve
maybe you should set the detectsPhoneNumbers property to NO