1 ////////////////////////////////////////////////////////////////////////////
3 // Copyright 2014 Realm Inc.
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 ////////////////////////////////////////////////////////////////////////////
19 #import "RLMUpdateChecker.hpp"
24 #if TARGET_IPHONE_SIMULATOR && !defined(REALM_COCOA_VERSION)
25 #import "RLMVersion.h"
28 void RLMCheckForUpdates() {
29 #if TARGET_IPHONE_SIMULATOR
30 if (getenv("REALM_DISABLE_UPDATE_CHECKER") || RLMIsRunningInPlayground()) {
34 NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"alpha|beta|rc"
35 options:(NSRegularExpressionOptions)0
37 NSUInteger numberOfMatches = [regex numberOfMatchesInString:REALM_COCOA_VERSION
38 options:(NSMatchingOptions)0
39 range:NSMakeRange(0, REALM_COCOA_VERSION.length)];
41 if (numberOfMatches > 0) {
42 // pre-release version, skip update checking
46 auto handler = ^(NSData *data, NSURLResponse *response, NSError *error) {
47 if (error || ((NSHTTPURLResponse *)response).statusCode != 200) {
51 NSString *latestVersion = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
52 if (![REALM_COCOA_VERSION isEqualToString:latestVersion]) {
53 NSLog(@"Version %@ of Realm is now available: https://github.com/realm/realm-cocoa/blob/v%@/CHANGELOG.md", latestVersion, latestVersion);
57 NSString *url = [NSString stringWithFormat:@"https://static.realm.io/update/cocoa?%@", REALM_COCOA_VERSION];
58 [[NSURLSession.sharedSession dataTaskWithURL:[NSURL URLWithString:url] completionHandler:handler] resume];