比较两个NSData

时间:2014-01-17 16:19:12

标签: objective-c nsdata

在我的项目中,我需要比较一个网站是否从现在改为30分钟,所以经过研究,我到达了这个:

- (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");
    }
}

问题在于,每当我得到“改变了一些东西”。为了测试我创建了一个博客来发布一些东西来改变它的HTML。

0 个答案:

没有答案