Bear with me, I am very much new. XCode macOS Objective-C, I want to create a very simple app version check. This is outside of the apple app store ecosystem, so I do not mean checking version against the app store - I was thinking something even easier.
I simply want to have a defined value in my app, maybe an string or bool. I want my app to check this value against a value in a text file on a web server (something like) http://example.com/check/version.txt - Then, just a simple if/then check to notify if there is a new version.
I have seen some examples like:
NSString *path = [[NSBundle mainBundle] pathForResource:@"File" ofType:@"txt"];
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
And a lot of swift examples, but not from reading from the web in obj-c, just local.
Update:
I have tried this, but NSLOG always says running current version even if text file on server has the text in it: 11
And the code is comparing 11 to 10 so I assume should say update available?
- (void)windowDidLoad {
[super windowDidLoad];
NSURL *url = [NSURL URLWithString:@"https://example.com/versioncheck.txt"];
NSError* error;
NSString *serverversion = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];
NSString *localversion = @"10";
if(localversion = serverversion) {
NSLog(@"Running Current Version of Software");
} else {
NSLog(@"An Update is Available");
}
}