Alertview in webapp - This link opens in a new window http://wwww - iphone

I am currently developing a little webapp with iWebKit I joined a UIWebView.
And I have a little problem, I would like the external links before opening in Safari displays a alertview "This link opens in a new window".
AlertView With:
Title: External Links (No URL)
Message: Would you open this link external mobile safari ?
Button: OK Cancel
How to do that just please?
Thank you very much for your help;)

In the object that is designated as the UIWebViewDelegate add the following:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return [self verifyUserWantsToNavigateAwayFromApp];
}
The method that you'll have to write verifyUserWantsToNavigateAwayFromApp. Is where you should pop up the alerts and wait for the UIAlertViewDelegate to get the user's answer. Return YES to navigate, NO to cancel.

Related

how to perform an action in iphone application on click in webview

I need to implement a functionality such that I have there is a login screen which sends an http request packet, gets a json response(a boolean and a routing link) and opens a webview. I have done this successfully. But further what I need to do is that when I click sign out in the webview, I should get back to the native login screen.How can I achieve that?
Check this call back method
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
}
You get this call back when you click link in webview.

Appying our own action to Facebook Login button & closing all Facebook screens.

I am using fbconnect api in my project. When the login dialog gets opened where we entered our credentials, when we click on login button then it is redirected to the publish page how can we close the login page or post to wall page or view.
My problem is I don't want to open any page belongs to face book API, instead i want to open my own page. Any one can help or suggest.
In FBConnect there is a class FBDialog which is using UIWebView for Facebook login authentication. The FBDialog class implements the UIWebView delegate protocol. So if you want to perform your action on login button press then you can handle it in FBDialog.m in UIWebView delegate -
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
which will call when you press on login button.
You can open your own view depending upon your requirement. After successful Login following delegate method is called
- (void)session:(FBSession*)session didLogin:(FBUID)uid
{
self.usession=session;
[self postToWall];
}
Here i am calling my own custom method postToWall. Where i create publish dialog as below:
-(void)postToWall
{
FBStreamDialog *dialog=[[[FBStreamDialog alloc]init]autorelease];
dialog.userMessagePrompt=#"Enter Message to Post";
[dialog show];
}
You can create your own view in postToWall in place of FBStreamDialog OR if you want to load request of another page then load that URL in Web View of FBStreamDialog.m class.

Call action from UIWebView with JavaScript

I am trying to build a simple app that uploads images to my site. I am using this tutorial:
http://www.youtube.com/watch?v=aQXaJO36I7Y
What I want to do instead of using a button from the app's interface I wan to use a button within a website in a webview. So I want a button to call the opening of the photo album to select a image to upload.
Basically I need a way for a javascript function to call a action in the app itself.
How can I do this?
You could just use a custom link, which you can then detect in the UIWebViewDelegate method.
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSString *rawURL = [[request URL] absoluteString];
if([rawURL isEqualToString:#"callImageLib://"]) {
[self methodeForImageLib];
}
return NO;
}
return YES;
}
If i understand it correctly you need to communicate iPHone Web application to call native iPhone application and visa versa. please check the following links.
http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript
http://iphoneincubator.com/blog/windows-views/how-to-inject-javascript-functions-into-a-uiwebview
hope these 2 link help to solve your issue.

Prevent app exit from UIWebView link

I have a UIWebView in my app which shows the clients webpage, however I would like to retain the user within the app if they choose to browse the webpage.
Can I prevent it breaking out to Safari when a link is clicked?
Try implementing UIWebViewDelegate's:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
HTH.

Have iPhone webpage URL open in specific view in application

I have an application that acts like an internet browser for one webpage. If the webpage is in one view, can I have it act so when a specific URL is selected that it will open the URL in a different view?
Yes. In your webViewController, implement this
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
Check to see if it's the url you're interested in, then create and push a view that displays the web page.
Oh, and return NO to prevent the load from occurring in this view.