Facebook comment part keep loading on UIWebView - iphone

Facebook comment part of webview keep loading and it never finish on device.
But, it works just fine on simulator.
Does somebody have an idea to fix this? Thanks in advance!
This is the code to add UIWebview on UIViewController.
NSString *address = #"http://techcrunch.com/2012/03/10/entrepreneurs-are-difficult-at-best-and-abrasive-at-worst-get-over-it/?grcc=33333Z98";
//make webview frame
webView_ = [[UIWebView alloc] init];
webView_.delegate = self;
webView_.frame = self.view.bounds;
webView_.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
webView_.scalesPageToFit = YES;
[self.view addSubview:webView_];
//load page on webview
NSURL *myURL = [NSURL URLWithString:address];
NSURLRequest *myURLReq = [NSURLRequest requestWithURL:myURL];
[webView_ loadRequest:myURLReq];
This is the error message on - (void)webView:(UIWebView *)webView didFailLoadWithError:
Error Domain=NSURLErrorDomain Code=-999 "The operation couldn't be completed. (NSURLErrorDomain error -999.)"
Update
I tested it with a clean uiwebview, since the previous build had Sharekit plugin,
but the error still exist with a new build. Also, this link is related,
First dialog after authenticating fails immediately and closes dialog

FYI, I opened a bug recently on this. Facebook hasn't really responded and oddly classified it as a "wishlist" item:
https://developers.facebook.com/bugs/373249496041875?browse=search_4fa8cf425c5aa8d66140047

Related

How to present webpage just like email composer with in the app

I have a table view with list of we site addresses.
I have implemented to open website with url existing in cell Text, by clicking on a respective cell
as follows:
NSURL *websiteURL = [NSURL URLWithString:cell.textLabel.text];
[[UIApplication sharedApplication] openURL:websiteURL];
assume http://mywebsite.com" is the text on my cell
*
NSURL *websiteURL = [NSURL URLWithString:#"http://mywebsite.com"];
[[UIApplication sharedApplication] openURL:websiteURL];
*
it opens the correct web page but it quits my active application, and opens safari app
I was unable to came bak to my application again with out quit the webpage.
So I need to present webpage with in the app just like MF Emil composer.
As all we know MF Emil composer opens mail page and return back to active application, when click on cancel button.
I need same like MF Emil composer present model.
Do like this,
-> Create the new view controller.
-> Add webview as a subview of the view controller.
Eg:
UIWebView *webView = [[UIWebView alloc] initWithFrame: CGRectMake(0.0, 0.0, 1.0, 1.0)];
webView.delegate = self;
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: [NSURL URLWithString: #"http://mywebsite.com"] cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: myTimeoutValue];
[self.webView loadRequest: request];
->then Present the new view controller from where you want to call the url.

Youtube video in UIWebview not working

Using this code to play YouTube video in UIWebView
- (void)embedYouTube {
UIWebView *webView = [[[UIWebView alloc] initWithFrame:self.view.bounds] autorelease];
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
// iframe
videoHTML = [NSString stringWithFormat:#"\
<html>\
<head>\
<style type=\"text/css\">\
iframe {position:absolute; top:50%%; margin-top:-130px;}\
body {background-color:#000; margin:0;}\
</style>\
</head>\
<body>\
<iframe width=\"560%%\" height=\"315px\" src=\"%#\"http://www.youtube.com/embed/j9CukQje2qw\" frameborder=\"0\" allowfullscreen></iframe>\
</body>\
</html>", videoURL];
[videoView loadHTMLString:videoHTML baseURL:nil];
}
When i click on this LaunchVideo UIButton all it shows black screen on iOS device
-(void)LaunchVideo:(id)sender
{
self.videoURL = #"http://www.youtube.com/embed/j9CukQje2qw";
WebViewController *webViewController = [[[WebViewController alloc] initWithNibName:nil bundle:nil] autorelease];
webViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
webViewController.videoURL = self.videoURL;
[self presentModalViewController:webViewController animated:YES];
}
If anyone can point out what i m missing or doing wrong in this code. Why youtube video is not showing. Not using interface builder doing programmtically. Got this project code from web. Tried this project code on ios device it works fine for that project but when applied its code in my project then it is not working. Only difference that his projectcode from web uses interface builder and i am doing it programmtically.I dont get it.
Please help what is wrong with this code.
Thanks for help.
Here is another way to load the youtube video into your app. First, put a UIWebView into your interface and size it to how big you want the video should show (there will be a button to make it full screen), then make an IBOutlet to it, so you can change its properties of hidden (to make it pop up and go away) Here is some code. In the code there is a method used called webviewshow, this calls a simple method that basically just says
webview.hidden = NO;
webviewbutton.hidden = NO;
Then there is a button that also pops up that makes the web view go away when tapped. Here is the code to load the youtube video into the web view
// Create your query ...
NSString* searchQuery = [NSString stringWithFormat:#"http://www.youtube.com/embed/j9CukQje2qw];
// Be careful to always URL encode things like spaces and other symbols that aren't URL friendly
searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
// Now create the URL string ...
NSString* urlString = searchQuery;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[webView loadRequest:request]; currentTimer= [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(webviewshow) userInfo:nil repeats:NO];;
It waits 2 seconds (usual wait time for most connections) until the web view is shown, so the page is loaded and the user does not have to watch it load.
Then when you want to make the video go away, make a method to close the web view like so
- (void) makewebviewGoAway {webview.hidden = YES; webviewbutton.hidden = YES;}
Hopefully, that was helpful. IF you need further help or explanation, just comment off of this.

Admob not working at AppStore

I have implemented Ad mobs in my iPhone app. The app is receiving ads in simulator and device while debugging. but when i upload it to app store it is not receiving any.
I'm using this piece of code
-(void)showAds{
self.adBanner = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin]autorelease];
self.adBanner.adUnitID = #"abcdef1234567890.";
self.adBanner.delegate = self;
[self.adBanner setRootViewController:self];
[self.view addSubview:self.adBanner];
GADRequest *request = [GADRequest request];
[self.adBanner loadRequest:request];
}
I dont know what mistake m I making ?? any help ?
It looks like you have a period at the end of your adUnitID. Are you sure that should be there?

call async asihttp in different view controller

I try to use UINavigationController to navigate from one view controller to another.
In both viewController , the viewWillAppear
I call asihttp using async mode.
but this always cause the app crash.
I try to use the function of asihttp '[request cancel]'
in the wiewWillDisaaoear, but the error still exist
Welcome any comment
I used Following code in my app and i also did forth-back using UINavigationController but it didn't give me any crash. I suggest you to show your code here so it will help you a lot to find out your resolution.
Here, I am showing you my code..see if it will help you.
-(void)viewWillAppear:(BOOL)animated
{
[self willAnimateRotationToInterfaceOrientation:self.interfaceOrientation duration:1];
NSURL *urlf = [NSURL URLWithString:#"Your url"];
ASIHTTPRequest *requestdiff = [[ASIHTTPRequest alloc]initWithURL:urlf];
[requestdiff setDelegate:self];
[requestdiff release];
[self willAnimateRotationToInterfaceOrientation:self.interfaceOrientation duration:1];
}

Opening popup links in UIWebView, possible?

I have a UIWebView which I'm using as an embedded browser within my app.
I've noticed that links in webpages that open new windows are ignored without any call into my code.
I've tried breakpointing on
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
and then selecting a link that would open a popup window, and the breakpoint is never hit.
Is there anything I can do to intercept that selection of the popup link and get the URL and just load it normally?
I'm not interested in displaying a popup window in the app itself, I just want the URL of whatever is going to be loaded in the popup window to load in the main webview itself.
Is this possible?
Thanks!
I ran into this as well, and HTML rewriting was the best solution I could come up with. The biggest issue that I ran into with that approach is that the web browser is interactive for up to a couple of seconds until the webViewDidFinishLoad: method is called, so the links seem to be broken for a few seconds until they're rewritten.
There's three areas that I rewrote: links, form posts, and calls to window.open().
I used a similar approach to the first code snipped in Jasarian's answer to overwrite the target for links and forms by iterating over tags and forms. To override window.open, I used code similar to the following:
var oldWindowOpen = window.open;
window.open = function(url, sName, sFeatures, bReplace) {
oldWindowOpen(url, '_self');
};
So after a small amount of research, it's clear that the UIWebView class purposefully ignores links that will open in a new window (either by using the 'target' element on the a tag or using javascript in the onClick event).
The only solutions I have found are to manipulate the html of a page using javascript. While this works for some cases, it's not bulletproof. Here are some examples:
links = document.getElementsByTagName('a');
for (i=0; i<links.length; i++)
{
links[i].target='_self';
}
This will change all links that use the 'target' element to point at _self - instead of _blank or _new. This will probably work across the board and not present any problems.
The other snippet I found followed the same idea, but with the onClick event:
links = document.getElementsByTagName('a');
for (i=0; i<links.length; i++)
{
links[i].onclick='';
}
This one is just plain nasty. It'll only work if the link tag has it's href element correctly set, and only if the onclick event is used to open the new window (using window.open() or something similar). The reasons why it is nasty shouldn't need explaining, but one example would be if the onClick is used for anything other than opening a window - which is a very common case.
I guess one could go further with this and start doing some string matching with the onClick method, and check for window.open(), but again, this is really far from ideal.
Here's how I get twitter links to work (i.e. link to pages that try to open with new windows):
-(BOOL)webView:(UIWebView *)mainWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
//Allows for twitter links
[self.mainWebView loadRequest:request];
return NO;
}
return YES;
}
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
theConfiguration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
webView1 = [[WKWebView alloc] initWithFrame:self.webView.frame configuration:theConfiguration];
webView1.navigationDelegate = self;
webView1.UIDelegate = self;
[self.view addSubview:webView1];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
NSString *htmlString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(#"htmlString: %#", htmlString);
[webView1 loadHTMLString:htmlString baseURL:[NSURL URLWithString:#"your url"];
}];
[dataTask resume];