From 8025f2d2983913461d06f7740c36d31a23a44bd0 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Mon, 27 Jul 2015 15:02:11 -0700 Subject: [PATCH 01/23] Removed limit for PubNub logs --- PubNub/Misc/Logger/PNLog.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PubNub/Misc/Logger/PNLog.m b/PubNub/Misc/Logger/PNLog.m index 790a80bc4..cb9be27f0 100644 --- a/PubNub/Misc/Logger/PNLog.m +++ b/PubNub/Misc/Logger/PNLog.m @@ -140,8 +140,8 @@ - (void)prepare { // Adding file logger for messages sent by PubNub client. self.fileLogger = [[DDFileLogger alloc] initWithLogFileManager:[PNLogFileManager new]]; self.fileLogger.maximumFileSize = (5 * 1024 * 1024); - self.fileLogger.logFileManager.maximumNumberOfLogFiles = 5; - self.fileLogger.logFileManager.logFilesDiskQuota = (50 * 1024 * 1024); + self.fileLogger.logFileManager.maximumNumberOfLogFiles = 0; + self.fileLogger.logFileManager.logFilesDiskQuota = 0; } + (void)enabled:(BOOL)isLoggingEnabled { From 273334ff93d3b7d9d1b8254f671f0145828b6fca Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Fri, 31 Jul 2015 12:59:43 -0700 Subject: [PATCH 02/23] Exposed some logging methods needed for verbose logging --- PubNub/Misc/Logger/PNLog.h | 3 +++ PubNub/Misc/Logger/PNLog.m | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/PubNub/Misc/Logger/PNLog.h b/PubNub/Misc/Logger/PNLog.h index c1feab169..ada3a5094 100644 --- a/PubNub/Misc/Logger/PNLog.h +++ b/PubNub/Misc/Logger/PNLog.h @@ -121,6 +121,9 @@ */ + (BOOL)isDumpingToFile; ++ (void)rollLogFileWithCompletion:(void (^)(void))completionBlock; ++ (NSString *)currentLogFilePath; + #pragma mark - diff --git a/PubNub/Misc/Logger/PNLog.m b/PubNub/Misc/Logger/PNLog.m index cb9be27f0..99a35c423 100644 --- a/PubNub/Misc/Logger/PNLog.m +++ b/PubNub/Misc/Logger/PNLog.m @@ -227,6 +227,30 @@ + (BOOL)isDumpingToFile { return [self sharedInstance].isFileLoggerActive; } +- (void)rollLogFileWithCompletion:(void (^)(void))completionBlock { + if (self.isFileLoggerActive) { + [self.fileLogger rollLogFileWithCompletionBlock:completionBlock]; + } +} + ++ (void)rollLogFileWithCompletion:(void (^)(void))completionBlock { + [[self sharedInstance] rollLogFileWithCompletion:completionBlock]; +} + +- (NSString *)currentLogFilePath { + if (self.isFileLoggerActive) { + DDLogFileInfo *fileInfo = [self.fileLogger currentLogFileInfo]; + if (fileInfo) { + return fileInfo.filePath; + } + } + return nil; +} + ++ (NSString *)currentLogFilePath { + return [[self sharedInstance] currentLogFilePath]; +} + #pragma mark - From c13cc14fb0028308aa461b1a419eac7dc724ea72 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Fri, 31 Jul 2015 13:00:02 -0700 Subject: [PATCH 03/23] Changed the file name of logs --- PubNub/Misc/Logger/PNLogFileManager.m | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/PubNub/Misc/Logger/PNLogFileManager.m b/PubNub/Misc/Logger/PNLogFileManager.m index 59d197b1a..e6d417d73 100644 --- a/PubNub/Misc/Logger/PNLogFileManager.m +++ b/PubNub/Misc/Logger/PNLogFileManager.m @@ -5,31 +5,38 @@ */ #import "PNLogFileManager.h" +@interface PNLogFileManager() + +@property (nonatomic, readwrite, strong) NSDateFormatter *dateFormatter; + +@end #pragma mark Interface implementation @implementation PNLogFileManager - (instancetype)init { - // Configure file manager with default storage in application's Documents folder. NSArray *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - return [self initWithLogsDirectory:[documents lastObject]]; + if (self = [self initWithLogsDirectory:[documents lastObject]]) { + NSString *dateFormat = @"yyyy'-'MM'-'dd'T'HH'-'mm'-'ss'"; + _dateFormatter = [[NSDateFormatter alloc] init]; + [_dateFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]]; + [_dateFormatter setDateFormat:dateFormat]; + [_dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; + } + return self; } - (NSString *)newLogFileName { - - return [[super newLogFileName] stringByReplacingOccurrencesOfString:@".log" - withString:@".txt"]; + NSString *formattedDate = [self.dateFormatter stringFromDate:[NSDate date]]; + return [[NSString alloc] initWithFormat:@"pubnub-console-dump-%@.log", formattedDate]; } - (BOOL)isLogFile:(NSString *)fileName { - - NSString *originalName = [fileName stringByReplacingOccurrencesOfString:@".txt" - withString:@".log"]; - - return [super isLogFile:originalName]; + return [fileName hasPrefix:@"pubnub-console-dump-"] + && [fileName hasSuffix:@".log"]; } #pragma mark - From 80c7cc6d7dcf6ec40c640c6c0a89bd8940060750 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Mon, 3 Aug 2015 13:57:32 -0700 Subject: [PATCH 04/23] Put history requests on their own network manager This is so we can set their timeout --- PubNub/Core/PubNub+Core.m | 12 ++++++++++++ PubNub/Data/PNConfiguration.h | 2 ++ PubNub/Data/PNConfiguration.m | 2 ++ 3 files changed, 16 insertions(+) diff --git a/PubNub/Core/PubNub+Core.m b/PubNub/Core/PubNub+Core.m index f9db95101..1be3fa349 100644 --- a/PubNub/Core/PubNub+Core.m +++ b/PubNub/Core/PubNub+Core.m @@ -70,6 +70,8 @@ @interface PubNub () */ @property (nonatomic, strong) PNNetwork *serviceNetwork; +@property (nonatomic, strong) PNNetwork *historyNetwork; + /** @brief Stores reference on reachability helper. @discussion Helper used by client to know about when something happened with network and when it is @@ -366,6 +368,10 @@ - (void)prepareNetworkManagers { _serviceNetwork = [PNNetwork networkForClient:self requestTimeout:_configuration.nonSubscribeRequestTimeout maximumConnections:3 longPoll:NO]; + _historyNetwork = [PNNetwork networkForClient:self + requestTimeout:_configuration.historyRequestTimeout + maximumConnections:1 + longPoll:NO]; } @@ -387,6 +393,12 @@ - (void)processOperation:(PNOperationType)operationType [self.subscriptionNetwork processOperation:operationType withParameters:parameters data:data completionBlock:block]; } + else if (operationType == PNHistoryOperation) { + [self.historyNetwork processOperation:operationType + withParameters:parameters + data:data + completionBlock:block]; + } else { [self.serviceNetwork processOperation:operationType withParameters:parameters diff --git a/PubNub/Data/PNConfiguration.h b/PubNub/Data/PNConfiguration.h index 3b0d5b05f..b2a6a93f2 100644 --- a/PubNub/Data/PNConfiguration.h +++ b/PubNub/Data/PNConfiguration.h @@ -111,6 +111,8 @@ */ @property (nonatomic, assign) NSTimeInterval nonSubscribeRequestTimeout; +@property (nonatomic, assign) NSTimeInterval historyRequestTimeout; + /** @brief Reference on number of seconds which is used by server to track whether client still subscribed on remote data objects live feed or not. diff --git a/PubNub/Data/PNConfiguration.m b/PubNub/Data/PNConfiguration.m index 4caf09887..97da5ae40 100644 --- a/PubNub/Data/PNConfiguration.m +++ b/PubNub/Data/PNConfiguration.m @@ -112,6 +112,7 @@ - (instancetype)initWithPublishKey:(NSString *)publishKey subscribeKey:(NSString _uuid = [[[NSUUID UUID] UUIDString] copy]; _subscribeMaximumIdleTime = kPNDefaultSubscribeMaximumIdleTime; _nonSubscribeRequestTimeout = kPNDefaultNonSubscribeRequestTimeout; + _historyRequestTimeout = kPNDefaultNonSubscribeRequestTimeout; _TLSEnabled = kPNDefaultIsTLSEnabled; _keepTimeTokenOnListChange = kPNDefaultShouldKeepTimeTokenOnListChange; _restoreSubscription = kPNDefaultShouldRestoreSubscription; @@ -133,6 +134,7 @@ - (id)copyWithZone:(NSZone *)zone { configuration.cipherKey = self.cipherKey; configuration.subscribeMaximumIdleTime = self.subscribeMaximumIdleTime; configuration.nonSubscribeRequestTimeout = self.nonSubscribeRequestTimeout; + configuration.historyRequestTimeout = self.historyRequestTimeout; configuration.presenceHeartbeatValue = self.presenceHeartbeatValue; configuration.presenceHeartbeatInterval = self.presenceHeartbeatInterval; configuration.TLSEnabled = self.isTLSEnabled; From 8459ff01583916863476593ac5d4ab10b24f7c47 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Wed, 19 Aug 2015 12:11:44 -0700 Subject: [PATCH 05/23] Added contents of published message to log --- PubNub/Core/PubNub+Publish.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PubNub/Core/PubNub+Publish.m b/PubNub/Core/PubNub+Publish.m index 5cf5f5712..3c7130861 100644 --- a/PubNub/Core/PubNub+Publish.m +++ b/PubNub/Core/PubNub+Publish.m @@ -179,8 +179,7 @@ - (void) publish:(id)message toChannel:(NSString *)channel DDLogAPICall([[self class] ddLogLevel], @" Publish%@ message to '%@' channel%@%@", (compressed ? @" compressed" : @""), (channel?: @""), (!shouldStore ? @" which won't be saved in hisotry" : @""), - (!compressed ? [NSString stringWithFormat:@": %@", - (messageForPublish?: @"")] : @".")); + ([NSString stringWithFormat:@": %@", (messageForPublish?: @"")])); [self processOperation:PNPublishOperation withParameters:parameters data:publishData completionBlock:^(PNStatus *status) { From e187de70cf1709a3d806f64b75aa72bdf4c20f23 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Wed, 19 Aug 2015 14:29:52 -0700 Subject: [PATCH 06/23] Added logging around continuing subscription cycle --- PubNub/Data/Managers/PNSubscriber.m | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/PubNub/Data/Managers/PNSubscriber.m b/PubNub/Data/Managers/PNSubscriber.m index 7e89454c1..79f7e1448 100644 --- a/PubNub/Data/Managers/PNSubscriber.m +++ b/PubNub/Data/Managers/PNSubscriber.m @@ -718,25 +718,30 @@ - (void)restoreSubscriptionCycleIfRequiredWithCompletion:(PNSubscriberCompletion __block BOOL shouldRestore; __block BOOL ableToRestore; + DDLogAPICall([[self class] ddLogLevel], @"Called restore subscription cycle with block: %@", block); + + __weak __typeof(self) weakSelf; dispatch_sync(self.resourceAccessQueue, ^{ - - shouldRestore = (self.currentState == PNDisconnectedUnexpectedlySubscriberState && - self.mayRequireSubscriptionRestore); - ableToRestore = ([self.channelsSet count] || [self.channelGroupsSet count] || - [self.presenceChannelsSet count]); + DDLogAPICall([[weakSelf class] ddLogLevel], @"Checking if should and able to restore subscription cycle with block: %@", block); + shouldRestore = (weakSelf.currentState == PNDisconnectedUnexpectedlySubscriberState && + weakSelf.mayRequireSubscriptionRestore); + ableToRestore = ([weakSelf.channelsSet count] || [weakSelf.channelGroupsSet count] || + [weakSelf.presenceChannelsSet count]); }); if (shouldRestore && ableToRestore) { - + DDLogAPICall([[self class] ddLogLevel], @"Restoring subscription cycle with block: %@", block); [self subscribe:YES withState:nil completion:block]; - } - else if (block) { - - block(nil); + } else { + DDLogAPICall([[self class] ddLogLevel], @"Not restoring subscription cycle with block (%d, %d): %@", shouldRestore, ableToRestore, block); + if (block) { + block(nil); + } } } - (void)continueSubscriptionCycleIfRequiredWithCompletion:(PNSubscriberCompletionBlock)block { + DDLogAPICall([[self class] ddLogLevel], @"Continuing subscription cycle with block: %@", block); [self subscribe:NO withState:nil completion:block]; } From f41edc036b4b1888426e4f63bf16fbd760c8b72a Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Wed, 9 Sep 2015 12:25:15 -0700 Subject: [PATCH 07/23] Fixed crash --- PubNub/Data/Service Objects/PNErrorStatus.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PubNub/Data/Service Objects/PNErrorStatus.m b/PubNub/Data/Service Objects/PNErrorStatus.m index b205d9659..7cb329c1f 100644 --- a/PubNub/Data/Service Objects/PNErrorStatus.m +++ b/PubNub/Data/Service Objects/PNErrorStatus.m @@ -23,8 +23,14 @@ - (NSArray *)channelGroups { } - (NSString *)information { - - return self.serviceData[@"information"]; + + if ([self.serviceData isKindOfClass:[NSDictionary class]]) { + return self.serviceData[@"information"]; + } else if ([self.serviceData isKindOfClass:[NSString class]]) { + return (NSString *)self.serviceData; + } else { + return nil; + } } - (id)data { From c402a1116e974fa7894520be297c8f15a951a5c0 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Wed, 9 Sep 2015 21:11:17 -0700 Subject: [PATCH 08/23] Fixed edge case with restoring connection --- PubNub/Core/PubNub+Core.m | 40 +++++++++++++---------------- PubNub/Data/Managers/PNSubscriber.m | 2 +- PubNub/Network/PNReachability.m | 15 +++++++---- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/PubNub/Core/PubNub+Core.m b/PubNub/Core/PubNub+Core.m index 1be3fa349..ef541a1f9 100644 --- a/PubNub/Core/PubNub+Core.m +++ b/PubNub/Core/PubNub+Core.m @@ -295,7 +295,6 @@ - (void)setRecentClientStatus:(PNStatusCategory)recentClientStatus { // Check whether previous client state reported unexpected disconnection from remote data // objects live feed or not. - PNStatusCategory previousState = self.recentClientStatus; PNStatusCategory currentState = recentClientStatus; // In case if client disconnected only from one of it's channels it should keep 'connected' @@ -310,25 +309,23 @@ - (void)setRecentClientStatus:(PNStatusCategory)recentClientStatus { // Check whether client reported unexpected disconnection. if (currentState == PNUnexpectedDisconnectCategory) { - // Check whether client unexpectedly disconnected while tried to subscribe or not. - if (previousState != PNDisconnectedCategory) { - - // Dispatching check block with small delay, which will allow to fire reachability - // change event. - __weak __typeof(self) weakSelf = self; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), - dispatch_get_main_queue(), ^{ - - // Silence static analyzer warnings. - // Code is aware about this case and at the end will simply call on 'nil' object - // method. In most cases if referenced object become 'nil' it mean what there is no - // more need in it and probably whole client instance has been deallocated. - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wreceiver-is-weak" - [weakSelf.reachability startServicePing]; - #pragma clang diagnostic pop - }); - } + // Dispatching check block with small delay, which will allow to fire reachability + // change event. + __weak __typeof(self) weakSelf = self; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), + dispatch_get_main_queue(), ^{ + + // Silence static analyzer warnings. + // Code is aware about this case and at the end will simply call on 'nil' object + // method. In most cases if referenced object become 'nil' it mean what there is no + // more need in it and probably whole client instance has been deallocated. + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wreceiver-is-weak" + [weakSelf.reachability startServicePing]; + #pragma clang diagnostic pop + }); + } else { + [self.reachability stopServicePing]; } } @@ -350,7 +347,6 @@ - (void)prepareReachability { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wreceiver-is-weak" #pragma clang diagnostic ignored "-Warc-repeated-use-of-weak" - [weakSelf.reachability stopServicePing]; [weakSelf.subscriberManager restoreSubscriptionCycleIfRequiredWithCompletion:nil]; #pragma clang diagnostic pop } @@ -476,7 +472,7 @@ - (void)callBlock:(id)block status:(BOOL)callingStatusBlock withResult:(PNResult - (void)client:(PubNub *)__unused client didReceiveStatus:(PNSubscribeStatus *)status { if (status.category == PNConnectedCategory || status.category == PNDisconnectedCategory || - status.category == PNUnexpectedDisconnectCategory) { + status.category == PNUnexpectedDisconnectCategory || status.category == PNReconnectedCategory) { self.recentClientStatus = status.category; } diff --git a/PubNub/Data/Managers/PNSubscriber.m b/PubNub/Data/Managers/PNSubscriber.m index 79f7e1448..5b58855a7 100644 --- a/PubNub/Data/Managers/PNSubscriber.m +++ b/PubNub/Data/Managers/PNSubscriber.m @@ -566,7 +566,7 @@ - (void)updateStateTo:(PNSubscriberState)state withStatus:(PNSubscribeStatus *)s currentState == PNConnectedSubscriberState); category = ((targetState == PNDisconnectedSubscriberState) ? PNDisconnectedCategory : PNUnexpectedDisconnectCategory); - self.mayRequireSubscriptionRestore = shouldHandleTransition; + self.mayRequireSubscriptionRestore = YES; } // Check whether transit to 'access denied' state. else if (targetState == PNAccessRightsErrorSubscriberState) { diff --git a/PubNub/Network/PNReachability.m b/PubNub/Network/PNReachability.m index 116beb6be..0c6a6f5ba 100644 --- a/PubNub/Network/PNReachability.m +++ b/PubNub/Network/PNReachability.m @@ -168,9 +168,13 @@ - (void)setPingRemoteService:(BOOL)pingRemoteService { - (void)startServicePing { if (!self.pingingRemoteService) { - self.pingRemoteService = YES; - + [self performServicePing]; + } +} + +- (void)performServicePing { + if (self.pingingRemoteService) { // Silence static analyzer warnings. // Code is aware about this case and at the end will simply call on 'nil' object method. // In most cases if referenced object become 'nil' it mean what there is no more need in @@ -181,6 +185,9 @@ - (void)startServicePing { // Try to request 'time' API to ensure what network really available. __weak __typeof(self) weakSelf = self; [self.client timeWithCompletion:^(PNTimeResult *result, __unused PNErrorStatus *status) { + if (!self.pingingRemoteService) { + return; + } __strong __typeof(self) strongSelf = weakSelf; BOOL successfulPing = (result.data != nil); @@ -201,9 +208,7 @@ - (void)startServicePing { NSTimeInterval delay = ((strongSelf.reachable && !successfulPing) ? 1.f : 10.0f); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - - strongSelf.pingRemoteService = NO; - [strongSelf startServicePing]; + [strongSelf performServicePing]; }); } strongSelf.reachable = successfulPing; From 5def595e394979562297d6f9d8585607ed15e326 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Fri, 2 Oct 2015 13:16:51 -0700 Subject: [PATCH 09/23] Changed maximum connections for subscription network This fixes the keep-alive issue for an unkown reason. There is an Apple Technical Support Request for this issue, follow up number 629273694 --- PubNub/Core/PubNub+Core.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PubNub/Core/PubNub+Core.m b/PubNub/Core/PubNub+Core.m index ef541a1f9..bdb38a771 100644 --- a/PubNub/Core/PubNub+Core.m +++ b/PubNub/Core/PubNub+Core.m @@ -360,7 +360,7 @@ - (void)prepareNetworkManagers { _subscriptionNetwork = [PNNetwork networkForClient:self requestTimeout:_configuration.subscribeMaximumIdleTime - maximumConnections:1 longPoll:YES]; + maximumConnections:2 longPoll:YES]; _serviceNetwork = [PNNetwork networkForClient:self requestTimeout:_configuration.nonSubscribeRequestTimeout maximumConnections:3 longPoll:NO]; From 05eb350b448e12b746ea94b480abc753da162021 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Wed, 14 Oct 2015 19:15:00 -0700 Subject: [PATCH 10/23] Handle subscribe timeouts as success --- PubNub/Data/Managers/PNSubscriber.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PubNub/Data/Managers/PNSubscriber.m b/PubNub/Data/Managers/PNSubscriber.m index 5b58855a7..4fc87c5fc 100644 --- a/PubNub/Data/Managers/PNSubscriber.m +++ b/PubNub/Data/Managers/PNSubscriber.m @@ -857,6 +857,8 @@ - (void)handleSubscriptionStatus:(PNSubscribeStatus *)status { [self stopRetryTimer]; if (!status.isError && status.category != PNCancelledCategory) { + [self handleSuccessSubscriptionStatus:status]; + } else if (status.isError && status.category == PNTimeoutCategory) { [self handleSuccessSubscriptionStatus:status]; } else { From b1fe272566863c75bd75e260a6a9a9854ec53007 Mon Sep 17 00:00:00 2001 From: Andrew Nguyen Date: Wed, 14 Oct 2015 17:31:43 -0700 Subject: [PATCH 11/23] remove cache from sessions since the cached data is never used --- PubNub/Network/PNNetwork.m | 1 + 1 file changed, 1 insertion(+) diff --git a/PubNub/Network/PNNetwork.m b/PubNub/Network/PNNetwork.m index 83a8c14cb..2a17e8fde 100644 --- a/PubNub/Network/PNNetwork.m +++ b/PubNub/Network/PNNetwork.m @@ -813,6 +813,7 @@ - (NSURLSessionConfiguration *)configurationWithRequestTimeout:(NSTimeInterval)t // Prepare base configuration with predefined timeout values and maximum connections // to same host (basically how many requests can be handled at once). NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration]; + configuration.URLCache = nil; configuration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData; configuration.HTTPShouldUsePipelining = !self.forLongPollRequests; configuration.HTTPAdditionalHeaders = _additionalHeaders; From 87dcb6bc440231c576a78bb9a73b76fd8f3b5cd3 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Tue, 27 Oct 2015 14:18:58 -0700 Subject: [PATCH 12/23] Code review for e187de70cf1709a3d806f64b75aa72bdf4c20f23 --- PubNub/Data/Managers/PNSubscriber.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PubNub/Data/Managers/PNSubscriber.m b/PubNub/Data/Managers/PNSubscriber.m index 4fc87c5fc..d59eb3b84 100644 --- a/PubNub/Data/Managers/PNSubscriber.m +++ b/PubNub/Data/Managers/PNSubscriber.m @@ -720,7 +720,7 @@ - (void)restoreSubscriptionCycleIfRequiredWithCompletion:(PNSubscriberCompletion __block BOOL ableToRestore; DDLogAPICall([[self class] ddLogLevel], @"Called restore subscription cycle with block: %@", block); - __weak __typeof(self) weakSelf; + __weak __typeof(self) weakSelf = self; dispatch_sync(self.resourceAccessQueue, ^{ DDLogAPICall([[weakSelf class] ddLogLevel], @"Checking if should and able to restore subscription cycle with block: %@", block); shouldRestore = (weakSelf.currentState == PNDisconnectedUnexpectedlySubscriberState && From 6ef0d48d3e74a0367c3ded97182be1d624b8df4f Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Tue, 27 Oct 2015 14:20:47 -0700 Subject: [PATCH 13/23] Code review for f41edc036b4b1888426e4f63bf16fbd760c8b72a Return description in case of unknown type --- PubNub/Data/Service Objects/PNErrorStatus.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PubNub/Data/Service Objects/PNErrorStatus.m b/PubNub/Data/Service Objects/PNErrorStatus.m index 7cb329c1f..9b33cf711 100644 --- a/PubNub/Data/Service Objects/PNErrorStatus.m +++ b/PubNub/Data/Service Objects/PNErrorStatus.m @@ -29,7 +29,7 @@ - (NSString *)information { } else if ([self.serviceData isKindOfClass:[NSString class]]) { return (NSString *)self.serviceData; } else { - return nil; + return [self.serviceData description]; } } From 70718fc5480defafc64ff23cffd6608e2ce3332e Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Tue, 27 Oct 2015 15:02:31 -0700 Subject: [PATCH 14/23] Code review change for e187de70cf1709a3d806f64b75aa72bdf4c20f23 --- PubNub/Data/Managers/PNSubscriber.m | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/PubNub/Data/Managers/PNSubscriber.m b/PubNub/Data/Managers/PNSubscriber.m index d59eb3b84..e43de1a09 100644 --- a/PubNub/Data/Managers/PNSubscriber.m +++ b/PubNub/Data/Managers/PNSubscriber.m @@ -722,11 +722,12 @@ - (void)restoreSubscriptionCycleIfRequiredWithCompletion:(PNSubscriberCompletion __weak __typeof(self) weakSelf = self; dispatch_sync(self.resourceAccessQueue, ^{ - DDLogAPICall([[weakSelf class] ddLogLevel], @"Checking if should and able to restore subscription cycle with block: %@", block); - shouldRestore = (weakSelf.currentState == PNDisconnectedUnexpectedlySubscriberState && - weakSelf.mayRequireSubscriptionRestore); - ableToRestore = ([weakSelf.channelsSet count] || [weakSelf.channelGroupsSet count] || - [weakSelf.presenceChannelsSet count]); + __strong __typeof(self) self = weakSelf; + DDLogAPICall([[self class] ddLogLevel], @"Checking if should and able to restore subscription cycle with block: %@", block); + shouldRestore = (self.currentState == PNDisconnectedUnexpectedlySubscriberState && + self.mayRequireSubscriptionRestore); + ableToRestore = ([self.channelsSet count] || [self.channelGroupsSet count] || + [self.presenceChannelsSet count]); }); if (shouldRestore && ableToRestore) { DDLogAPICall([[self class] ddLogLevel], @"Restoring subscription cycle with block: %@", block); From 5c240a263aaee3c08e23863d6c3e36fc7d8cf826 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Wed, 18 Nov 2015 18:01:34 -0800 Subject: [PATCH 15/23] Added a hopeful workaround to the crash from copying serviceData --- PubNub/Data/Service Objects/PNResult.m | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/PubNub/Data/Service Objects/PNResult.m b/PubNub/Data/Service Objects/PNResult.m index 586f55721..5abe72c81 100644 --- a/PubNub/Data/Service Objects/PNResult.m +++ b/PubNub/Data/Service Objects/PNResult.m @@ -67,7 +67,7 @@ - (instancetype)initForOperation:(PNOperationType)operation processedData = [dataForUpdate copy]; _statusCode = (([statusCode integerValue] > 200) ? [statusCode integerValue] : _statusCode); } - _serviceData = [processedData copy]; + _serviceData = [PNResult normalizeServiceData:processedData]; } return self; @@ -83,22 +83,35 @@ - (id)copyWithZone:(NSZone *)zone { result.authKey = self.authKey; result.origin = self.origin; result.clientRequest = self.clientRequest; - result.serviceData = self.serviceData; - + [result updateData:self.serviceData]; + return result; } - (instancetype)copyWithMutatedData:(id)data { PNResult *result = [self copy]; - result->_serviceData = [data copy]; - + [result updateData:data]; + return result; } ++ (NSDictionary *)normalizeServiceData:(id)serviceData { + if (serviceData && ![serviceData isKindOfClass:[NSDictionary class]]) { + id copyableServiceData; + if ([serviceData respondsToSelector:@selector(copy)]) { + copyableServiceData = serviceData; + } else { + copyableServiceData = [serviceData description]; + } + return @{@"information": [copyableServiceData copy]}; + } + return [serviceData copy]; +} + - (void)updateData:(id)data { - _serviceData = [data copy]; + _serviceData = [PNResult normalizeServiceData:data]; } From 3c9f586c109c8fad2925d3df2d91f2240260ef1e Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Wed, 9 Dec 2015 14:23:54 -0800 Subject: [PATCH 16/23] Copied status before using it on another thread --- PubNub/Data/Managers/PNSubscriber.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PubNub/Data/Managers/PNSubscriber.m b/PubNub/Data/Managers/PNSubscriber.m index e43de1a09..70be2f942 100644 --- a/PubNub/Data/Managers/PNSubscriber.m +++ b/PubNub/Data/Managers/PNSubscriber.m @@ -1059,6 +1059,7 @@ - (void)handleLiveFeedEvents:(PNSubscribeStatus *)status { // it and probably whole client instance has been deallocated. #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wreceiver-is-weak" + PNSubscribeStatus *copiedStatus = [status copy]; [self.client.listenersManager notifyWithBlock:^{ // Iterate through array with notifications and report back using callback blocks to the @@ -1086,7 +1087,7 @@ - (void)handleLiveFeedEvents:(PNSubscribeStatus *)status { } } - id eventResultObject = [status copyWithMutatedData:event]; + id eventResultObject = [copiedStatus copyWithMutatedData:event]; if (isPresenceEvent) { object_setClass(eventResultObject, [PNPresenceEventResult class]); From a7678c31839402e2dade488288dc49af82abdd64 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Wed, 9 Dec 2015 14:24:36 -0800 Subject: [PATCH 17/23] Don't copy serviceData when copying with mutatedData This is unnecessary and may cause a crash in thread unsafe code --- PubNub/Data/Service Objects/PNResult.m | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/PubNub/Data/Service Objects/PNResult.m b/PubNub/Data/Service Objects/PNResult.m index 5abe72c81..1fbbc301e 100644 --- a/PubNub/Data/Service Objects/PNResult.m +++ b/PubNub/Data/Service Objects/PNResult.m @@ -74,8 +74,20 @@ - (instancetype)initForOperation:(PNOperationType)operation } - (id)copyWithZone:(NSZone *)zone { + + return [self copyWithServiceData:YES]; +} + +- (instancetype)copyWithMutatedData:(id)data { - PNResult *result = [[[self class] allocWithZone:zone] init]; + PNResult *result = [self copyWithServiceData:NO]; + [result updateData:data]; + + return result; +} + +- (id)copyWithServiceData:(BOOL)shouldCopyServiceData { + PNResult *result = [[[self class] alloc] init]; result.statusCode = self.statusCode; result.operation = self.operation; result.TLSEnabled = self.isTLSEnabled; @@ -83,15 +95,10 @@ - (id)copyWithZone:(NSZone *)zone { result.authKey = self.authKey; result.origin = self.origin; result.clientRequest = self.clientRequest; - [result updateData:self.serviceData]; - - return result; -} -- (instancetype)copyWithMutatedData:(id)data { - - PNResult *result = [self copy]; - [result updateData:data]; + if (shouldCopyServiceData) { + [result updateData:self.serviceData]; + } return result; } From 1380f6b0ab5572dbb64df296c14b614f49191e49 Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Thu, 10 Dec 2015 13:08:33 -0800 Subject: [PATCH 18/23] Used allocWithZone in copyWithZone Code review change for a7678c31839402e2dade488288dc49af82abdd64 --- PubNub/Data/Service Objects/PNResult.m | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/PubNub/Data/Service Objects/PNResult.m b/PubNub/Data/Service Objects/PNResult.m index 1fbbc301e..8daf49cf6 100644 --- a/PubNub/Data/Service Objects/PNResult.m +++ b/PubNub/Data/Service Objects/PNResult.m @@ -74,20 +74,21 @@ - (instancetype)initForOperation:(PNOperationType)operation } - (id)copyWithZone:(NSZone *)zone { - - return [self copyWithServiceData:YES]; + PNResult *result = [[[self class] allocWithZone:zone] init]; + [self fillCopy:result shouldCopyServiceData:YES]; + return result; } - (instancetype)copyWithMutatedData:(id)data { - PNResult *result = [self copyWithServiceData:NO]; + PNResult *result = [[[self class] alloc] init]; + [self fillCopy:result shouldCopyServiceData:NO]; [result updateData:data]; return result; } -- (id)copyWithServiceData:(BOOL)shouldCopyServiceData { - PNResult *result = [[[self class] alloc] init]; +- (void)fillCopy:(PNResult *)result shouldCopyServiceData:(BOOL)shouldCopyServiceData { result.statusCode = self.statusCode; result.operation = self.operation; result.TLSEnabled = self.isTLSEnabled; @@ -99,8 +100,6 @@ - (id)copyWithServiceData:(BOOL)shouldCopyServiceData { if (shouldCopyServiceData) { [result updateData:self.serviceData]; } - - return result; } + (NSDictionary *)normalizeServiceData:(id)serviceData { From 7001666e3b27c43e3b69c7b31a9a650b7483f376 Mon Sep 17 00:00:00 2001 From: Steven Jeram Date: Mon, 8 Jun 2015 14:47:10 -0700 Subject: [PATCH 19/23] Ignore Android build artefacts Conflicts: .gitignore --- .gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.gitignore b/.gitignore index 541965de2..827bedd6f 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,13 @@ Icon? ehthumbs.db Thumbs.db .idea/ + +# Removed because it has some weird file names that Windows can't handle # +########################################################################## +iOS/tests/* + +# Android # +########### +**/*.approj/configuration.json +**/*.approj/Headers +**/*.approj/targets From f4f980d9523f6f3f84282ec980109bc926873efa Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Fri, 4 Sep 2015 15:31:24 -0700 Subject: [PATCH 20/23] Get PubNub 4.0.3 building on Android --- PubNub/Core/PubNub+Core.m | 9 ++- PubNub/Data/PNAES.m | 7 ++ PubNub/Data/PNConfiguration.m | 4 +- PubNub/Misc/PNConstants.h | 2 +- PubNub/Network/PNNetwork.m | 5 +- PubNub/SConscript | 117 ++++++++++++++++++++++++++++++++++ src | 1 + 7 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 PubNub/SConscript create mode 120000 src diff --git a/PubNub/Core/PubNub+Core.m b/PubNub/Core/PubNub+Core.m index bdb38a771..eacd53682 100644 --- a/PubNub/Core/PubNub+Core.m +++ b/PubNub/Core/PubNub+Core.m @@ -16,6 +16,9 @@ #import "PNNetwork.h" #import "PNHelpers.h" +#ifdef PGDROID +#import +#endif #pragma mark Static @@ -208,7 +211,7 @@ - (instancetype)initWithConfiguration:(PNConfiguration *)configuration _heartbeatManager = [PNHeartbeat heartbeatForClient:self]; [self addListener:self]; [self prepareReachability]; -#if __IPHONE_OS_VERSION_MIN_REQUIRED +#if __IPHONE_OS_VERSION_MIN_REQUIRED || defined(PGDROID) NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter addObserver:self selector:@selector(handleContextTransition:) name:UIApplicationWillEnterForegroundNotification object:nil]; @@ -483,7 +486,7 @@ - (void)client:(PubNub *)__unused client didReceiveStatus:(PNSubscribeStatus *)s - (void)handleContextTransition:(NSNotification *)notification { -#if __IPHONE_OS_VERSION_MIN_REQUIRED +#if __IPHONE_OS_VERSION_MIN_REQUIRED || defined(PGDROID) if ([notification.name isEqualToString:UIApplicationDidEnterBackgroundNotification]) { DDLogClientInfo([[self class] ddLogLevel], @" Did enter background execution context."); @@ -511,7 +514,7 @@ - (void)handleContextTransition:(NSNotification *)notification { - (void)dealloc { -#if __IPHONE_OS_VERSION_MIN_REQUIRED +#if __IPHONE_OS_VERSION_MIN_REQUIRED || defined(PGDROID) NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil]; diff --git a/PubNub/Data/PNAES.m b/PubNub/Data/PNAES.m index 4042ceb99..66a64261f 100644 --- a/PubNub/Data/PNAES.m +++ b/PubNub/Data/PNAES.m @@ -6,6 +6,9 @@ #import "PNAES.h" #import #import +#ifdef PGDROID +//#import +#endif #import "PubNub+CorePrivate.h" #import #import "PNErrorCodes.h" @@ -356,8 +359,12 @@ + (NSError *)errorFor:(CCCryptorStatus)status { errorCode = kPNAESInsufficientMemoryError; break; case kCCDecodeError: +#ifdef PGDROID +# warning HC SVNT DRACONES! : CommonCrypto is not fully implemented on PGDroid ... +#else case kCCOverflow: case kCCRNGFailure: +#endif description = @"Provided data can't be processed (data can be not encryped)."; errorCode = kPNAESDecryptionError; diff --git a/PubNub/Data/PNConfiguration.m b/PubNub/Data/PNConfiguration.m index 97da5ae40..b600f6f8f 100644 --- a/PubNub/Data/PNConfiguration.m +++ b/PubNub/Data/PNConfiguration.m @@ -3,7 +3,7 @@ @since 4.0 @copyright © 2009-2015 PubNub, Inc. */ -#if __IPHONE_OS_VERSION_MIN_REQUIRED +#if __IPHONE_OS_VERSION_MIN_REQUIRED || defined(PGDROID) #import #elif __MAC_OS_X_VERSION_MIN_REQUIRED #import @@ -149,7 +149,7 @@ - (id)copyWithZone:(NSZone *)zone { #pragma mark - Misc - (NSString *)uniqueDeviceIdentifier { -#if __IPHONE_OS_VERSION_MIN_REQUIRED +#if __IPHONE_OS_VERSION_MIN_REQUIRED || defined(PGDROID) return [[[UIDevice currentDevice] identifierForVendor] UUIDString]; #elif __MAC_OS_X_VERSION_MIN_REQUIRED return ([self serialNumber]?: [self macAddress]); diff --git a/PubNub/Misc/PNConstants.h b/PubNub/Misc/PNConstants.h index c511e78b2..a3b964070 100644 --- a/PubNub/Misc/PNConstants.h +++ b/PubNub/Misc/PNConstants.h @@ -20,7 +20,7 @@ static NSString * const kPNLibraryVersion = @"4.0.3"; static NSString * const kPNBranchName = @"master"; static NSString * const kPNCommit = @"a9c8c4648958b86cac4b59f7092cc6ed06dd7626"; -#if __IPHONE_OS_VERSION_MIN_REQUIRED +#if __IPHONE_OS_VERSION_MIN_REQUIRED || defined(PGDROID) static NSString * const kPNClientName = @"ObjC-iOS"; #elif __MAC_OS_X_VERSION_MIN_REQUIRED static NSString * const kPNClientName = @"ObjC-MacOS"; diff --git a/PubNub/Network/PNNetwork.m b/PubNub/Network/PNNetwork.m index 2a17e8fde..3454bf338 100644 --- a/PubNub/Network/PNNetwork.m +++ b/PubNub/Network/PNNetwork.m @@ -18,6 +18,9 @@ #import "PNConstants.h" #import "PNHelpers.h" +#ifdef PGDROID + #import +#endif #pragma mark CocoaLumberjack logging support @@ -849,7 +852,7 @@ - (NSURL *)requestBaseURL { - (NSDictionary *)defaultHeaders { NSString *device = @"iPhone"; -#if __IPHONE_OS_VERSION_MIN_REQUIRED +#if __IPHONE_OS_VERSION_MIN_REQUIRED || defined(PGDROID) device = [[UIDevice currentDevice] model]; NSString *osVersion = [[UIDevice currentDevice] systemVersion]; #elif __MAC_OS_X_VERSION_MIN_REQUIRED diff --git a/PubNub/SConscript b/PubNub/SConscript new file mode 100644 index 000000000..0f1cff994 --- /dev/null +++ b/PubNub/SConscript @@ -0,0 +1,117 @@ +header_paths = [ + # Lumberingjack stuff + '../../Pods/CocoaLumberjack/Classes/', + '../../Pods/Headers/Public/', + + # PubNub + './Core', + './Data', + './Data/Managers', + './Data/Service Objects', + './Misc', + './Misc/Helpers', + './Misc/Logger', + './Misc/Protocols', + './Network', + './Network/Parsers', + './PubNub', + '.', +] + +defines = { + 'PGDROID' : 1, +} + +flags = [ + '-fobjc-arc', + '-Wall', + #'-Werror', ... sigh ... maybe someday +] + +deps = [ +] + +sources = [ + # Lumberingjack stuff + '../../Pods/CocoaLumberjack/Classes/DDASLLogCapture.m', + '../../Pods/CocoaLumberjack/Classes/DDASLLogger.m', + '../../Pods/CocoaLumberjack/Classes/DDAbstractDatabaseLogger.m', + '../../Pods/CocoaLumberjack/Classes/DDFileLogger.m', + '../../Pods/CocoaLumberjack/Classes/DDLog.m', + '../../Pods/CocoaLumberjack/Classes/DDTTYLogger.m', + + # PubNub stuffs + './Core/PubNub+APNS.m', + './Core/PubNub+ChannelGroup.m', + './Core/PubNub+Core.m', + './Core/PubNub+History.m', + './Core/PubNub+Presence.m', + './Core/PubNub+Publish.m', + './Core/PubNub+State.m', + './Core/PubNub+Subscribe.m', + './Core/PubNub+Time.m', + './Data/Managers/PNClientState.m', + './Data/Managers/PNHeartbeat.m', + './Data/Managers/PNStateListener.m', + './Data/Managers/PNSubscriber.m', + './Data/PNAES.m', + './Data/PNConfiguration.m', + './Data/Service Objects/PNAcknowledgmentStatus.m', + './Data/Service Objects/PNAPNSEnabledChannelsResult.m', + './Data/Service Objects/PNChannelClientStateResult.m', + './Data/Service Objects/PNChannelGroupChannelsResult.m', + './Data/Service Objects/PNChannelGroupClientStateResult.m', + './Data/Service Objects/PNChannelGroupsResult.m', + './Data/Service Objects/PNClientStateUpdateStatus.m', + './Data/Service Objects/PNErrorStatus.m', + './Data/Service Objects/PNHistoryResult.m', + './Data/Service Objects/PNPresenceChannelGroupHereNowResult.m', + './Data/Service Objects/PNPresenceChannelHereNowResult.m', + './Data/Service Objects/PNPresenceGlobalHereNowResult.m', + './Data/Service Objects/PNPresenceWhereNowResult.m', + './Data/Service Objects/PNPublishStatus.m', + './Data/Service Objects/PNResult.m', + './Data/Service Objects/PNServiceData.m', + './Data/Service Objects/PNStatus.m', + './Data/Service Objects/PNSubscriberResults.m', + './Data/Service Objects/PNSubscribeStatus.m', + './Data/Service Objects/PNTimeResult.m', + './Misc/Helpers/PNArray.m', + './Misc/Helpers/PNChannel.m', + './Misc/Helpers/PNClass.m', + './Misc/Helpers/PNData.m', + './Misc/Helpers/PNDictionary.m', + './Misc/Helpers/PNGZIP.m', + './Misc/Helpers/PNJSON.m', + './Misc/Helpers/PNString.m', + './Misc/Helpers/PNURLRequest.m', + './Misc/Logger/PNLog.m', + './Misc/Logger/PNLogFileManager.m', + './Misc/Logger/PNLogger.m', + './Network/Parsers/PNChannelGroupAuditionParser.m', + './Network/Parsers/PNChannelGroupModificationParser.m', + './Network/Parsers/PNClientStateParser.m', + './Network/Parsers/PNErrorParser.m', + './Network/Parsers/PNHeartbeatParser.m', + './Network/Parsers/PNHistoryParser.m', + './Network/Parsers/PNLeaveParser.m', + './Network/Parsers/PNMessagePublishParser.m', + './Network/Parsers/PNPresenceHereNowParser.m', + './Network/Parsers/PNPresenceWhereNowParser.m', + './Network/Parsers/PNPushNotificationsAuditParser.m', + './Network/Parsers/PNPushNotificationsStateModificationParser.m', + './Network/Parsers/PNRemoveDeviceFromAPNSResponseParser.m', + './Network/Parsers/PNSubscribeParser.m', + './Network/Parsers/PNTimeParser.m', + './Network/PNNetwork.m', + './Network/PNNetworkResponseSerializer.m', + './Network/PNReachability.m', + './Network/PNRequestParameters.m', + './Network/PNURLBuilder.m', +] + +features = [ +] + +Import('env') +env.BuildLibrary('PubNub', sources, header_paths=header_paths, static=True, flags=flags, defines=defines, deps=deps, features=features) diff --git a/src b/src new file mode 120000 index 000000000..bb49dac7b --- /dev/null +++ b/src @@ -0,0 +1 @@ +PubNub \ No newline at end of file From bcf9b35883f053eb958e56269c42d534acad4b34 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Mon, 25 Jan 2016 13:53:04 -0800 Subject: [PATCH 21/23] Removed unnecessary commented code --- PubNub/Data/PNAES.m | 3 --- 1 file changed, 3 deletions(-) diff --git a/PubNub/Data/PNAES.m b/PubNub/Data/PNAES.m index 66a64261f..ae37a725d 100644 --- a/PubNub/Data/PNAES.m +++ b/PubNub/Data/PNAES.m @@ -6,9 +6,6 @@ #import "PNAES.h" #import #import -#ifdef PGDROID -//#import -#endif #import "PubNub+CorePrivate.h" #import #import "PNErrorCodes.h" From c179213e9295cdab466069d02c1f8623caf5eded Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Wed, 17 Feb 2016 15:30:13 -0800 Subject: [PATCH 22/23] Fix a crash on Android --- PubNub/Data/Managers/PNSubscriber.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PubNub/Data/Managers/PNSubscriber.m b/PubNub/Data/Managers/PNSubscriber.m index 70be2f942..dbdff1ede 100644 --- a/PubNub/Data/Managers/PNSubscriber.m +++ b/PubNub/Data/Managers/PNSubscriber.m @@ -859,8 +859,12 @@ - (void)handleSubscriptionStatus:(PNSubscribeStatus *)status { if (!status.isError && status.category != PNCancelledCategory) { [self handleSuccessSubscriptionStatus:status]; +#ifdef PGDROID + // 2016/02/16 : this PG addition is causing crashes on Android ... Sending an instance of PNErrorStatus to -handleSuccessSubscriptionStatus: is not valid since it references properties specific to PNSubscribeStatus ... unsure why we're not seeing this in crash groups on iOS ... LONG TERM solution is to probably revert both of the commits around this and roll forward to the latest PubNub and run full QA ;-) +#else } else if (status.isError && status.category == PNTimeoutCategory) { [self handleSuccessSubscriptionStatus:status]; +#endif } else { From f6b308ecdaa7b5b2c2fd6c36b069b276511fabac Mon Sep 17 00:00:00 2001 From: Matthew Koontz Date: Tue, 8 Mar 2016 12:52:36 -0800 Subject: [PATCH 23/23] Added support for custom ports --- PubNub/Data/PNConfiguration.h | 2 ++ PubNub/Data/PNConfiguration.m | 2 ++ PubNub/Network/PNNetwork.m | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/PubNub/Data/PNConfiguration.h b/PubNub/Data/PNConfiguration.h index b2a6a93f2..8f2f8bf21 100644 --- a/PubNub/Data/PNConfiguration.h +++ b/PubNub/Data/PNConfiguration.h @@ -189,6 +189,8 @@ */ @property (nonatomic, assign, getter = shouldTryCatchUpOnSubscriptionRestore) BOOL catchUpOnSubscriptionRestore; +@property (nonatomic, assign) long port; + /** @brief Construct configuration instance using minimal required data. diff --git a/PubNub/Data/PNConfiguration.m b/PubNub/Data/PNConfiguration.m index b600f6f8f..a9a6ac490 100644 --- a/PubNub/Data/PNConfiguration.m +++ b/PubNub/Data/PNConfiguration.m @@ -117,6 +117,7 @@ - (instancetype)initWithPublishKey:(NSString *)publishKey subscribeKey:(NSString _keepTimeTokenOnListChange = kPNDefaultShouldKeepTimeTokenOnListChange; _restoreSubscription = kPNDefaultShouldRestoreSubscription; _catchUpOnSubscriptionRestore = kPNDefaultShouldTryCatchUpOnSubscriptionRestore; + _port = _TLSEnabled ? 443 : 80; } return self; @@ -141,6 +142,7 @@ - (id)copyWithZone:(NSZone *)zone { configuration.keepTimeTokenOnListChange = self.shouldKeepTimeTokenOnListChange; configuration.restoreSubscription = self.shouldRestoreSubscription; configuration.catchUpOnSubscriptionRestore = self.shouldTryCatchUpOnSubscriptionRestore; + configuration.port = self.port; return configuration; } diff --git a/PubNub/Network/PNNetwork.m b/PubNub/Network/PNNetwork.m index 3454bf338..2e426e0e0 100644 --- a/PubNub/Network/PNNetwork.m +++ b/PubNub/Network/PNNetwork.m @@ -845,8 +845,8 @@ - (NSURLSession *)sessionWithConfiguration:(NSURLSessionConfiguration *)configur - (NSURL *)requestBaseURL { - return [NSURL URLWithString:[NSString stringWithFormat:@"http%@://%@", - (_configuration.TLSEnabled ? @"s" : @""), _configuration.origin]]; + return [NSURL URLWithString:[[NSString alloc] initWithFormat:@"http%@://%@:%ld", + (_configuration.TLSEnabled ? @"s" : @""), _configuration.origin, _configuration.port]]; } - (NSDictionary *)defaultHeaders {