I am using a URL Protocol to save the cache of UIWebView in order to call it back when an internet connection is not available.
My app is also using a link "https://custom-link-to-no-add-to-cache.php" that is used by Reachability to check for connection.
What I am trying to avoid is for the
context.save(&error)
to not save or cache the URL used by Reachability. I have been trying several way to do that such as:if (request.URL != "https://custom-link-to-no-add-to-cache.php") {...save code here... }
the saving function is:
func saveCachedResponse () {
println("Saving cached response")
let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context = delegate.managedObjectContext!
//
let cachedResponse = NSEntityDescription.insertNewObjectForEntityForName("CachedURLResponse", inManagedObjectContext: context) as! NSManagedObject
cachedResponse.setValue(self.mutableData, forKey: "data")
cachedResponse.setValue(self.request.URL!.absoluteString, forKey: "url")
cachedResponse.setValue(NSDate(), forKey: "timestamp")
cachedResponse.setValue(self.response.MIMEType, forKey: "mimeType")
cachedResponse.setValue(self.response.textEncodingName, forKey: "encoding")
// check if URL == "https://custom-link-to-no-add-to-cache.php"
var error: NSError?
let success = context.save(&error)
if !success {
println("Could not cache the response")
}
}
How can Avoid to cache the link used in Reachability?