Skip to content
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

Stop location monitoring when app goes to background for usages that don't require 'always' permission #64

Merged
merged 7 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
--disable redundantSelf
--disable unusedArguments
--indentcase true
--disable preferForLoop

# Don't format generated files
--exclude **/Strings+Generated.swift
5 changes: 2 additions & 3 deletions Sources/UBFoundation/Networking/AutoRefreshCacheLogic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import OSLog

@available(iOS 14.0, watchOS 7.0, *)
fileprivate struct Log {
private struct Log {
static let logger = Logger(subsystem: "UBKit", category: "AutoRefreshCacheLogic")
}

Expand Down Expand Up @@ -47,8 +47,7 @@ open class UBAutoRefreshCacheLogic: UBBaseCachingLogic {
if #available(iOS 14.0, watchOS 7.0, *) {
if let task {
Log.logger.trace("Start cron refresh for task \(task)")
}
else {
} else {
Log.logger.trace("Not start cron refresh, task doesn't exist anymore.")
}
}
Expand Down
1 change: 0 additions & 1 deletion Sources/UBFoundation/Networking/CachingLogic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public enum UBCacheResult {

/// A caching logic object can provide decision when comes to requests and response that needs caching
public protocol UBCachingLogic {

/// Modify the request before starting
/// Allows to change the cache policy
func prepareRequest(_ request: inout URLRequest)
Expand Down
24 changes: 12 additions & 12 deletions Sources/UBFoundation/Networking/Networking+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,27 @@ extension UBNetworkingError: UBCodedError {
}
}

extension UBNetworkingError {
public var errorDescription: String? {
public extension UBNetworkingError {
var errorDescription: String? {
switch self {
case .notConnected:
return NSLocalizedString("error_timeout", bundle: Bundle.module, comment: "Connection to the server failed")
case .timedOut:
return NSLocalizedString("error_timeout", bundle: Bundle.module, comment: "The request timed out")
case .certificateValidationFailed:
return NSLocalizedString("error_invalid_certificate_message", bundle: Bundle.module, comment: "Validation of TLS certificate failed")
default:
return NSLocalizedString("error_unexpected", bundle: Bundle.module, comment: "Generic unexpected error message")
case .notConnected:
return NSLocalizedString("error_timeout", bundle: Bundle.module, comment: "Connection to the server failed")
case .timedOut:
return NSLocalizedString("error_timeout", bundle: Bundle.module, comment: "The request timed out")
case .certificateValidationFailed:
return NSLocalizedString("error_invalid_certificate_message", bundle: Bundle.module, comment: "Validation of TLS certificate failed")
default:
return NSLocalizedString("error_unexpected", bundle: Bundle.module, comment: "Generic unexpected error message")
}
}

public var localizedDescription: String {
var localizedDescription: String {
var errorMessage = NSLocalizedString("error_unexpected", bundle: Bundle.module, comment: "Generic unexpected error message")
if let description = errorDescription {
errorMessage = description
}
let errorCodePrefix = NSLocalizedString("error_code_prefix", bundle: Bundle.module, comment: "Prefix of error code")

return "\(errorMessage)\n\n\(errorCodePrefix) \(errorCode)"
}
}
Expand Down
28 changes: 14 additions & 14 deletions Sources/UBFoundation/Networking/UBURLDataTask+Decoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

#if canImport(UIKit)
import UIKit
import UIKit
#endif

/// An object that can decode data into the desired type
Expand Down Expand Up @@ -106,22 +106,22 @@ public extension UBURLDataTaskDecoder where T: Decodable {
}

#if canImport(UIKit)
public class UBImageDecoder: UBURLDataTaskDecoder<UIImage> {
/// Initializes the decoder
///
/// - Parameter scale: Use 2 or 3 to create images with more pixels than points
public init(scale: Double = 1) {
super.init { data, _ -> UIImage in
guard let image = UIImage(data: data, scale: scale) else {
throw UBInternalNetworkingError.couldNotDecodeBody
public class UBImageDecoder: UBURLDataTaskDecoder<UIImage> {
/// Initializes the decoder
///
/// - Parameter scale: Use 2 or 3 to create images with more pixels than points
public init(scale: Double = 1) {
super.init { data, _ -> UIImage in
guard let image = UIImage(data: data, scale: scale) else {
throw UBInternalNetworkingError.couldNotDecodeBody
}
return image
}
return image
}
}
}

public extension UBURLDataTaskDecoder where T == UIImage {
static let image = UBImageDecoder()
}
public extension UBURLDataTaskDecoder where T == UIImage {
static let image = UBImageDecoder()
}

#endif
2 changes: 1 addition & 1 deletion Sources/UBFoundation/Networking/UBURLDataTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public final class UBURLDataTask: UBURLSessionTask, CustomStringConvertible, Cus
requestStartSemaphore.wait()
dataTask?.cancel()
requestStartSemaphore.signal()

switch state {
case .initial, .parsing, .finished, .cancelled:
break
Expand Down
5 changes: 2 additions & 3 deletions Sources/UBFoundation/Networking/UBURLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ public class UBURLSession: UBDataTaskURLSession {
guard let cacheResult else {
return createTask(request.getRequest())
}

if owner.flags.contains(.refresh) {
var reloadRequest = request.getRequest()
for header in cacheResult.reloadHeaders {
reloadRequest.setValue(header.value, forHTTPHeaderField: header.key)
}
return createTask(reloadRequest, cachedResponse: cacheResult.cachedResponse)
}
else if owner.flags.contains(.ignoreCache) {
} else if owner.flags.contains(.ignoreCache) {
return createTask(request.getRequest(), cachedResponse: nil)
}

Expand Down
Loading
Loading