服务商获取权限失败的话retry,更换了首页的背景图

This commit is contained in:
DDIsFriend
2023-11-21 13:47:33 +08:00
parent cfd5d93c71
commit 11d838906f
28 changed files with 921 additions and 372 deletions

View File

@@ -24,9 +24,9 @@
import Foundation
#if os(iOS) || os(watchOS) || os(tvOS)
#if canImport(MobileCoreServices)
import MobileCoreServices
#elseif os(macOS)
#elseif canImport(CoreServices)
import CoreServices
#endif
@@ -213,7 +213,7 @@ open class MultipartFormData {
// Check 2 - is file URL reachable?
//============================================================
#if !(os(Linux) || os(Windows))
#if !(os(Linux) || os(Windows) || os(Android))
do {
let isReachable = try fileURL.checkPromisedItemIsReachable()
guard isReachable else {
@@ -455,9 +455,11 @@ open class MultipartFormData {
inputStream.open()
defer { inputStream.close() }
while inputStream.hasBytesAvailable {
var buffer = [UInt8](repeating: 0, count: streamBufferSize)
let bytesRead = inputStream.read(&buffer, maxLength: streamBufferSize)
var bytesLeftToRead = bodyPart.bodyContentLength
while inputStream.hasBytesAvailable && bytesLeftToRead > 0 {
let bufferSize = min(streamBufferSize, Int(bytesLeftToRead))
var buffer = [UInt8](repeating: 0, count: bufferSize)
let bytesRead = inputStream.read(&buffer, maxLength: bufferSize)
if let streamError = inputStream.streamError {
throw AFError.multipartEncodingFailed(reason: .inputStreamReadFailed(error: streamError))
@@ -469,6 +471,7 @@ open class MultipartFormData {
}
try write(&buffer, to: outputStream)
bytesLeftToRead -= UInt64(bytesRead)
} else {
break
}
@@ -549,6 +552,19 @@ extension MultipartFormData {
// MARK: - Private - Mime Type
private func mimeType(forPathExtension pathExtension: String) -> String {
#if swift(>=5.9)
if #available(iOS 14, macOS 11, tvOS 14, watchOS 7, visionOS 1, *) {
return UTType(filenameExtension: pathExtension)?.preferredMIMEType ?? "application/octet-stream"
} else {
if
let id = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension as CFString, nil)?.takeRetainedValue(),
let contentType = UTTypeCopyPreferredTagWithClass(id, kUTTagClassMIMEType)?.takeRetainedValue() {
return contentType as String
}
return "application/octet-stream"
}
#else
if #available(iOS 14, macOS 11, tvOS 14, watchOS 7, *) {
return UTType(filenameExtension: pathExtension)?.preferredMIMEType ?? "application/octet-stream"
} else {
@@ -560,6 +576,7 @@ extension MultipartFormData {
return "application/octet-stream"
}
#endif
}
}
@@ -569,7 +586,7 @@ extension MultipartFormData {
// MARK: - Private - Mime Type
private func mimeType(forPathExtension pathExtension: String) -> String {
#if !(os(Linux) || os(Windows))
#if canImport(CoreServices) || canImport(MobileCoreServices)
if
let id = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension as CFString, nil)?.takeRetainedValue(),
let contentType = UTTypeCopyPreferredTagWithClass(id, kUTTagClassMIMEType)?.takeRetainedValue() {