0

In my project I need to compare if a website changed from now to 30 minutes later, so after a research, I arrived in this:

- (IBAction)saveHTML:(id)sender{
    // Determile cache file path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];

    self.Surl= [self.meuWebView stringByEvaluatingJavaScriptFromString:@"window.location.href"];
    NSLog(@"URL: %@",self.Surl);
    // Download and write to file
    NSURL *url = [NSURL URLWithString:self.Surl];
    NSData *urlData = [NSData dataWithContentsOfURL:url];
    [urlData writeToFile:filePath atomically:YES];

    // Load file in UIWebView
    //   [web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];

    self.oldURL = urlData;
    self.timerURLNew = [NSTimer scheduledTimerWithTimeInterval:5 target:self     selector:@selector(saveHTMLNew:) userInfo:[NSNumber numberWithBool:YES] repeats:NO];
}

-(void)saveHTMLNew:(id)sender{
    // Determile cache file path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];

    self.Surl= [self.meuWebView stringByEvaluatingJavaScriptFromString:@"window.location.href"];
    NSLog(@"%@",self.Surl);

    NSURL *url = [NSURL URLWithString:self.Surl];
    NSData *urlData = [NSData dataWithContentsOfURL:url];
    [urlData writeToFile:filePath atomically:YES];
    self.newURL = urlData;

    if (![self.oldURL isEqualToData:self.newURL]) {
        NSLog(@"Something changed");
    }
    else {
        NSLog(@"Nothing changed");
    }
}

The problem is that everytime I get "Something Changed". For testing I create a blog to post something to change its HTML.

Mike D
  • 4,938
  • 6
  • 43
  • 99
Lucas Farah
  • 1,022
  • 10
  • 24
  • 1
    Why don't you use the HTTP `Last-Modified` value (if your server supports it)? http://stackoverflow.com/questions/10856302/how-to-query-the-last-modification-date-of-a-file-via-http-on-the-iphone-using-n – trojanfoe Jan 17 '14 at 16:27
  • Use a comparison scheme that shows you WHAT has changed, and you'll be closer to figuring out your solution. – Hot Licks Jan 17 '14 at 16:35

0 Answers0