I'm trying to find a way to get a UIWebView to cache an entire web page while one wifi and view it from the cache while connected to 3G, but then reload and recache while on WiFi again.
Are the any APIs or anything to do this?
Cheers
regardless of 3G or WIFI you can use NSURLRequestReturnCacheDataElseLoad with your NSURLRequest which caches webpage otherwise load.. you could create a check for your 3G status
here is the usage of NSURLRequestReturnCacheDataElseLoad
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 10.0];
and load your data returned from webpage by using loadHTMLString in UIWebView
Related
I am trying to load a URL using webView in Objective C. I tried "https://www.tidecleaners.com/cincinati-pricing" and it works fine for all devices. But not working only in iPhone X.
Here its my code,
NSString *fullURL = #"https://www.tidecleaners.com/cincinati-pricing";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
self.WebView_O.delegate = self;
[self.WebView_O loadRequest:requestObj];
According to the Apple docs, error -1007 means NSURLErrorHTTPTooManyRedirects, i.e. the HTTP connection failed due to too many redirects.
Maybe the WebView implementation of the iOS version on your iPhone X is less tolerant to redirects than on older devices. However, this seems to be a server issue, and you probably won't be able to do much about it on the client side.
However, to get more information about the issue, you can enable a more verbose network log:
Open your scheme in Xcode.
Select Runon the left, and the Arguments tab on the right.
Add CFNETWORK_DIAGNOSTICS to the environment variables, and add 1, 2, or 3 as a value (depending on the verbosity you want).
Hopefully, the logs will then tell you a bit more about the error.
My question is same as this question, but don't get a proper answer.
If I am connected to wifi, but internet is not available/gone it should be notify. Alslo tested using Apple Reachability demo but still its not working.
Steps to reproduce:
1) connect iPhone using tethering on another device.
2) run the apple rechability demo.
3) turn off the cellular data on another device on wich iPhone is connected.
You can simply call the below code and then call NSURLConnection delegate methods. This way even if wifi is connected and internet not available it can be detected.
NSMutableURLRequest *headerRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com"] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0];
headerRequest.HTTPMethod = #"HEAD";
self.headerConnection = [[NSURLConnection alloc] initWithRequest:headerRequest delegate:self];
I am loading a yelp URL into a UIWebView and want to display the mobile website instead of automatically opening Yelp App. Behavior is as expected in my simulator, but goes to yelp on my phone since I have the yelp app installed.
Below is my code to load the URL:
NSString *fullURL = #"http://yelp.com/search?find_desc=coffee&find_loc=union+square";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_yelpView loadRequest:requestObj];
It can be because the yelp web page could ask about the redirect with some custom URL scheme which then is recognized by Yelp app.
You should debug which requests your web view performs during the loading of Yelp web page.
try to set a delegate to your web view and check which requests it performs with this delegate callback:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
I am developing a content reading app in which some data is displayed in a tale view and respective detail views.
Now I have already completed the app but there is a small bug.
I am using AFNetworking library for online data load and offline caching.
I have defined caching policy as described by following code.
Reachability *reach = [Reachability reachabilityWithHostname:#"google.com"];
if ([reach isReachable])
{
// Reachable
request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60.0];
}
else
{
request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataDontLoad
timeoutInterval:60.0];
}
But I am having a small problem that if I load some data online and then turn off the internet connection and close the app.
And afterwords if I restart the app again in offline mode, the cached data should load but it is not happening.
I also have tried changing the caching policies as defined in the following link:
http://blog.originate.com/blog/2014/02/20/afimagecache-vs-nsurlcache/
app deployment target : iOS 6.0
devices : universal
xcode version : 6.1
AFNetworking lib version : 2.0
Any suggestion is appreciated, thanks in advanced
I am developing a content reading app in which some data is displayed in a tale view and respective detail views.
I have already completed the app but there is a small bug.
I am using AFNetworking library for online data load and offline caching.
I have defined caching policy as described by following code:
Reachability *reach = [Reachability reachabilityWithHostname:#"google.com"];
if ([reach isReachable]) {
// Reachable
request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60.0];
}
else{
request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataDontLoad
timeoutInterval:60.0];
}
But, I am having a small problem that if I load some data online and then turn off the internet connection and close the app, and afterwords if I restart the app again in offline mode, the cached data should load but it is not happening.
I also have tried changing the caching policies as defined in this link.
app deployment target : iOS 6.0
devices : universal
xcode version : 6.1
AFNetworking lib version : 2.0
Replace all of the code you posted and just set the request cache policy to NSURLRequestUseProtocolCachePolicy.
As it stands, you're currently making a synchronous reachability query on every request. Either that or worse—it's returning immediately, but always returning before a real reachability state can be determined.