Skip to content

Commit

Permalink
Merge pull request #325 from ParsePlatform/nlutsenko.watch.reachability
Browse files Browse the repository at this point in the history
Cleaned up reachability tracking in PFEventuallyQueue, disabled reachability for watchOS.
  • Loading branch information
nlutsenko committed Sep 25, 2015
2 parents 881d164 + 71d5d8e commit 9e866f0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
2 changes: 0 additions & 2 deletions Parse.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@
810155F41BB3832700D7C7BD /* PFMutableObjectState.h in Headers */ = {isa = PBXBuildFile; fileRef = 81CB7F731B166FF500DC601D /* PFMutableObjectState.h */; };
810155F51BB3832700D7C7BD /* PFWeakValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 81C1EE471AE1EF960031C438 /* PFWeakValue.h */; };
810155F61BB3832700D7C7BD /* PFOfflineStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 8166FCA41B503886003841A2 /* PFOfflineStore.h */; };
810155F71BB3832700D7C7BD /* PFReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = 81329E8C1AE1E8840071EE3E /* PFReachability.h */; };
810155F81BB3832700D7C7BD /* PFMutableQueryState.h in Headers */ = {isa = PBXBuildFile; fileRef = 81C7F4A71AF42BD9007B5418 /* PFMutableQueryState.h */; };
810155F91BB3832700D7C7BD /* PFPaymentTransactionObserver_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = F5B0B3121B44A05100F3EBC4 /* PFPaymentTransactionObserver_Private.h */; };
810155FA1BB3832700D7C7BD /* PFPushState_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 81CB7F981B17970400DC601D /* PFPushState_Private.h */; };
Expand Down Expand Up @@ -3528,7 +3527,6 @@
810155F41BB3832700D7C7BD /* PFMutableObjectState.h in Headers */,
810155F51BB3832700D7C7BD /* PFWeakValue.h in Headers */,
810155F61BB3832700D7C7BD /* PFOfflineStore.h in Headers */,
810155F71BB3832700D7C7BD /* PFReachability.h in Headers */,
810155F81BB3832700D7C7BD /* PFMutableQueryState.h in Headers */,
810155F91BB3832700D7C7BD /* PFPaymentTransactionObserver_Private.h in Headers */,
810155FA1BB3832700D7C7BD /* PFPushState_Private.h in Headers */,
Expand Down
2 changes: 1 addition & 1 deletion Parse/Internal/PFEventuallyQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern NSTimeInterval const PFEventuallyQueueDefaultTimeoutRetryInterval;
Controls whether the queue should monitor network reachability and pause itself when there is no connection.
Default: `YES`.
*/
@property (atomic, assign, readonly) BOOL monitorsReachability;
@property (atomic, assign, readonly) BOOL monitorsReachability PF_WATCH_UNAVAILABLE;
@property (nonatomic, assign, readonly, getter=isConnected) BOOL connected;

// Gets notifications of various events happening in the command cache, so that tests can be synchronized.
Expand Down
22 changes: 14 additions & 8 deletions Parse/Internal/PFEventuallyQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
NSUInteger const PFEventuallyQueueDefaultMaxAttemptsCount = 5;
NSTimeInterval const PFEventuallyQueueDefaultTimeoutRetryInterval = 600.0f;

@interface PFEventuallyQueue () <PFReachabilityListener>
@interface PFEventuallyQueue ()
#if !TARGET_OS_WATCH
<PFReachabilityListener>
#endif

@property (atomic, assign, readwrite) BOOL monitorsReachability;
@property (atomic, assign, getter=isRunning) BOOL running;
Expand Down Expand Up @@ -360,6 +363,9 @@ - (BFTask *)_waitForOperationSet:(PFOperationSet *)operationSet
///--------------------------------------

- (void)_startMonitoringNetworkReachability {
#if TARGET_OS_WATCH
self.connected = YES;
#else
if (self.monitorsReachability) {
return;
}
Expand All @@ -369,24 +375,20 @@ - (void)_startMonitoringNetworkReachability {

// Set the initial connected status
self.connected = ([PFReachability sharedParseReachability].currentState != PFReachabilityStateNotReachable);
#endif
}

- (void)_stopMonitoringNetworkReachability {
#if !TARGET_OS_WATCH
if (!self.monitorsReachability) {
return;
}

[[PFReachability sharedParseReachability] removeListener:self];

if (_reachability != NULL) {
SCNetworkReachabilitySetCallback(_reachability, NULL, NULL);
SCNetworkReachabilitySetDispatchQueue(_reachability, NULL);
CFRelease(_reachability);
_reachability = NULL;
}

self.monitorsReachability = NO;
self.connected = YES;
#endif
}

///--------------------------------------
Expand Down Expand Up @@ -454,6 +456,8 @@ - (void)_setRetryInterval:(NSTimeInterval)retryInterval {
_retryInterval = retryInterval;
}

#if !TARGET_OS_WATCH

///--------------------------------------
#pragma mark - Reachability
///--------------------------------------
Expand All @@ -464,6 +468,8 @@ - (void)reachability:(PFReachability *)reachability didChangeReachabilityState:(
}
}

#endif

@end

// PFEventuallyQueueTestHelper gets notifications of various events happening in the command cache,
Expand Down
6 changes: 0 additions & 6 deletions Parse/Internal/PFEventuallyQueue_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import <SystemConfiguration/SCNetworkReachability.h>

#import "PFEventuallyQueue.h"

@class BFExecutor;
Expand All @@ -28,10 +26,6 @@ extern NSTimeInterval const PFEventuallyQueueDefaultTimeoutRetryInterval;
BFExecutor *_synchronizationExecutor;
dispatch_queue_t _synchronizationQueue;

// Object for getting network status.
SCNetworkReachabilityRef _reachability;
dispatch_queue_t _reachabilityQueue;

@private
dispatch_queue_t _processingQueue;
dispatch_source_t _processingQueueSource;
Expand Down
5 changes: 3 additions & 2 deletions Parse/Internal/PFReachability.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*/

#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>

#import <Parse/PFConstants.h>

@class PFReachability;

Expand All @@ -26,7 +27,7 @@ typedef NS_ENUM(uint8_t, PFReachabilityState) {

@end

@interface PFReachability : NSObject
PF_WATCH_UNAVAILABLE @interface PFReachability : NSObject

@property (nonatomic, assign, readonly) PFReachabilityState currentState;

Expand Down
2 changes: 2 additions & 0 deletions Parse/Internal/PFReachability.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import "PFReachability.h"

#import <SystemConfiguration/SystemConfiguration.h>

#import "PFAssert.h"
#import "PFConstants.h"
#import "PFLogging.h"
Expand Down
18 changes: 15 additions & 3 deletions Parse/PFConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,27 @@ extern NSString *const PF_NONNULL_S PFNetworkNotificationURLResponseBodyUserInfo
///--------------------------------------

#ifndef TARGET_OS_IOS
#define TARGET_OS_IOS TARGET_OS_IPHONE
# define TARGET_OS_IOS TARGET_OS_IPHONE
#endif
#ifndef TARGET_OS_WATCH
#define TARGET_OS_WATCH 0
# define TARGET_OS_WATCH 0
#endif
#ifndef TARGET_OS_TV
#define TARGET_OS_TV 0
# define TARGET_OS_TV 0
#endif

#ifndef PF_TARGET_OS_OSX
# define PF_TARGET_OS_OSX TARGET_OS_MAC && !TARGET_OS_IOS && !TARGET_OS_WATCH && !TARGET_OS_TV
#endif

///--------------------------------------
/// @name Avaiability Macros
///--------------------------------------

#ifndef PF_WATCH_UNAVAILABLE
# ifdef __WATCHOS_UNAVAILABLE
# define PF_WATCH_UNAVAILABLE __WATCHOS_UNAVAILABLE
# else
# define PF_WATCH_UNAVAILABLE
# endif
#endif

0 comments on commit 9e866f0

Please sign in to comment.