Задать вопрос
  • Как отсылать геолокацию на сервер в фоне?

    @flome1ster Автор вопроса
    Приложение запрашивает разрешение при закрытии на работу в фоне.
    Сам код геолокации
    DeviceLocationService
    Code

    import Combine
    import CoreLocation
    
    class DeviceLocationService: NSObject, CLLocationManagerDelegate, ObservableObject{
        var coordinatesPublisher = PassthroughSubject<CLLocationCoordinate2D, Error>()
        var deniedLocationAccessPublisher = PassthroughSubject<Void, Never>()
        var startTime: Date?
        private override init() {
            super.init()
        }
        static let shared = DeviceLocationService()
        private lazy var locationManager: CLLocationManager = {
            let manager = CLLocationManager()
            manager.desiredAccuracy = kCLLocationAccuracyBest
            manager.delegate = self
            return manager
        }()
        func requestLocationUpdates(){
            switch locationManager.authorizationStatus {
            case.notDetermined:
                locationManager.requestAlwaysAuthorization()
            case.authorizedAlways, .authorizedWhenInUse:
                locationManager.startUpdatingLocation()
            default:
                deniedLocationAccessPublisher.send()
            }
        }
        func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
            switch manager.authorizationStatus{
            case .authorizedWhenInUse, .authorizedAlways:
                manager.startUpdatingLocation()
                
            default:
                manager.stopUpdatingLocation()
                deniedLocationAccessPublisher.send()
            }
        }
        
        func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
            guard let location = locations.last else {return}
            coordinatesPublisher.send(location.coordinate)
            
        }
        func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
            coordinatesPublisher.send(completion: .failure(error))
        }
    }

  • Как организовать сохранение сессии в WKWebView?

    @flome1ster Автор вопроса
    https://stackoverflow.com/a/53512299/19187009 данный код почему-то выдавал ошибку
    "Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value"