NSURLConnection delegate methods are not called

后端 未结 4 742
借酒劲吻你
借酒劲吻你 2020-12-04 17:51

I am trying to create a simple NSURLConnection to communicate with a server using a GET request. Connection works well, but delegates methods of NSURLConnection are never ca

相关标签:
4条回答
  • 2020-12-04 17:55

    Are you calling this on a background thread? If you are performing this on a background thread, the thread is probably exiting before the delegates can be called.

    0 讨论(0)
  • 2020-12-04 18:04

    Try running the operation on main thread:

    NSURLConnection * connection = [[NSURLConnection alloc] 
                                    initWithRequest:request
                                           delegate:self startImmediately:NO];
    
    [connection scheduleInRunLoop:[NSRunLoop mainRunLoop] 
                          forMode:NSDefaultRunLoopMode];
    [connection start];
    
    0 讨论(0)
  • 2020-12-04 18:10

    Try to check length for the received response it should not getting 0 byte of data.

    0 讨论(0)
  • 2020-12-04 18:17

    Apart from checking if the request is called from the main thread, you can check if you give back execution time to the system (if you exit "main"). I had some test code that would stay in a loop until the delegate was called : it would never be called, because the system needs to do stuff in order for the delegate to be called, in the main thread.

    0 讨论(0)
提交回复
热议问题