Skip to content

Commit ef39e46

Browse files
committed
Merge pull request #235 from ParsePlatform/nlutsenko.notifications
Publicize network notifications.
2 parents 4962d4d + 89a311d commit ef39e46

File tree

6 files changed

+58
-54
lines changed

6 files changed

+58
-54
lines changed

Parse/Internal/Commands/CommandRunner/PFCommandRunningConstants.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,3 @@ extern NSString *const PFCommandHeaderNameSessionToken;
3333
///--------------------------------------
3434

3535
extern NSString *const PFCommandParameterNameMethodOverride;
36-
37-
///--------------------------------------
38-
/// @name Notifications
39-
///--------------------------------------
40-
41-
/*!
42-
@abstract The name of the notification that is going to be sent before any URL request is sent.
43-
*/
44-
extern NSString *const PFCommandRunnerWillSendURLRequestNotification;
45-
46-
/*!
47-
@abstract The name of the notification that is going to be sent after any URL response is received.
48-
*/
49-
extern NSString *const PFCommandRunnerDidReceiveURLResponseNotification;
50-
51-
/*!
52-
@abstract The key of request(NSURLRequest) in the userInfo dictionary of a notification.
53-
@note This key is populated in userInfo, only of `PFLogLevel` in `PFLogger` is set to `PFLogLevelDebug`.
54-
*/
55-
extern NSString *const PFCommandRunnerNotificationURLRequestUserInfoKey;
56-
57-
/*!
58-
@abstract The key of response(NSHTTPURLResponse) in the userInfo dictionary of a notification.
59-
@note This key is populated in userInfo, only of `PFLogLevel` in `PFLogger` is set to `PFLogLevelDebug`.
60-
*/
61-
extern NSString *const PFCommandRunnerNotificationURLResponseUserInfoKey;
62-
63-
/*!
64-
@abstract The key of repsonse body (usually `NSString` with JSON) in the userInfo dictionary of a notification.
65-
@note This key is populated in userInfo, only of `PFLogLevel` in `PFLogger` is set to `PFLogLevelDebug`.
66-
*/
67-
extern NSString *const PFCommandRunnerNotificationURLResponseBodyUserInfoKey;

Parse/Internal/Commands/CommandRunner/PFCommandRunningConstants.m

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,3 @@
2121
NSString *const PFCommandHeaderNameSessionToken = @"X-Parse-Session-Token";
2222

2323
NSString *const PFCommandParameterNameMethodOverride = @"_method";
24-
25-
///--------------------------------------
26-
#pragma mark - Notifications
27-
///--------------------------------------
28-
29-
NSString *const PFCommandRunnerWillSendURLRequestNotification = @"PFCommandRunnerWillSendURLRequestNotification";
30-
NSString *const PFCommandRunnerDidReceiveURLResponseNotification = @"PFCommandRunnerDidReceiveURLResponseNotification";
31-
NSString *const PFCommandRunnerNotificationURLRequestUserInfoKey = @"PFCommandRunnerNotificationURLRequestUserInfoKey";
32-
NSString *const PFCommandRunnerNotificationURLResponseUserInfoKey = @"PFCommandRunnerNotificationURLResponseUserInfoKey";
33-
NSString *const PFCommandRunnerNotificationURLResponseBodyUserInfoKey = @"PFCommandRunnerNotificationURLResponseBodyUserInfoKey";

Parse/Internal/Commands/CommandRunner/URLSession/PFURLSessionCommandRunner.m

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ - (BFTask *)runCommandAsync:(PFRESTCommand *)command withOptions:(PFCommandRunni
119119
- (BFTask *)runCommandAsync:(PFRESTCommand *)command
120120
withOptions:(PFCommandRunningOptions)options
121121
cancellationToken:(BFCancellationToken *)cancellationToken {
122-
return [self _performCommandRunningBlock:^id{
122+
return [self _performCommandRunningBlock:^id {
123123
[command resolveLocalIds];
124124
NSURLRequest *request = [self.requestConstructor dataURLRequestForCommand:command];
125125
return [_session performDataURLRequestAsync:request forCommand:command cancellationToken:cancellationToken];
@@ -137,7 +137,7 @@ - (BFTask *)runFileUploadCommandAsync:(PFRESTCommand *)command
137137
cancellationToken:(nullable BFCancellationToken *)cancellationToken
138138
progressBlock:(nullable PFProgressBlock)progressBlock {
139139
@weakify(self);
140-
return [self _performCommandRunningBlock:^id{
140+
return [self _performCommandRunningBlock:^id {
141141
@strongify(self);
142142

143143
[command resolveLocalIds];
@@ -157,13 +157,14 @@ - (BFTask *)runFileDownloadCommandAsyncWithFileURL:(NSURL *)url
157157
targetFilePath:(NSString *)filePath
158158
cancellationToken:(nullable BFCancellationToken *)cancellationToken
159159
progressBlock:(nullable PFProgressBlock)progressBlock {
160-
return [self _performCommandRunningBlock:^id{
160+
return [self _performCommandRunningBlock:^id {
161161
NSURLRequest *request = [NSURLRequest requestWithURL:url];
162162
return [_session performFileDownloadURLRequestAsync:request
163163
toFileAtPath:filePath
164164
withCancellationToken:cancellationToken
165165
progressBlock:progressBlock];
166-
} withOptions:PFCommandRunningOptionRetryIfFailed cancellationToken:cancellationToken];
166+
} withOptions:PFCommandRunningOptionRetryIfFailed
167+
cancellationToken:cancellationToken];
167168
}
168169

169170
///--------------------------------------
@@ -253,8 +254,8 @@ + (NSURLSessionConfiguration *)_urlSessionConfigurationForApplicationId:(NSStrin
253254
- (void)urlSession:(PFURLSession *)session willPerformURLRequest:(NSURLRequest *)request {
254255
[[BFExecutor defaultPriorityBackgroundExecutor] execute:^{
255256
NSDictionary *userInfo = ([PFLogger sharedLogger].logLevel == PFLogLevelDebug ?
256-
@{ PFCommandRunnerNotificationURLRequestUserInfoKey : request } : nil);
257-
[self.notificationCenter postNotificationName:PFCommandRunnerWillSendURLRequestNotification
257+
@{ PFNetworkNotificationURLRequestUserInfoKey : request } : nil);
258+
[self.notificationCenter postNotificationName:PFNetworkWillSendURLRequestNotification
258259
object:self
259260
userInfo:userInfo];
260261
}];
@@ -268,15 +269,15 @@ - (void)urlSession:(PFURLSession *)session
268269
NSMutableDictionary *userInfo = nil;
269270
if ([PFLogger sharedLogger].logLevel == PFLogLevelDebug) {
270271
userInfo = [NSMutableDictionary dictionaryWithObject:request
271-
forKey:PFCommandRunnerNotificationURLRequestUserInfoKey];
272+
forKey:PFNetworkNotificationURLRequestUserInfoKey];
272273
if (response) {
273-
userInfo[PFCommandRunnerNotificationURLResponseUserInfoKey] = response;
274+
userInfo[PFNetworkNotificationURLResponseUserInfoKey] = response;
274275
}
275276
if (responseString) {
276-
userInfo[PFCommandRunnerNotificationURLResponseBodyUserInfoKey] = responseString;
277+
userInfo[PFNetworkNotificationURLResponseBodyUserInfoKey] = responseString;
277278
}
278279
}
279-
[self.notificationCenter postNotificationName:PFCommandRunnerDidReceiveURLResponseNotification
280+
[self.notificationCenter postNotificationName:PFNetworkDidReceiveURLResponseNotification
280281
object:self
281282
userInfo:userInfo];
282283
}];

Parse/PFConstants.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,39 @@ typedef void (^PFStringResultBlock)(NSString *PF_NULLABLE_S string, NSError *PF_
385385
typedef void (^PFIdResultBlock)(PF_NULLABLE_S id object, NSError *PF_NULLABLE_S error);
386386
typedef void (^PFProgressBlock)(int percentDone);
387387

388+
///--------------------------------------
389+
/// @name Network Notifications
390+
///--------------------------------------
391+
392+
/*!
393+
@abstract The name of the notification that is going to be sent before any URL request is sent.
394+
*/
395+
extern NSString *const PF_NONNULL_S PFNetworkWillSendURLRequestNotification;
396+
397+
/*!
398+
@abstract The name of the notification that is going to be sent after any URL response is received.
399+
*/
400+
extern NSString *const PF_NONNULL_S PFNetworkDidReceiveURLResponseNotification;
401+
402+
/*!
403+
@abstract The key of request(NSURLRequest) in the userInfo dictionary of a notification.
404+
@note This key is populated in userInfo, only if `PFLogLevel` on `Parse` is set to `PFLogLevelDebug`.
405+
*/
406+
extern NSString *const PF_NONNULL_S PFNetworkNotificationURLRequestUserInfoKey;
407+
408+
/*!
409+
@abstract The key of response(NSHTTPURLResponse) in the userInfo dictionary of a notification.
410+
@note This key is populated in userInfo, only if `PFLogLevel` on `Parse` is set to `PFLogLevelDebug`.
411+
*/
412+
extern NSString *const PF_NONNULL_S PFNetworkNotificationURLResponseUserInfoKey;
413+
414+
/*!
415+
@abstract The key of repsonse body (usually `NSString` with JSON) in the userInfo dictionary of a notification.
416+
@note This key is populated in userInfo, only if `PFLogLevel` on `Parse` is set to `PFLogLevelDebug`.
417+
*/
418+
extern NSString *const PF_NONNULL_S PFNetworkNotificationURLResponseBodyUserInfoKey;
419+
420+
388421
///--------------------------------------
389422
/// @name Deprecated Macros
390423
///--------------------------------------

Parse/PFConstants.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@
2020
NSString *const kPFParseServer = @"https://api.parse.com";
2121

2222
NSString *const PFParseErrorDomain = @"Parse";
23+
24+
///--------------------------------------
25+
#pragma mark - Network Notifications
26+
///--------------------------------------
27+
28+
NSString *const PFNetworkWillSendURLRequestNotification = @"PFNetworkWillSendURLRequestNotification";
29+
NSString *const PFNetworkDidReceiveURLResponseNotification = @"PFNetworkDidReceiveURLResponseNotification";
30+
NSString *const PFNetworkNotificationURLRequestUserInfoKey = @"PFNetworkNotificationURLRequestUserInfoKey";
31+
NSString *const PFNetworkNotificationURLResponseUserInfoKey = @"PFNetworkNotificationURLResponseUserInfoKey";
32+
NSString *const PFNetworkNotificationURLResponseBodyUserInfoKey = @"PFNetworkNotificationURLResponseBodyUserInfoKey";

Parse/PFNetworkActivityIndicatorManager.m

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

1010
#import "PFNetworkActivityIndicatorManager.h"
1111

12+
#import <Parse/PFConstants.h>
13+
1214
#import "PFApplication.h"
1315
#import "PFCommandRunningConstants.h"
1416

@@ -52,11 +54,11 @@ - (instancetype)init {
5254

5355
[[NSNotificationCenter defaultCenter] addObserver:self
5456
selector:@selector(_handleWillSendURLRequestNotification:)
55-
name:PFCommandRunnerWillSendURLRequestNotification
57+
name:PFNetworkWillSendURLRequestNotification
5658
object:nil];
5759
[[NSNotificationCenter defaultCenter] addObserver:self
5860
selector:@selector(_handleDidReceiveURLResponseNotification:)
59-
name:PFCommandRunnerDidReceiveURLResponseNotification
61+
name:PFNetworkDidReceiveURLResponseNotification
6062
object:nil];
6163

6264
return self;

0 commit comments

Comments
 (0)