Display Authentication dialog in WebView - iphone

I have a webView which will display the https url. I am trying to open a https url which will provide a authentication dialog like this http://members.easynews.com/ . In Mac, it is opening as dialog box, even in iPhone safari browser it is displaying as dialog box. But in webview , it is not displaying the dialog box. How to display that dialog box in webView ??

I think it is because of some firewall settings by that link authorities.thats why they are asking for authorisation.i am trying to load that in my webview i wont get anything .it is not loading
go for this
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://members.easynews.com"]];
instead of loading it in to webview
or else are loading i this manner
- (void)viewDidLoad {
[super viewDidLoad];
webView.delegate = self;
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView setScalesPageToFit:YES];
[self.webView loadRequest:request];
}
add this new method in your class
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog("Error : %#",error);
}
I hope you have connected webView object with its outlet in Interface builder?

Related

how to open the web sent by rich push notification outside the apps

now im doing the push notification on iphone by using xcode. When i sending the message/notification to the user that contain URL for the user to open it, so the user will receive the notification and message that contained URL and open it in the webview in the apps. Is it possible to open that URL outside the apps by chrome or safari?
what are coding need to modified in order to connect that clicked URL to open the browser outside the apps?
this is the coding that make the webview is open when clicked on the link.
- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
if ([[url scheme] isEqualToString:#"ua"]) {
if ((navigationType == UIWebViewNavigationTypeLinkClicked) || (navigationType == UIWebViewNavigationTypeOther)) {
[UAInboxMessage performJSDelegate:wv url:url];
return NO;
}
With the use of this code you can open a link to safari browser just pass your link instead of provided
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.daledietrich.com"]];
you can make static method.
+ (void)openBrowser:(NSString *)url {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
and then call it anywhere
[className openBrowser:#"http://rajneesh071.blogspot.in/2013/03/ios-sdk-open-other-app-from-our-app.html"];
If you have rich text in your url then you can make encoding with it.
NSError *err = nil;
NSString *resultStr=[[NSString alloc] initWithContentsOfFile:url encoding:NSUTF8StringEncoding error:&err];

Instagram IPHONE HOOKS - the app isnt opening

Im trying to open Instagram from my own application, trying to get a list of photos tagged with "brazil". But Instagram isnt opening. Please see code snippet here.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//Load URL
NSURL *instagramURL = [NSURL URLWithString:#"instagram://tag?name=brazil"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
}
NSURLRequest *instagramRequest = [NSURLRequest requestWithURL:instagramURL];
[instagramWebView loadRequest:instagramRequest];
}
Thanks in advance!

Best way to have article text with links on iPhone?

I am making an iPhone app that has a bunch of "articles" with certain words that I want to link to other "articles". I need to display the articles in UITableViewCells.
If there is a way to do this without a web view, that's great.
If I need to use a web view, should I just make <a href> style links? How can I have it jump to the article without creating a bunch of actual html pages, just have it let my program know that they clicked on that link and then the program goes and finds the appropriate article from a plist or something?
I've create a test demo using UIWebView and it works fine.
Create two HTML files:home.html and first.html.
// home.html
Home page. first
// first.html
First page. home
//viewDidLoad
self.webView.delegate = self;
NSString *htmlFilePathString = [[NSBundle mainBundle] pathForResource:#"home" ofType:#"html"];
NSURL *htmlFileURL = [[NSURL alloc] initFileURLWithPath:htmlFilePathString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:htmlFileURL];
[self.webView loadRequest:request];
// webView's delegate:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES;
}

UIWebView links opening in Safari

I want to open an iTunes link in my webView, but when the webView launches the page, it redirects to the Safari browser. There, the url is getting opened, but I want it to open in my webView.
- (void)viewDidLoad {
NSString *urlAddress = #"http://itunes.apple.com/us/app/foodcheck-traffic-light-nutrition/id386368933?mt=8";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
[super viewDidLoad];
}
Please suggest a way to sort out this problem.
You may want to try logging the load requests when you run the app. It may be that apple is automatically changing http:// to itms-apps or http://phobos or something along these lines. If so, then you can block the load when it's call using something like this:
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType;
{
NSURL *loadURL = [[request URL] retain];
NSLog(#"%#",loadURL);
if([[loadURL absoluteString] hasPrefix:#"http://"])
{
[loadURL release];
return TRUE;
}
[loadURL release];
return FALSE;
}
Good luck. I'm curious to know what finally works.
A note from the Apple reference documents- Q: How do I launch the App Store from my iPhone application? Also, how do I link to my application on the store?
Note: If you have iTunes links inside
a UIWebView, you can use this
technique after intercepting the links
with the -[UIWebViewDelegate webView:shouldStartLoadWithRequest:navigationType:]
delegate method.
Not sure if you ever got it working, but this works well for me:
NSString *responseString = [NSString stringWithContentsOfURL:myURL];
[self.webView loadHTMLString:responseString baseURL: nil)];

WebView Twitter slow loading

I have a WebView loading a Twitter mobile user's wall:
NSString *urlAddress = [NSString stringWithString:#"http://mobile.twitter.com/gatrecords"];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
When web is loaded it freezes for 10- 15 secs then I can navigate normally. On the iPhone's Safary Browser happens the same. That behavior only happens with loading mobile.twitter plus a user's wall.
On the simulator all is ok.
Any suggostions on what could be wrong ?
I found a workaround for the freezeing. Apparently WebView freezed bacause tries to execute twitter's javascript for 10 seconds, after that time the system will stop trying and the WebView will be scrollable. So I stopLoading only when twitter's web is being loaded:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *twitter = [NSString stringWithFormat:#"%#", [[myWebView request] URL]];
if ([twitter isEqualToString:#"http://mobile.twitter.com/gatrecords"]) {
[myWebView stopLoading];
}
}
Then I get an error alert after the 10 seconds regarding javascript did not load correctly, I fix that as follows:
- (void)webViewDidStartLoad:(UIWebView *)webView {
[myWebView stringByEvaluatingJavaScriptFromString:#"window.alert=null;"];
}