diff --git a/TravelKit.podspec b/TravelKit.podspec index 2ab1a44..fd2485b 100644 --- a/TravelKit.podspec +++ b/TravelKit.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |spec| spec.name = 'TravelKit' - spec.version = '2.0.2' + spec.version = '2.0.3' spec.license = 'MIT' spec.homepage = 'https://github.com/sygic-travel/apple-sdk' spec.authors = 'Tripomatic s.r.o.', 'Michal Zelinka' spec.summary = 'Travel SDK for travelling projects' - spec.source = { :http => 'https://github.com/sygic-travel/apple-sdk/releases/download/v2.0.2/TravelKit-2.0.2-iOS.zip' } + spec.source = { :http => 'https://github.com/sygic-travel/apple-sdk/releases/download/v2.0.3/TravelKit-2.0.3-iOS.zip' } spec.documentation_url = 'http://docs.sygictravelapi.com/apple-sdk/latest' spec.module_name = 'TravelKit' diff --git a/TravelKit.xcodeproj/project.pbxproj b/TravelKit.xcodeproj/project.pbxproj index c142553..9851d96 100644 --- a/TravelKit.xcodeproj/project.pbxproj +++ b/TravelKit.xcodeproj/project.pbxproj @@ -1252,8 +1252,8 @@ STRIP_INSTALLED_PRODUCT = NO; STRIP_SWIFT_SYMBOLS = NO; TARGETED_DEVICE_FAMILY = "1,2"; - TK_BUNDLE_BUILD = 237; - TK_BUNDLE_VERSION = 2.0.2; + TK_BUNDLE_BUILD = 238; + TK_BUNDLE_VERSION = 2.0.3; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1340,8 +1340,8 @@ RUN_CLANG_STATIC_ANALYZER = YES; SKIP_INSTALL = YES; TARGETED_DEVICE_FAMILY = "1,2"; - TK_BUNDLE_BUILD = 237; - TK_BUNDLE_VERSION = 2.0.2; + TK_BUNDLE_BUILD = 238; + TK_BUNDLE_VERSION = 2.0.3; TVOS_DEPLOYMENT_TARGET = 9.0; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; diff --git a/TravelKit/TKSessionManager.m b/TravelKit/TKSessionManager.m index 5f903b0..61c60ec 100644 --- a/TravelKit/TKSessionManager.m +++ b/TravelKit/TKSessionManager.m @@ -6,6 +6,8 @@ // Copyright © 2017 Tripomatic. All rights reserved. // +#import + #import "TKSessionManager+Private.h" #import "TKDatabaseManager+Private.h" #import "TKEventsManager+Private.h" @@ -49,13 +51,13 @@ - (instancetype)init { __weak typeof(self) weakSelf = self; + _database = [TKDatabaseManager sharedManager]; + _events = [TKEventsManager sharedManager]; + _events.sessionExpirationHandler = ^{ [weakSelf refreshSession]; }; - _database = [TKDatabaseManager sharedManager]; - _events = [TKEventsManager sharedManager]; - NSString *suiteName = @"com.tripomatic.travelkit"; NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier]; @@ -73,7 +75,9 @@ - (instancetype)init [self loadState]; - [self checkSession]; + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + [self checkSession]; + }]; } return self; @@ -182,6 +186,11 @@ - (void)checkSession - (void)refreshSession { + static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; + + if (pthread_mutex_trylock(&lock) != EXIT_SUCCESS) + return; + NSString *token = _session.refreshToken; if (!token) return; @@ -189,6 +198,7 @@ - (void)refreshSession [[TKSSOAPI sharedAPI] performSessionRefreshWithToken:token success:^(TKSession *session) { self.session = session; + pthread_mutex_unlock(&lock); } failure:^(TKAPIError *error) { @@ -196,6 +206,8 @@ - (void)refreshSession if (error.code / 100 == 4) self.session = nil; + pthread_mutex_unlock(&lock); + }]; }