1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-14 01:26:05 +01:00
mastodon-app-ufficiale-ipho.../MastodonSDK/Sources/MastodonCore/Service/API/APIService.swift

63 lines
1.9 KiB
Swift
Raw Normal View History

2021-01-28 09:10:30 +01:00
//
// APIService.swift
// Mastodon
//
// Created by sxiaojian on 2021/1/27.
//
import UIKit
2021-01-28 09:10:30 +01:00
import Combine
import CoreData
import CoreDataStack
import MastodonSDK
import AlamofireImage
// import AlamofireNetworkActivityIndicator
2021-01-28 09:10:30 +01:00
public final class APIService {
public static let callbackURLScheme = "mastodon"
public static let oauthCallbackURL = "mastodon://joinmastodon.org/oauth"
2021-01-28 09:10:30 +01:00
var disposeBag = Set<AnyCancellable>()
// internal
let session: URLSession
// input
public let backgroundManagedObjectContext: NSManagedObjectContext
2021-01-28 09:10:30 +01:00
2021-02-03 09:01:08 +01:00
// output
2022-10-08 07:43:06 +02:00
public let error = PassthroughSubject<APIError, Never>()
2021-01-28 09:10:30 +01:00
public init(backgroundManagedObjectContext: NSManagedObjectContext) {
2021-01-28 09:10:30 +01:00
self.backgroundManagedObjectContext = backgroundManagedObjectContext
2024-03-19 16:16:42 +01:00
let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = ["User-Agent" : "mastodon-ios/" + appVersion]
self.session = URLSession(configuration: configuration)
2021-01-28 09:10:30 +01:00
// setup cache. 10MB RAM + 50MB Disk
URLCache.shared = URLCache(memoryCapacity: 10 * 1024 * 1024, diskCapacity: 50 * 1024 * 1024, diskPath: nil)
// enable network activity manager for AlamofireImage
// NetworkActivityIndicatorManager.shared.isEnabled = true
// NetworkActivityIndicatorManager.shared.startDelay = 0.2
// NetworkActivityIndicatorManager.shared.completionDelay = 0.5
UIImageView.af.sharedImageDownloader = ImageDownloader(downloadPrioritization: .lifo)
2021-01-28 09:10:30 +01:00
}
}
extension APIService {
2021-04-01 08:39:15 +02:00
public static let onceRequestStatusMaxCount = 100
public static let onceRequestUserMaxCount = 100
2021-04-29 09:51:52 +02:00
public static let onceRequestDomainBlocksMaxCount = 100
}
2021-01-28 09:10:30 +01:00
extension APIService {
public enum Persist { }
public enum CoreData { }
}