Skip to content

Conversation

kmusco-foreflight
Copy link

What and why?

This PR adds a constrainedNetworkUploadsDisabled property which allows users to configure whether or not the SDK blocks uploads on constrained networks. This property defaults to false to keep the existing behavior.

How?

The SDK is already tracking whether or not the network is constrained in NWPathMonitorPublisher and has a mechanism for blocking uploads with DataUploadConditions.blockersForUpload(). This PR updates blockersForUpload() to check the isConstrained network property. If isConstrained is true and the constrainedNetworkUploadsDisabled parameter is true, the upload is blocked.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference
  • Add CHANGELOG entry for user facing changes
  • Add Objective-C interface for public APIs (see our guidelines (internal) and run make api-surface)

@kmusco-foreflight kmusco-foreflight marked this pull request as ready for review June 12, 2025 20:56
Copy link

@moshe-foreflight moshe-foreflight left a comment

Choose a reason for hiding this comment

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

My only feedback is to match the name of Apple's property on URLSession. Otherwise this lgm!

internal struct DataUploadConditions {
enum Blocker {
case battery(level: Int, state: BatteryStatus.State)
case lowDataModeOn

Choose a reason for hiding this comment

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

Precision here to match Apple's API might be a good idea. allowsConstrained... or whatever URLRequest calls it.

Copy link
Author

Choose a reason for hiding this comment

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

Good idea 👍 I renamed this and a few others to better match allowsConstrainedNetworkAccess

case let .battery(level: level, state: state):
return "🔋 Battery state is: \(state) (\(level)%)"
case .lowDataModeOn:
return "🛜 Network is in Low Data Mode and uploads are disabled for constrained networks"

Choose a reason for hiding this comment

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

Nice emoji! 😄


/// Allows uploads on constrained networks
///
/// Defaults to `true` but can be overridden to block uploads on networks with "Low Data Mode" enabled

Choose a reason for hiding this comment

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

Are "block"ed uploads cancelled or deferred? Is that explicitly understood here, or do we want to specify?

Suggested change
/// Defaults to `true` but can be overridden to block uploads on networks with "Low Data Mode" enabled
/// Defaults to `true` but can be overridden to block uploads on networks with "Low Data Mode" enabled.

Copy link
Author

Choose a reason for hiding this comment

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

Blocked uploads are deferred and I updated this comment to make that more clear

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.

2 participants