Skip to content

Added NSNotifications being posted on every network request being sent/finished. #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2015

Conversation

nlutsenko
Copy link
Contributor

This is required #74

  • Added delegate to PFURLSession
  • Updated Tests
  • Added NSNotification posting whenever the request will be sent/finished.

Review on Reviewable

@richardjrossiii
Copy link
Contributor

I'm not super happy about using the default NSNotificationCenter everywhere. Thoughts on having a Parse-specific dependency-injected one? It would make testing/mocking better I think.

@protocol PFURLSessionDelegate <NSObject>

- (void)urlSession:(PFURLSession *)session willPerformURLRequest:(NSURLRequest *)request;
- (void)urlSession:(PFURLSession *)session didPerformURLRequest:(NSURLRequest *)request withURLResponse:(nullable NSURLResponse *)response;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we fail below the protocol level (e.g. user switches wifi off), this will be called without a URL Response, and no way to get the error out. Thoughts on having a way to get the underlying network error if one exists here?

There's also no good way to track cancelled requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this specific case - we don't really care about the result/error/cancellation, only about when the request is about to be sent and when request succeeded.
We don't really need an error right now, or a result, or cancelled status - that's why these are not implemented.

We can expand from here though at any given point of time.

@nlutsenko
Copy link
Contributor Author

Parse-specific - not really
Dependency-injected - sure

Will update in a bit.

@nlutsenko nlutsenko force-pushed the nlutsenko.notifications branch 2 times, most recently from 3433a9b to b1b1abd Compare August 21, 2015 19:26
@@ -49,11 +55,12 @@ - (instancetype)initWithDataSource:(id<PFInstallationIdentifierStoreProvider>)da
clientKey:(NSString *)clientKey {
NSURLSessionConfiguration *configuration = [[self class] _urlSessionConfigurationForApplicationId:applicationId
clientKey:clientKey];
PFURLSession *session = [PFURLSession sessionWithConfiguration:configuration];
PFURLSession *session = [PFURLSession sessionWithConfiguration:configuration delegate:self];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bad. Self may be re-assigned by init, and then we have a dead delegate value. We should think about how to improve this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, the possibility of that happening is really really close to 0, so better testability (with injected everything) vs rare edge case scenario.

nlutsenko added a commit that referenced this pull request Aug 21, 2015
Added NSNotifications being posted on every network request being sent/finished.
@nlutsenko nlutsenko merged commit a08ca14 into master Aug 21, 2015
@nlutsenko nlutsenko deleted the nlutsenko.notifications branch August 21, 2015 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants