开发者

Help making auto updater

I'm making a app that automatically updates itself. Fist of all I want to check if the file exists at a d开发者_开发知识库omain, I've never done something like it before so I've found a code and adapted it to fit in my project. The problem is that, I always get that the file exists.

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

}

Any ideas? By the way if someone also knows how to download the file, and install it replacing the old one, please help me out.


Your problem has been solved by Sparkle already. It's widely used, well tested and trusted by users so why reinvent that wheel?

Also, it's open source and hosted on github so you can have a look at how it's implemented.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜