Skip to content

Commit d17795d

Browse files
committed
Merge pull request #553 from ParsePlatform/nlutsenko.tvos.analytics
Create in-memory eventually queue for analytics events on tvOS.
2 parents 6997f39 + e670dbb commit d17795d

File tree

6 files changed

+189
-5
lines changed

6 files changed

+189
-5
lines changed

Parse.podspec

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ Pod::Spec.new do |s|
1111
s.platform = :ios, :osx
1212
s.ios.deployment_target = '7.0'
1313
s.osx.deployment_target = '10.9'
14-
14+
1515
s.requires_arc = true
1616

1717
s.source_files = 'Parse/*.{h,m}',
1818
'Parse/Internal/**/*.{h,m}'
1919
s.public_header_files = 'Parse/*.h'
20-
20+
21+
s.ios.exclude_files = 'Parse/Internal/PFMemoryEventuallyQueue.{h,m}'
2122
s.osx.exclude_files = 'Parse/PFNetworkActivityIndicatorManager.{h,m}',
2223
'Parse/PFProduct.{h,m}',
2324
'Parse/PFPurchase.{h,m}',
2425
'Parse/Internal/PFAlertView.{h,m}',
2526
'Parse/Internal/Product/**/*.{h,m}',
26-
'Parse/Internal/Purchase/**/*.{h,m}'
27-
27+
'Parse/Internal/Purchase/**/*.{h,m}',
28+
'Parse/Internal/PFMemoryEventuallyQueue.{h,m}'
29+
2830
s.resources = 'Parse/Resources/en.lproj'
2931

3032
s.ios.frameworks = 'AudioToolbox',
@@ -44,7 +46,7 @@ Pod::Spec.new do |s|
4446
'QuartzCore',
4547
'Security',
4648
'SystemConfiguration'
47-
49+
4850
s.libraries = 'z', 'sqlite3'
4951

5052
s.dependency 'Bolts/Tasks', '>= 1.4.0'

Parse.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@
654654
815960A21ABCA3B30069EBCC /* PFFileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 8159609F1ABCA3B30069EBCC /* PFFileManager.h */; };
655655
815960A31ABCA3B30069EBCC /* PFFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 815960A01ABCA3B30069EBCC /* PFFileManager.m */; };
656656
815960A41ABCA3B30069EBCC /* PFFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 815960A01ABCA3B30069EBCC /* PFFileManager.m */; };
657+
815CC4411BF533EF00FBF8D3 /* PFMemoryEventuallyQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 815CC43F1BF533EF00FBF8D3 /* PFMemoryEventuallyQueue.h */; };
658+
815CC4421BF533EF00FBF8D3 /* PFMemoryEventuallyQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 815CC4401BF533EF00FBF8D3 /* PFMemoryEventuallyQueue.m */; };
657659
815E764D1BDF168A00E1DF8E /* PFPersistenceController.h in Headers */ = {isa = PBXBuildFile; fileRef = 815E764B1BDF168A00E1DF8E /* PFPersistenceController.h */; };
658660
815E764E1BDF168A00E1DF8E /* PFPersistenceController.h in Headers */ = {isa = PBXBuildFile; fileRef = 815E764B1BDF168A00E1DF8E /* PFPersistenceController.h */; };
659661
815E764F1BDF168A00E1DF8E /* PFPersistenceController.h in Headers */ = {isa = PBXBuildFile; fileRef = 815E764B1BDF168A00E1DF8E /* PFPersistenceController.h */; };
@@ -1939,6 +1941,8 @@
19391941
815618FF1A1F79AC0076504A /* PFDateFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFDateFormatter.m; sourceTree = "<group>"; };
19401942
8159609F1ABCA3B30069EBCC /* PFFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFFileManager.h; sourceTree = "<group>"; };
19411943
815960A01ABCA3B30069EBCC /* PFFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFFileManager.m; sourceTree = "<group>"; };
1944+
815CC43F1BF533EF00FBF8D3 /* PFMemoryEventuallyQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFMemoryEventuallyQueue.h; sourceTree = "<group>"; };
1945+
815CC4401BF533EF00FBF8D3 /* PFMemoryEventuallyQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFMemoryEventuallyQueue.m; sourceTree = "<group>"; };
19421946
815E764B1BDF168A00E1DF8E /* PFPersistenceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFPersistenceController.h; sourceTree = "<group>"; };
19431947
815E764C1BDF168A00E1DF8E /* PFPersistenceController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFPersistenceController.m; sourceTree = "<group>"; };
19441948
815EE8EE19F976D50076FE5D /* PFRESTCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFRESTCommand.h; sourceTree = "<group>"; };
@@ -2504,6 +2508,8 @@
25042508
children = (
25052509
81EDD4BC1B59A6D8002F69C0 /* CommandRunner */,
25062510
8119C9961A76E28F0085B516 /* PFNetworkCommand.h */,
2511+
815CC43F1BF533EF00FBF8D3 /* PFMemoryEventuallyQueue.h */,
2512+
815CC4401BF533EF00FBF8D3 /* PFMemoryEventuallyQueue.m */,
25072513
7C1FDDCA14E1B1BD00A77007 /* PFCommandCache.h */,
25082514
7C1FDDCB14E1B1BD00A77007 /* PFCommandCache.m */,
25092515
913B9F2C1A311FF40040247C /* PFCommandCache_Private.h */,
@@ -4176,6 +4182,7 @@
41764182
815F23E91BD04D150054659F /* PFMutableRelationState.h in Headers */,
41774183
815F23EA1BD04D150054659F /* PFSession_Private.h in Headers */,
41784184
815F23EB1BD04D150054659F /* PFObjectEstimatedData.h in Headers */,
4185+
815CC4411BF533EF00FBF8D3 /* PFMemoryEventuallyQueue.h in Headers */,
41794186
815F23EC1BD04D150054659F /* PFObjectFilePersistenceController.h in Headers */,
41804187
815F23ED1BD04D150054659F /* PFInstallationConstants.h in Headers */,
41814188
815F23EE1BD04D150054659F /* PFUserPrivate.h in Headers */,
@@ -5142,6 +5149,7 @@
51425149
files = (
51435150
815F22B41BD04D150054659F /* PFWeakValue.m in Sources */,
51445151
815F22B51BD04D150054659F /* PFUserState.m in Sources */,
5152+
815CC4421BF533EF00FBF8D3 /* PFMemoryEventuallyQueue.m in Sources */,
51455153
815F22B61BD04D150054659F /* PFCommandURLRequestConstructor.m in Sources */,
51465154
815F22B71BD04D150054659F /* PFCoreManager.m in Sources */,
51475155
815F22B81BD04D150054659F /* PFURLSessionUploadTaskDelegate.m in Sources */,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) 2015-present, Parse, LLC.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "PFEventuallyQueue.h"
11+
12+
PF_IOS_UNAVAILABLE_WARNING
13+
PF_OSX_UNAVAILABLE_WARNING
14+
PF_WATCH_UNAVAILABLE_WARNING
15+
16+
PF_IOS_UNAVAILABLE PF_OSX_UNAVAILABLE PF_WATCH_UNAVAILABLE @interface PFMemoryEventuallyQueue : PFEventuallyQueue
17+
18+
+ (instancetype)newDefaultMemoryEventuallyQueueWithCommandRunner:(id<PFCommandRunning>)commandRunner;
19+
20+
@end
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* Copyright (c) 2015-present, Parse, LLC.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "PFMemoryEventuallyQueue.h"
11+
#import "PFEventuallyQueue_Private.h"
12+
13+
#import <Bolts/BFTask.h>
14+
#import <Bolts/BFExecutor.h>
15+
16+
@interface PFMemoryEventuallyQueue () <PFEventuallyQueueSubclass> {
17+
dispatch_queue_t _dataAccessQueue;
18+
BFExecutor *_dataAccessExecutor;
19+
20+
NSMutableArray PF_GENERIC(NSString *)*_pendingCommandIdentifiers;
21+
NSMutableDictionary PF_GENERIC(NSString *, id<PFNetworkCommand>)*_commandsDictionary;
22+
}
23+
24+
@end
25+
26+
@implementation PFMemoryEventuallyQueue
27+
28+
///--------------------------------------
29+
#pragma mark - Init
30+
///--------------------------------------
31+
32+
+ (instancetype)newDefaultMemoryEventuallyQueueWithCommandRunner:(id<PFCommandRunning>)commandRunner {
33+
PFMemoryEventuallyQueue *queue = [[self alloc] initWithCommandRunner:commandRunner
34+
maxAttemptsCount:PFEventuallyQueueDefaultMaxAttemptsCount
35+
retryInterval:PFEventuallyQueueDefaultTimeoutRetryInterval];
36+
[queue start];
37+
return queue;
38+
}
39+
40+
- (instancetype)initWithCommandRunner:(id<PFCommandRunning>)commandRunner
41+
maxAttemptsCount:(NSUInteger)attemptsCount
42+
retryInterval:(NSTimeInterval)retryInterval {
43+
self = [super initWithCommandRunner:commandRunner maxAttemptsCount:attemptsCount retryInterval:retryInterval];
44+
if (!self) return nil;
45+
46+
_dataAccessQueue = dispatch_queue_create("com.parse.eventuallyQueue.memory", DISPATCH_QUEUE_SERIAL);
47+
_dataAccessExecutor = [BFExecutor executorWithDispatchQueue:_dataAccessQueue];
48+
49+
_pendingCommandIdentifiers = [NSMutableArray array];
50+
_commandsDictionary = [NSMutableDictionary dictionary];
51+
52+
return self;
53+
}
54+
55+
///--------------------------------------
56+
#pragma mark - Controlling Queue
57+
///--------------------------------------
58+
59+
- (void)removeAllCommands {
60+
[super removeAllCommands];
61+
62+
dispatch_sync(_dataAccessQueue, ^{
63+
[_pendingCommandIdentifiers removeAllObjects];
64+
[_commandsDictionary removeAllObjects];
65+
});
66+
}
67+
68+
///--------------------------------------
69+
#pragma mark - PFEventuallyQueueSubclass
70+
///--------------------------------------
71+
72+
- (NSString *)_newIdentifierForCommand:(id<PFNetworkCommand>)command {
73+
return [NSUUID UUID].UUIDString;
74+
}
75+
76+
- (NSArray PF_GENERIC(NSString *)*)_pendingCommandIdentifiers {
77+
__block NSArray *array = nil;
78+
dispatch_sync(_dataAccessQueue, ^{
79+
array = [_pendingCommandIdentifiers copy];
80+
});
81+
return array;
82+
}
83+
84+
- (id<PFNetworkCommand>)_commandWithIdentifier:(NSString *)identifier error:(NSError **)error {
85+
__block id<PFNetworkCommand> command = nil;
86+
dispatch_sync(_dataAccessQueue, ^{
87+
command = _commandsDictionary[identifier];
88+
});
89+
return command;
90+
}
91+
92+
- (BFTask *)_enqueueCommandInBackground:(id<PFNetworkCommand>)command object:(PFObject *)object identifier:(NSString *)identifier {
93+
return [BFTask taskFromExecutor:_dataAccessExecutor withBlock:^id{
94+
[_pendingCommandIdentifiers addObject:identifier];
95+
_commandsDictionary[identifier] = command;
96+
return nil;
97+
}];
98+
}
99+
100+
- (BFTask *)_didFinishRunningCommand:(id<PFNetworkCommand>)command withIdentifier:(NSString *)identifier resultTask:(BFTask *)resultTask {
101+
return [BFTask taskFromExecutor:_dataAccessExecutor withBlock:^id{
102+
[_pendingCommandIdentifiers removeObject:identifier];
103+
[_commandsDictionary removeObjectForKey:identifier];
104+
return [super _didFinishRunningCommand:command withIdentifier:identifier resultTask:resultTask];
105+
}];
106+
}
107+
108+
- (BFTask *)_waitForOperationSet:(PFOperationSet *)operationSet eventuallyPin:(PFEventuallyPin *)eventuallyPin {
109+
return [BFTask taskWithResult:nil];
110+
}
111+
112+
@end

Parse/Internal/ParseManager.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
#import "PFProduct.h"
3939
#endif
4040

41+
#if TARGET_OS_TV
42+
#import "PFMemoryEventuallyQueue.h"
43+
#endif
44+
4145
static NSString *const _ParseApplicationIdFileName = @"applicationId";
4246

4347
@interface ParseManager () <PFCoreManagerDataSource>
@@ -165,6 +169,11 @@ - (BOOL)isOfflineStoreLoaded {
165169
- (PFEventuallyQueue *)eventuallyQueue {
166170
__block PFEventuallyQueue *queue = nil;
167171
dispatch_sync(_eventuallyQueueAccessQueue, ^{
172+
#if TARGET_OS_TV
173+
if (!_eventuallyQueue) {
174+
_eventuallyQueue = [PFMemoryEventuallyQueue newDefaultMemoryEventuallyQueueWithCommandRunner:self.commandRunner];
175+
}
176+
#else
168177
if (!_eventuallyQueue ||
169178
(self.offlineStoreLoaded && [_eventuallyQueue isKindOfClass:[PFCommandCache class]]) ||
170179
(!self.offlineStoreLoaded && [_eventuallyQueue isKindOfClass:[PFPinningEventuallyQueue class]])) {
@@ -184,6 +193,7 @@ - (PFEventuallyQueue *)eventuallyQueue {
184193
[commandCache removeAllCommands];
185194
}
186195
}
196+
#endif
187197
queue = _eventuallyQueue;
188198
});
189199
return queue;

Parse/PFConstants.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,38 @@ extern NSString *const __nonnull PFNetworkNotificationURLResponseBodyUserInfoKey
498498
/// @name Avaiability Macros
499499
///--------------------------------------
500500

501+
#ifndef PF_IOS_UNAVAILABLE
502+
# ifdef __IOS_UNAVILABLE
503+
# define PF_IOS_UNAVAILABLE __IOS_UNAVAILABLE
504+
# else
505+
# define PF_IOS_UNAVAILABLE
506+
# endif
507+
#endif
508+
509+
#ifndef PF_IOS_UNAVAILABLE_WARNING
510+
# if TARGET_OS_IOS
511+
# define PF_IOS_UNAVAILABLE_WARNING _Pragma("GCC warning \"This file is unavailable on iOS.\"")
512+
# else
513+
# define PF_IOS_UNAVAILABLE_WARNING
514+
# endif
515+
#endif
516+
517+
#ifndef PF_OSX_UNAVAILABLE
518+
# if PF_TARGET_OS_OSX
519+
# define PF_OSX_UNAVAILABLE __OSX_UNAVAILABLE
520+
# else
521+
# define PF_OSX_UNAVAILABLE
522+
# endif
523+
#endif
524+
525+
#ifndef PF_OSX_UNAVAILABLE_WARNING
526+
# if PF_TARGET_OS_OSX
527+
# define PF_OSX_UNAVAILABLE_WARNING _Pragma("GCC warning \"This file is unavailable on OS X.\"")
528+
# else
529+
# define PF_OSX_UNAVAILABLE_WARNING
530+
# endif
531+
#endif
532+
501533
#ifndef PF_WATCH_UNAVAILABLE
502534
# ifdef __WATCHOS_UNAVAILABLE
503535
# define PF_WATCH_UNAVAILABLE __WATCHOS_UNAVAILABLE

0 commit comments

Comments
 (0)