2
我正在制作自动更新自己的应用程序。我想要检查文件是否存在于域中,我之前从未做过这样的事情,因此我找到了一个代码并将其改编以适合我的项目。问题是,我总是得到该文件存在。帮助制作自动更新程序
-(BOOL) webFileExists {
int fcurVer = [[self getCurrentVersion] intValue];
fcurVer++;
NSLog(@"%i", fcurVer);
NSString *url = [NSString stringWithFormat:@"http://www.site.org/folder/version/%i.dmg", fcurVer];
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0];
NSHTTPURLResponse* response = nil;
NSError* error = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"statusCode = %i", [response statusCode]);
if ([response statusCode] == 404) {
return NO;
}
else {
return YES;
}
}
任何想法?顺便说一下,如果有人也知道如何下载文件,并安装它替换旧文件,请帮助我。