0

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)
    }
}
Miki
  • 903
  • 7
  • 26
Ghulam Rasool
  • 3,996
  • 2
  • 27
  • 40
  • 1
    @nebiros yes I have fixed it. Actually my main thread was held every time. And it causes the hold of all other threads. But I thought that it might be the issue in Xcode or network calls etc. When the app hangs, pause the app and check where the main thread is. – Ghulam Rasool Aug 30 '19 at 07:42
  • thanks for you answer, we have seen a main thread issue but with core motion, at Xcode 10, dunno why Xcode 11 doesn't catch that – nebiros Aug 30 '19 at 15:09
  • @nebiros yes, I had the same issue. It was working fine on iOS 13 simulator with Xcode 10 but not with Xcode 11. Strange – Ghulam Rasool Sep 02 '19 at 09:14

2 Answers2

5

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 :)

Ghulam Rasool
  • 3,996
  • 2
  • 27
  • 40
0

This sounds like an iOS 13 beta bug. You can report it here https://developer.apple.com/bug-reporting/

User123335511231
  • 11,654
  • 4
  • 18
  • 22