-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios] Specify custom NSURLSessionDelegate #13491
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@julianrex does the changelogs look good? |
Looks good - thanks @halset! |
NSDictionary *info = [[NSBundle mainBundle] infoDictionary]; | ||
NSString *delegateClassName = [info valueForKey:@"MGLNSURLSessionDelegateClassName"]; | ||
if (delegateClassName) { | ||
sessionDelegate = [[NSClassFromString(delegateClassName) alloc] init]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Would you mind documenting MGLNSURLSessionDelegateClassName
in the following two documents?
https://github.com/mapbox/mapbox-gl-native/blob/master/platform/ios/docs/guides/Info.plist%20Keys.md
https://github.com/mapbox/mapbox-gl-native/blob/master/platform/macos/docs/guides/Info.plist%20Keys.md
Some points that could be covered, since I think this is the first time we’ve introduced an API that represents a class name as a string:
- If the class is implemented in Swift, it needs to bridge to Objective-C.
- The key needs to be set to a runtime class name. (A Swift application would either need to give the class an Objective-C name or set the key to a mangled name.)
- The class should conform to the NSURLSessionDelegate protocol. (Since the protocol’s methods are all optional, we can’t check for conformance at runtime. If the class doesn’t conform to the protocol, there wouldn’t be any adverse effects, but that would probably be a mistake on the part of the developer.)
- See also
MGLOfflineStorageDelegate
. (Like the new Info.plist key, that protocol is used for any request initiated by mbgl but presumably not for Mapbox Telemetry requests, which are handled by a different dependency.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@halset are you planning on updating this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@julianrex I still want this to be merged, but the documentation work suggested by @1ec5 has not bubbled up to the top of my priority list yet. Sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries! Was just checking in 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could add a method mgl_applicationInfoDictionary
to NSBundle+MGLAdditions.m and use that here instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@halset when you're ready for this to be reviewed again, please remove the |
@julianrex Sorry for the delay. I have finally added the Info.plist documentation, but I do not know if I have privileges to remove the |
I have updated this with the latest from #13886. Is that okay or should this be moved from a Info.plist key to something in |
NSURLSessionDelegate is limited, if the backend will require an Authorization header with a |
@fabian-guerra would you mind looking at this PR please, especially in context of your recent changes to @lucianboboc thanks for the link - that's very clear. We realize that this PR is limited in scope, however authentication is something that is on our radar. /cc @tmpsantos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making this change. I'm ok with this current implementation. But now that we have made some changes to expose the network configuration object it may be worth it to consider a different approach.
@@ -69,6 +69,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT | |||
* Points of interest have clearer, localized VoiceOver hints in styles that use version 8 of the Mapbox Streets source. ([#13525](https://github.com/mapbox/mapbox-gl-native/pull/13525)) | |||
* Added `MGLLoggingConfiguration` and `MGLLoggingBlockHandler` that handle error and fault events produced by the SDK. ([#13235](https://github.com/mapbox/mapbox-gl-native/pull/13235)) | |||
* Fixed random crashes during app termination. ([#13367](https://github.com/mapbox/mapbox-gl-native/pull/13367)) | |||
* Specify custom NSURLSessionDelegate with Info.plist key MGLNSURLSessionDelegateClassName. ([#13491](https://github.com/mapbox/mapbox-gl-native/pull/13491)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using verbs at the beginning of the changelog entry use the past tense.
Enclose any class/method/keyword with ``.
This entry should be in the latest version: 4.9.0
@@ -40,6 +40,7 @@ | |||
* Renamed `-[MGLOfflineStorage putResourceWithUrl:data:modified:expires:etag:mustRevalidate:]` to `-[MGLOfflineStorage preloadData:forURL:modificationDate:expirationDate:eTag:mustRevalidate:]`. ([#13318](https://github.com/mapbox/mapbox-gl-native/pull/13318)) | |||
* `MGLMapSnapshotter` now respects the `MGLIdeographicFontFamilyName` key in Info.plist, which reduces bandwidth consumption when snapshotting regions that contain Chinese or Japanese characters. ([#13427](https://github.com/mapbox/mapbox-gl-native/pull/13427)) | |||
* Added `MGLLoggingConfiguration` and `MGLLoggingBlockHandler` that handle error and fault events produced by the SDK. ([#13235](https://github.com/mapbox/mapbox-gl-native/pull/13235)) | |||
* Specify custom NSURLSessionDelegate with Info.plist key MGLNSURLSessionDelegateClassName. ([#13491](https://github.com/mapbox/mapbox-gl-native/pull/13491)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
// app might provide a NSURLSessionDelegate for authentication and such | ||
id<NSURLSessionDelegate> sessionDelegate = nil; | ||
NSDictionary *info = [[NSBundle mainBundle] infoDictionary]; | ||
NSString *delegateClassName = [info valueForKey:@"MGLNSURLSessionDelegateClassName"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that MGLNetworkConfiguration
is public what do you think if instead of reading a class from the Info file we register the class in the network configuration singleton?
- Reading from the plist file is a bit hidden.
- This way it's clear where to look if anyone requires custom authentication.
- It's safer instantiating a class than parsing first a string.
This pull request has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
Re-opening: @halset do you have any feedback on @fabian-guerra's comment above about using |
@julianrex Looking at @fabian-guerra's comment, this pull-request has probably been out-dated by the |
This is an attempt to solve #11888 by letting the app provide a custom NSURLSessionDelegate by setting "MGLNSURLSessionDelegateClassName" in Info.plist.
My main motivation for doing this is to be able to use tile services that uses HTTP Basic Authentication.