Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Adds NSURLSession delegate to MGLNetworkConfiguration #228

Merged
merged 16 commits into from
Mar 27, 2020

Conversation

julianrex
Copy link
Contributor

@julianrex julianrex commented Mar 18, 2020

Depends on #242

This PR adds an undocumented MGLNetworkConfigurationSessionDelegate and a id delegate property to MGLNetworkConfiguration.

This allows the application to provide an NSURLSession object, which will be used instead of one being created using the existing sessionConfiguration property. It is the developer's responsibility to maintain the life (and reuse) the session object. It's also important to note that the delegate method does not get called on the main thread.

Background sessions are not supported, and an exception will fire if one is supplied - this exception is provided by the OS.

The existing sessionConfiguration behavior remains unchanged.

To enable these changes, the PR also includes:

  • Removal of MGLNetworkIntegrationManager (non-public type) - this was just acting as a go-between, as was superfluous.
  • Addition of MGLIntegrationTestCase to share existing testing functionality.

TODO:

  • Integration tests
  • update/test macOS

See also these changes in gl-native, which this PR depends on.

@julianrex
Copy link
Contributor Author

cc @halset (who proposed a session delegate PR).

Copy link
Contributor

@knov knov left a comment

Choose a reason for hiding this comment

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

needs tests

@halset
Copy link
Contributor

halset commented Mar 24, 2020

@julianrex Thanks for the cc! Should probably recreate the NSURLSessionDelegate-PR after this is merged to be able to set a NSURLSessionDelegate or will this PR handle that as well?

@julianrex
Copy link
Contributor Author

@halset I'm thinking this PR would make the existing session delegate PR redundant.

Note this is still just an experiment, and we may end up adding a delegate for MGLNetworkConfiguration which I think would be more idiomatic.

@julianrex julianrex requested review from knov and jmkiley and removed request for tmpsantos and zugaldia March 25, 2020 19:20
@julianrex julianrex changed the title Adds "private" NSURLSession to MGLNetworkConfiguration Adds NSURLSession delegate to MGLNetworkConfiguration Mar 25, 2020
@julianrex julianrex marked this pull request as ready for review March 25, 2020 19:47
@julianrex julianrex requested a review from a team March 25, 2020 19:47
Copy link
Contributor

@fabian-guerra fabian-guerra left a comment

Choose a reason for hiding this comment

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

Build issues aside. LGTM I left minor comments. Thank you.

platform/darwin/src/MGLNetworkConfiguration.m Outdated Show resolved Hide resolved
platform/darwin/src/MGLNetworkConfiguration.m Outdated Show resolved Hide resolved
1ec5
1ec5 previously requested changes Mar 26, 2020
Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

Is it possible to split out the build system changes into a separate PR? It isn’t clear to me how they relate to MGLNetworkConfiguration.

platform/darwin/darwin.xcconfig Outdated Show resolved Hide resolved
platform/macos/src/MGLMapView.mm Outdated Show resolved Hide resolved
Copy link
Contributor

@captainbarbosa captainbarbosa left a comment

Choose a reason for hiding this comment

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

@julianrex and I went over these changes over the phone.

👍 from me, but echoing @1ec5's comments about the build changes being broken out in another PR if possible.

platform/darwin/src/MGLNetworkConfiguration.h Outdated Show resolved Hide resolved
@@ -34,26 +40,46 @@ + (instancetype)sharedManager {
_sharedManager = [[self alloc] init];
});

[self setNativeNetworkManagerDelegateToDefault];
// Notice, this is reset for each call. This is primarily for testing purposes.
// TODO: Consider only calling this for testing?
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this to-do still relevant? (×2)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll create a new ticket to track this.

platform/darwin/src/MGLNetworkConfiguration.h Outdated Show resolved Hide resolved
platform/darwin/src/MGLNetworkConfiguration.h Outdated Show resolved Hide resolved
@@ -23,12 +49,14 @@ MGL_EXPORT
If this property is set to nil or if no session configuration is provided this property
is set to the default session configuration.

Assign this object before instantiating any `MGLMapView` object.
Assign this object before instantiating any `MGLMapView` object, or using
`MGLOfflineStorage`
Copy link
Contributor

Choose a reason for hiding this comment

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

What’s an example of a place where this object can be assigned safely? Consider that fixing #227 may require us to invoke +[MGLOfflineStorage sharedStorage] in an +initialize method.

Copy link
Contributor Author

@julianrex julianrex Mar 26, 2020

Choose a reason for hiding this comment

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

Ugh. Let's address that when we fix #227. Hopefully we can find a way around without having to use an +initialize.

@julianrex julianrex dismissed 1ec5’s stale review March 26, 2020 20:17

Build changes were refactored into #242

@julianrex
Copy link
Contributor Author

When merged, the commit will need to be cherry-picked to release-vanillashake

@julianrex julianrex added this to the release-vanillashake milestone Mar 26, 2020
Copy link
Contributor

@halset halset left a comment

Choose a reason for hiding this comment

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

I have tested this with a tile source that uses HTTP Basic Authentication by using a NSURLSession with a custom NSURLSessionDelegate. It works fine! So for me, this can replace my original PR. Thank you for the good work!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request skip-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants