Search code examples
iosswiftxcodeios13xcode11

App stuck on iOS 13 beta simulator with Xcode 11 beta but working fine on iOS 13 beta simulator with Xcode 10


I am facing a very strange problem. At the start of the app, I call API to get the token. It was working fine till iOS 12. But, on iOS 13 beta version, the completion closure is not called and app keep on accumulating memory and finally crashes.

However, when I run the same code from Xcode 10 to iOS 13 beta simulator, it works fine.

I am attaching the code through which I call API, please help me.

This is the function where I don't get the completion handler and the control just lost.

@discardableResult
static func requestObject<T: Decodable>(urlRequest: URLRequest, sessionManager: SessionManager? = nil, keyPath: String? = nil, decoder: JSONDecoder = JSONDecoder(), queue: DispatchQueue? = nil, completion: @escaping (NetworkResult<T>) -> Void) -> URLSessionTask? {

    let request = self.request(urlRequest: urlRequest, sessionManager: sessionManager)
        .responseDecodableObject(decoder: decoder, keyPath: keyPath, queue: queue) { (response: DataResponse<T>) in

            switch response.result {
            case .failure(let error):    completion(NetworkResult.failure(error))
            case .success(let value):    completion(NetworkResult.success(value))
            }
    }

    return request.task
}

And this is the request function that I call.

static func request(urlRequest: URLRequest, sessionManager: SessionManager?) -> DataRequest {

    guard let sessionManager = sessionManager else {
        return Alamofire.request(urlRequest)
            .validate { (request, response, data) -> Request.ValidationResult in
                return self.validation(request: request, response: response, data: data)
        }
    }

    return sessionManager.request(urlRequest)
        .validate { (request, response, data) -> Request.ValidationResult in
            return self.validation(request: request, response: response, data: data)
    }
}

Solution

  • Found the solution, finally :)

    Actually my main thread was blocked and it was blocking all other threads and the app keep on accumulating memory. I was using third party label, which caused that issue.

    Here is the code that was responsible for the issue.

    override func layoutSubviews() {
        super.layoutSubviews()
        self.frame = self.frame.insetBy(dx: 0, dy: -3)
    }
    

    Till iOS 12, it was working fine. But it was holding the main thread in iOS 13 and causes the application to crash after gathering too much memory.

    I removed the frame update code from layoutsubviews and every thing was working :)