I have three UIwebView added from story board when i load them i add activity indicator to show loading progress and when loading is finish. Delegate of DidFinishLoading called. But i see the white color on uiwebview. When i again load the UIwebview when white screen is visible then it shows the error "Operation couldn't be completed" but when loading of UIwebview is properly done and again i reload with new url. then it does not show any error.
Please somebody tell me.. Thanks in advance.
NSString* urlgmap=#"www.google.com"
NSURL *url_gmap = [NSURL URLWithString:urlgmap];
NSURLRequest *request_gmap = [NSURLRequest requestWithURL:url_gmap cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
[self.wrae_one loadRequest:request_gmap];
NSString* urlgrid=#"www.yahoo.com";
NSURL *url_grid = [NSURL URLWithString:urlgrid];
NSURLRequest *request_grid = [NSURLRequest requestWithURL:url_grid cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
[self.wrae_two loadRequest:request_grid];
NSString* urlSmap=#"www.facebook.com";
NSURL *url_smap = [NSURL URLWithString:urlSmap];
NSURLRequest *request_smap = [NSURLRequest requestWithURL:url_smap cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
Related
I have a UIWebView when using the NSURLRequest I’m setting cachePolicy: NSURLRequestReturnCacheDataElseLoad and also setting the pro cache memory size. When I open the application with internet, I open the screens and then deactivate the internet, the url I open is cached, until then everything is fine, but when closing the application and open again it loses all the cache. Can you persist the cache?
I have this:
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:500*1024*1024 diskCapacity:500*1024*1024 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
and loading from UIWebView:
NSURL *websiteURL = [NSURL URLWithString:URLString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:websiteURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60.0];
[self.mainWebView loadRequest:urlRequest];
I was able to resolve using a cache.manifest file on the server.
I create app to use UIWebview and show log to url if touch in content in UIWebview.
this is my code
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url1 =[NSURL URLWithString:#"MyWebSite"];
NSURLRequest *request1 = [NSURLRequest requestWithURL:url1];
[_webView1 loadRequest:request1];
NSURL *url2 =[NSURL URLWithString:#"MyWebsite2"];
NSURLRequest *request2 = [NSURLRequest requestWithURL:url2];
[_webView2 loadRequest:request2];//url menu 2
NSString *currentURL = [_webView1 stringByEvaluatingJavaScriptFromString:#"document.title"];
NSLog(#"%#",currentURL);
}
but I touch the content log is not print and change webview log is print (null)
sorry for my poor English.
You can not get title of a website before you receive data from the URL.
So
Set your webview delegate to self
Then in
- webViewDidFinishLoad: to get title
I have the one webview which load the this url
https://sketchfab.com/models/9fb581d7cb414e0fbec4108099a73619/embed.
After loading this url my web view start showing the memory warning and after some time it crash. I am using the arc in my application
Here is my code:
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSURL *sUrl = [NSURL URLWithString:[NSString stringWithFormat:#"%#/embed",m_Data.m_sModelUrl]];
NSMutableURLRequest *sRequest = [NSMutableURLRequest requestWithURL:sUrl];
[sRequest setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[m_webView loadRequest:sRequest];
}
Please help me out.
You can try autoreleasepool to solve memory warning.
#autoreleasepool
{
NSURL *sUrl = [NSURL URLWithString:[NSString stringWithFormat:#"%#/embed",m_Data.m_sModelUrl]];
NSMutableURLRequest *sRequest = [NSMutableURLRequest requestWithURL:sUrl];
[sRequest setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
}
[m_webView loadRequest:sRequest];
I have an UIWebview, when user taps a UIButton, my webview will be loaded. I have an 10 HTML files in bundle i want to show the first html in webview and when user **swipes** i want to show the next HTML file. When user wants to see previous HTML file, i want to allow swipe and see. I have used UISwipeGesture but how can i load the files one by one.. Please help me. I have loaded the files from bundle and i used
NSURLREQUEST *req = [NSURLREQUEST requestwithURL : myURL];
[webView loadRequest:req];
myURL is the path for first HTML. How can i do this for 10 HTML files using SWIPE
One simple thing you can do is rename your HTML files like 1.html, 2.html ..... 10.html
Declare an integar variable in your .h file initialize it in viewDidLoad and on detecting swipe right increment in that variable and use formatString to make correct url and reload the webview and on detecting swipe left decrement in that variable make correct url and reload the webview.
-(void)swipeRightDetected
{
if(fileNumber <= 10)
{
fileNumber++;
NSString *urlString = [NSString stringWithFormat:#"http://172.161.331.25/casa/admmathematic/Page00%d.html",fileNumber];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[webview loadRequest:request];
}
else
{
//No more files
}
}
-(void)swipeLeftDetected
{
if(fileNumber > 0)
{
fileNumber--;
NSString *urlString = [NSString stringWithFormat:#"http://172.161.331.25/casa/admmathematic/Page00%d.html",fileNumber];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[webview loadRequest:request];
}
else
{
//No more files
}
}
today, I encountered a problem with NSURLConnection. I want to download the contents of the URL http://api.wunderground.com/api/fs3a45dsa345/geolookup/q/34.532900,-122.345.json. If I simply paste the URL into Safari, I get the correct response. However, if I do the same thing with NSURLConnection, I get a "not found" response. Here's the code I'm using:
NSURL *requestURL = [[NSURL alloc] initWithString:#"same url as above"];
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:requestURL];
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest
delegate:self
startImmediately:YES];
What's the problem here?
Make sure you're escaping any special characters in the URL string by sending it a stringByAddingPercentEscapesUsingEncoding: message, for example:
NSString *s = [#"some url string" stringByAddingPercentEscapesUsingEncoding:NSUTFStringEncoding];
NSURL *requestURL = [NSURL URLWithString:s];
EDIT
It turns out the web service request is failing because the User-Agent header doesn't get set by default. To set it, use an instance of NSMutableURLRequest rather than NSURLRequest to create the request, as shown below:
NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:myURL];
[myRequest setValue:#"My App" forHTTPHeaderField:#"User-Agent"];
Where is the delegate code? For async NSURLConnection there needs to be a delegate method to receive the returned data. Other options include sendSynchronousRequest: or if it must be async wrapping sendSynchronousRequest in a GCD block.