Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8025f2d
Removed limit for PubNub logs
mjk3979 Jul 27, 2015
273334f
Exposed some logging methods needed for verbose logging
mjk3979 Jul 31, 2015
c13cc14
Changed the file name of logs
mjk3979 Jul 31, 2015
80c7cc6
Put history requests on their own network manager
mjk3979 Aug 3, 2015
8459ff0
Added contents of published message to log
mjk3979 Aug 19, 2015
e187de7
Added logging around continuing subscription cycle
mjk3979 Aug 19, 2015
f41edc0
Fixed crash
mjk3979 Sep 9, 2015
c402a11
Fixed edge case with restoring connection
mjk3979 Sep 10, 2015
5def595
Changed maximum connections for subscription network
mjk3979 Oct 2, 2015
05eb350
Handle subscribe timeouts as success
mjk3979 Oct 15, 2015
b1fe272
remove cache from sessions since the cached data is never used
andrew87 Oct 15, 2015
87dcb6b
Code review for e187de70cf1709a3d806f64b75aa72bdf4c20f23
mjk3979 Oct 27, 2015
6ef0d48
Code review for f41edc036b4b1888426e4f63bf16fbd760c8b72a
mjk3979 Oct 27, 2015
70718fc
Code review change for e187de70cf1709a3d806f64b75aa72bdf4c20f23
mjk3979 Oct 27, 2015
5c240a2
Added a hopeful workaround to the crash from copying serviceData
mjk3979 Nov 19, 2015
2340a79
Merge pull request #9 from pocketgems/dragons3d_service_data_fix
mjk3979 Nov 20, 2015
3c9f586
Copied status before using it on another thread
mjk3979 Dec 9, 2015
a7678c3
Don't copy serviceData when copying with mutatedData
mjk3979 Dec 9, 2015
1380f6b
Used allocWithZone in copyWithZone
mjk3979 Dec 10, 2015
0b1fe56
Merge pull request #10 from pocketgems/fix-service-data
mjk3979 Dec 11, 2015
7001666
Ignore Android build artefacts
steven-jeram Jun 8, 2015
f4f980d
Get PubNub 4.0.3 building on Android
Sep 4, 2015
86c2eb7
Merge pull request #11 from pocketgems/dragonsDroid_master_merge
Feb 12, 2016
bcf9b35
Removed unnecessary commented code
Jan 25, 2016
c179213
Fix a crash on Android
Feb 17, 2016
04b664e
Merge pull request #12 from pocketgems/DRG-36268
mauiaaron Feb 22, 2016
f6b308e
Added support for custom ports
mjk3979 Mar 8, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
63 changes: 37 additions & 26 deletions PubNub/Core/PubNub+Core.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#import "PNNetwork.h"
#import "PNHelpers.h"

#ifdef PGDROID
#import <UIKit/UIKit.h>
#endif

#pragma mark Static

Expand Down Expand Up @@ -70,6 +73,8 @@ @interface PubNub () <PNObjectEventListener>
*/
@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
Expand Down Expand Up @@ -206,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];
Expand Down Expand Up @@ -293,7 +298,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'
Expand All @@ -308,25 +312,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];
}
}

Expand All @@ -348,7 +350,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
}
Expand All @@ -362,10 +363,14 @@ - (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];
_historyNetwork = [PNNetwork networkForClient:self
requestTimeout:_configuration.historyRequestTimeout
maximumConnections:1
longPoll:NO];
}


Expand All @@ -387,6 +392,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
Expand Down Expand Up @@ -464,7 +475,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;
}
Expand All @@ -475,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], @"<PubNub> Did enter background execution context.");
Expand Down Expand Up @@ -503,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];
Expand Down
3 changes: 1 addition & 2 deletions PubNub/Core/PubNub+Publish.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ - (void) publish:(id)message toChannel:(NSString *)channel
DDLogAPICall([[self class] ddLogLevel], @"<PubNub> Publish%@ message to '%@' channel%@%@",
(compressed ? @" compressed" : @""), (channel?: @"<error>"),
(!shouldStore ? @" which won't be saved in hisotry" : @""),
(!compressed ? [NSString stringWithFormat:@": %@",
(messageForPublish?: @"<error>")] : @"."));
([NSString stringWithFormat:@": %@", (messageForPublish?: @"<error>")]));

[self processOperation:PNPublishOperation withParameters:parameters data:publishData
completionBlock:^(PNStatus *status) {
Expand Down
29 changes: 21 additions & 8 deletions PubNub/Data/Managers/PNSubscriber.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -718,25 +718,31 @@ - (void)restoreSubscriptionCycleIfRequiredWithCompletion:(PNSubscriberCompletion

__block BOOL shouldRestore;
__block BOOL ableToRestore;
DDLogAPICall([[self class] ddLogLevel], @"Called restore subscription cycle with block: %@", block);

__weak __typeof(self) weakSelf = self;
dispatch_sync(self.resourceAccessQueue, ^{

__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);
[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];
}

Expand Down Expand Up @@ -853,6 +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 {

Expand Down Expand Up @@ -1051,6 +1063,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
Expand Down Expand Up @@ -1078,7 +1091,7 @@ - (void)handleLiveFeedEvents:(PNSubscribeStatus *)status {
}
}

id eventResultObject = [status copyWithMutatedData:event];
id eventResultObject = [copiedStatus copyWithMutatedData:event];
if (isPresenceEvent) {

object_setClass(eventResultObject, [PNPresenceEventResult class]);
Expand Down
4 changes: 4 additions & 0 deletions PubNub/Data/PNAES.m
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,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;
Expand Down
4 changes: 4 additions & 0 deletions PubNub/Data/PNConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -187,6 +189,8 @@
*/
@property (nonatomic, assign, getter = shouldTryCatchUpOnSubscriptionRestore) BOOL catchUpOnSubscriptionRestore;

@property (nonatomic, assign) long port;

/**
@brief Construct configuration instance using minimal required data.

Expand Down
8 changes: 6 additions & 2 deletions PubNub/Data/PNConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 <UIKit/UIKit.h>
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
#import <IOKit/IOKitLib.h>
Expand Down Expand Up @@ -112,10 +112,12 @@ - (instancetype)initWithPublishKey:(NSString *)publishKey subscribeKey:(NSString
_uuid = [[[NSUUID UUID] UUIDString] copy];
_subscribeMaximumIdleTime = kPNDefaultSubscribeMaximumIdleTime;
_nonSubscribeRequestTimeout = kPNDefaultNonSubscribeRequestTimeout;
_historyRequestTimeout = kPNDefaultNonSubscribeRequestTimeout;
_TLSEnabled = kPNDefaultIsTLSEnabled;
_keepTimeTokenOnListChange = kPNDefaultShouldKeepTimeTokenOnListChange;
_restoreSubscription = kPNDefaultShouldRestoreSubscription;
_catchUpOnSubscriptionRestore = kPNDefaultShouldTryCatchUpOnSubscriptionRestore;
_port = _TLSEnabled ? 443 : 80;
}

return self;
Expand All @@ -133,12 +135,14 @@ - (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;
configuration.keepTimeTokenOnListChange = self.shouldKeepTimeTokenOnListChange;
configuration.restoreSubscription = self.shouldRestoreSubscription;
configuration.catchUpOnSubscriptionRestore = self.shouldTryCatchUpOnSubscriptionRestore;
configuration.port = self.port;

return configuration;
}
Expand All @@ -147,7 +151,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]);
Expand Down
10 changes: 8 additions & 2 deletions PubNub/Data/Service Objects/PNErrorStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 [self.serviceData description];
}
}

- (id)data {
Expand Down
Loading