-
Notifications
You must be signed in to change notification settings - Fork 151
/
CheckUpdatesHelper.m
65 lines (46 loc) · 1.65 KB
/
CheckUpdatesHelper.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// CheckUpdatesHelper.m
// Turbo Boost Switcher Pro
//
// Created by Rubén García Pérez on 18/09/16.
// Copyright © 2016 Rubén García Pérez. All rights reserved.
//
#import "CheckUpdatesHelper.h"
#define CURRENT_VERSION 291
@implementation CheckUpdatesHelper {
}
// Check for updates
- (void) checkUpdatesWithDelegate:(id <CheckUpdatesHelperDelegate>) _delegate {
// Save the delegate
delegate = _delegate;
// Download the version descriptor
NSURL *url = [NSURL URLWithString:@"https://api.rugarciap.com/tbs_version_free"];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
// Error downloading file
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[delegate errorCheckingUpdate];
}
// Start the download
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
contents = [[NSMutableData alloc]init];
}
// Download data
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[contents appendData:data];
}
// Data download finished
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *versionContent = [[NSString alloc] initWithData:contents encoding:NSUTF8StringEncoding];
int latestVersion = [versionContent intValue];
if (latestVersion > CURRENT_VERSION) {
[delegate updateAvailable];
} else {
[delegate updateNotAvailable];
}
}
@end