Skip to content

Commit 2ffa975

Browse files
committed
Merge pull request #730 from ParsePlatform/nlutsenko.macros
Unify all platform conditional macros.
2 parents d396768 + 8bebe60 commit 2ffa975

13 files changed

+34
-32
lines changed

Parse/Internal/Object/PFObjectPrivate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
- (PFObjectEstimatedData *)_estimatedData;
9999

100-
#if PARSE_OSX_ONLY
100+
#if PF_TARGET_OS_OSX
101101
// Not available publicly, but available for testing
102102

103103
- (instancetype)refresh;

Parse/Internal/PFApplication.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ + (instancetype)currentApplication {
3535
///--------------------------------------
3636

3737
- (BOOL)isAppStoreEnvironment {
38-
#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
38+
#if TARGET_OS_IOS && !TARGET_IPHONE_SIMULATOR
3939
return ([[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"] == nil);
4040
#endif
4141

Parse/Internal/PFDevice.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ - (NSString *)operatingSystemBuild {
133133

134134
- (BOOL)isJailbroken {
135135
BOOL jailbroken = NO;
136-
#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
136+
#if TARGET_OS_IOS && !TARGET_IPHONE_SIMULATOR
137137
DIR *dir = opendir("/");
138138
if (dir != NULL) {
139139
jailbroken = YES;

Parse/Internal/PFFileManager.m

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
static NSString *const _PFFileManagerParseDirectoryName = @"Parse";
2020

2121
static NSDictionary *_PFFileManagerDefaultDirectoryFileAttributes() {
22-
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
22+
#if !PF_TARGET_OS_OSX
2323
return @{ NSFileProtectionKey : NSFileProtectionCompleteUntilFirstUserAuthentication };
2424
#else
2525
return nil;
@@ -28,7 +28,7 @@
2828

2929
static NSDataWritingOptions _PFFileManagerDefaultDataWritingOptions() {
3030
NSDataWritingOptions options = NSDataWritingAtomic;
31-
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
31+
#if !PF_TARGET_OS_OSX
3232
options |= NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication;
3333
#endif
3434
return options;
@@ -92,7 +92,7 @@ + (BFTask *)createDirectoryIfNeededAsyncAtPath:(NSString *)path
9292
}
9393
}
9494

95-
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
95+
#if TARGET_OS_IOS || TARGET_OS_WATCH // No backups for Apple TV, since everything is cache.
9696
if (options & PFFileManagerOptionSkipBackup) {
9797
[self _skipBackupOnPath:path];
9898
}
@@ -246,7 +246,12 @@ - (instancetype)initWithApplicationIdentifier:(NSString *)applicationIdentifier
246246
- (NSString *)parseDefaultDataDirectoryPath {
247247
// NSHomeDirectory: Returns the path to either the user's or application's
248248
// home directory, depending on the platform. Sandboxed by default on iOS.
249-
#if PARSE_IOS_ONLY
249+
#if PF_TARGET_OS_OSX
250+
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
251+
NSString *directoryPath = [paths firstObject];
252+
directoryPath = [directoryPath stringByAppendingPathComponent:_PFFileManagerParseDirectoryName];
253+
directoryPath = [directoryPath stringByAppendingPathComponent:self.applicationIdentifier];
254+
#else
250255
NSString *directoryPath = nil;
251256
if (self.applicationGroupIdentifier) {
252257
NSURL *containerPath = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:self.applicationGroupIdentifier];
@@ -255,11 +260,6 @@ - (NSString *)parseDefaultDataDirectoryPath {
255260
} else {
256261
return [self parseLocalSandboxDataDirectoryPath];
257262
}
258-
#else
259-
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
260-
NSString *directoryPath = [paths firstObject];
261-
directoryPath = [directoryPath stringByAppendingPathComponent:_PFFileManagerParseDirectoryName];
262-
directoryPath = [directoryPath stringByAppendingPathComponent:self.applicationIdentifier];
263263
#endif
264264

265265
BFTask *createDirectoryTask = [[self class] createDirectoryIfNeededAsyncAtPath:directoryPath
@@ -271,7 +271,9 @@ - (NSString *)parseDefaultDataDirectoryPath {
271271
}
272272

273273
- (NSString *)parseLocalSandboxDataDirectoryPath {
274-
#if TARGET_OS_IPHONE
274+
#if PF_TARGET_OS_OSX
275+
return [self parseDefaultDataDirectoryPath];
276+
#else
275277
NSString *library = [NSHomeDirectory() stringByAppendingPathComponent:@"Library"];
276278
NSString *privateDocuments = [library stringByAppendingPathComponent:@"Private Documents"];
277279
NSString *directoryPath = [privateDocuments stringByAppendingPathComponent:_PFFileManagerParseDirectoryName];
@@ -281,8 +283,6 @@ - (NSString *)parseLocalSandboxDataDirectoryPath {
281283
[createDirectoryTask waitForResult:nil withMainThreadWarning:NO];
282284

283285
return directoryPath;
284-
#else
285-
return [self parseDefaultDataDirectoryPath];
286286
#endif
287287
}
288288

@@ -294,7 +294,7 @@ - (NSString *)parseCacheItemPathForPathComponent:(NSString *)component {
294294
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
295295
NSString *folderPath = paths.firstObject;
296296
folderPath = [folderPath stringByAppendingPathComponent:_PFFileManagerParseDirectoryName];
297-
#if !TARGET_OS_IPHONE
297+
#if PF_TARGET_OS_OSX
298298
// We append the applicationId in case the OS X application isn't sandboxed,
299299
// to avoid collisions in the generic ~/Library/Caches/Parse/------ dir.
300300
folderPath = [folderPath stringByAppendingPathComponent:self.applicationIdentifier];

Parse/Internal/PFLocationManager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
#import <Foundation/Foundation.h>
1111

12+
#import <Parse/PFConstants.h>
13+
1214
@class CLLocation;
1315
@class CLLocationManager;
1416

15-
#if TARGET_OS_IPHONE
17+
#if !PF_TARGET_OS_OSX
1618

1719
@class UIApplication;
1820

@@ -39,7 +41,7 @@ typedef void(^PFLocationManagerLocationUpdateBlock)(CLLocation *location, NSErro
3941

4042
- (instancetype)initWithSystemLocationManager:(CLLocationManager *)manager;
4143

42-
#if TARGET_OS_IPHONE
44+
#if !PF_TARGET_OS_OSX
4345

4446
- (instancetype)initWithSystemLocationManager:(CLLocationManager *)manager
4547
application:(UIApplication *)application

Parse/Internal/PFReachability.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ + (BOOL)_reachabilityStateForFlags:(SCNetworkConnectionFlags)flags {
6666
}
6767
}
6868

69-
#if TARGET_OS_IPHONE
69+
#if !PF_TARGET_OS_OSX
7070
if (((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) &&
7171
((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0)) {
7272
// ... but WWAN connections are OK if the calling application

Parse/PFConstants.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
#pragma mark - Platform
2020
///--------------------------------------
2121

22-
#define PARSE_IOS_ONLY (TARGET_OS_IPHONE)
23-
#define PARSE_OSX_ONLY (TARGET_OS_MAC && !(TARGET_OS_IPHONE))
24-
2522
extern NSString *const _Nonnull kPFDeviceType;
2623

2724
///--------------------------------------
@@ -469,7 +466,7 @@ extern NSString *const _Nonnull PFNetworkNotificationURLResponseBodyUserInfoKey;
469466
#endif
470467

471468
#ifndef PF_TARGET_OS_OSX
472-
# define PF_TARGET_OS_OSX TARGET_OS_MAC && !TARGET_OS_IOS && !TARGET_OS_WATCH && !TARGET_OS_TV
469+
# define PF_TARGET_OS_OSX (TARGET_OS_MAC && !TARGET_OS_IOS && !TARGET_OS_WATCH && !TARGET_OS_TV)
473470
#endif
474471

475472
///--------------------------------------

Parse/PFObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ NS_REQUIRES_PROPERTY_DEFINITIONS
394394
*/
395395
@property (nonatomic, assign, readonly, getter=isDataAvailable) BOOL dataAvailable;
396396

397-
#if PARSE_IOS_ONLY
397+
#if TARGET_OS_IOS
398398

399399
/**
400400
Refreshes the PFObject with the current data from the server.

Parse/PFPush.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#import "PFQueryPrivate.h"
2929
#import "PFUserPrivate.h"
3030
#import "Parse_Private.h"
31+
#import "PFApplication.h"
3132

3233
static Class _pushInternalUtilClass = nil;
3334

@@ -286,9 +287,9 @@ + (void)unsubscribeFromChannelInBackground:(NSString *)channel block:(PFBooleanR
286287
#pragma mark - Handling Notifications
287288
///--------------------------------------
288289

289-
#if PARSE_IOS_ONLY
290+
#if TARGET_OS_IOS
290291
+ (void)handlePush:(NSDictionary *)userInfo {
291-
UIApplication *application = [UIApplication sharedApplication];
292+
UIApplication *application = [PFApplication currentApplication].systemApplication;
292293
if (application.applicationState != UIApplicationStateActive) {
293294
return;
294295
}

Parse/Parse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ NS_ASSUME_NONNULL_BEGIN
171171
*/
172172
+ (NSString *)containingApplicationBundleIdentifierForDataSharing PF_WATCH_UNAVAILABLE PF_TV_UNAVAILABLE;
173173

174-
#if PARSE_IOS_ONLY
174+
#if TARGET_OS_IOS
175175

176176
///--------------------------------------
177177
#pragma mark - Configuring UI Settings

Parse/Parse.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ + (BOOL)isLocalDatastoreEnabled {
186186
#pragma mark - User Interface
187187
///--------------------------------------
188188

189-
#if PARSE_IOS_ONLY
189+
#if TARGET_OS_IOS
190190

191191
+ (void)offlineMessagesEnabled:(BOOL)enabled {
192192
// Deprecated method - shouldn't do anything.

Tests/Other/ExtensionDataSharing/PFExtensionDataSharingTestHelper.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ + (NSString *)sharedTestDirectoryPath {
3232
}
3333

3434
+ (NSString *)sharedTestDirectoryPathForGroupIdentifier:(NSString *)groupIdentifier {
35-
#if TARGET_OS_IPHONE
36-
return [[PFExtensionDataSharingTestHelper sharedTestDirectoryPath] stringByAppendingPathComponent:groupIdentifier];
37-
#else
35+
#if PF_TARGET_OS_OSX
3836
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
3937
return [paths firstObject];
38+
#else
39+
return [[PFExtensionDataSharingTestHelper sharedTestDirectoryPath] stringByAppendingPathComponent:groupIdentifier];
4040
#endif
4141
}
4242

Tests/Other/LocationManager/CLLocationManager+TestAdditions.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#import "CLLocationManager+TestAdditions.h"
1111

12+
#import <Parse/PFConstants.h>
13+
1214
#import "PFTestSwizzlingUtilities.h"
1315

1416
@interface CLLocationManager ()
@@ -31,7 +33,7 @@ @implementation CLLocationManager (TestAdditions)
3133

3234
+ (void)setMockingEnabled:(BOOL)enabled {
3335
// There is no ability to use real CLLocationManager on Mac, due to permission requests
34-
#if PARSE_OSX_ONLY
36+
#if PF_TARGET_OS_OSX
3537
if (!enabled) {
3638
return;
3739
}

0 commit comments

Comments
 (0)