Skip to content

Commit ece2f24

Browse files
bsneedBrandon Sneed
andauthored
Fix for app being terminated due to lingering bg tasks. (#111)
Co-authored-by: Brandon Sneed <[email protected]>
1 parent ce9a9d7 commit ece2f24

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleMonitor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ extension SegmentDestination.UploadTaskInfo {
191191

192192
if let application = UIApplication.safeShared {
193193
let taskIdentifier = application.beginBackgroundTask { [self] in
194-
self.task.suspend()
194+
self.task.cancel()
195195
self.cleanup?()
196196
}
197197
self.taskID = taskIdentifier.rawValue

Sources/Segment/Plugins/SegmentDestination.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ public class SegmentDestination: DestinationPlugin {
128128
}
129129

130130
analytics.log(message: "Processed: \(url.lastPathComponent)")
131+
// the upload we have here has just finished.
132+
// make sure it gets removed and it's cleanup() called rather
133+
// than waiting on the next flush to come around.
134+
self.cleanupUploads()
131135
}
132136
// we have a legit upload in progress now, so add it to our list.
133137
if let upload = uploadTask {

Sources/Segment/Utilities/HTTPClient.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,11 @@ extension HTTPClient {
168168
configuration.allowsCellularAccess = true
169169
configuration.timeoutIntervalForResource = 30
170170
configuration.timeoutIntervalForRequest = 60
171+
configuration.httpMaximumConnectionsPerHost = 2
171172
configuration.httpAdditionalHeaders = ["Content-Type": "application/json; charset=utf-8",
172173
"Authorization": "Basic \(Self.authorizationHeaderForWriteKey(writeKey))",
173174
"User-Agent": "analytics-ios/\(Analytics.version())"]
174-
let session = URLSession.init(configuration: configuration, delegate: nil, delegateQueue: nil)
175+
let session = URLSession(configuration: configuration, delegate: nil, delegateQueue: nil)
175176
return session
176177
}
177178
}

0 commit comments

Comments
 (0)