0

I have a quite ugly problem with a subclassed UIWebView which is maintaining a user's web session with an online backend server, that will communicate with a session object, while the user is logged in to a specific service. From time to time, my app runs a data update service on a background thread with GDC and uses NSURLSessionDataTask to perform backend requests.

The background thread work somehow corrupts the web session object maintained by the UIWebView. In my understanding, that means that the NSHTTPCookieStorage gets corrupted … I don't know this exactly.

I think it would help, if the session maintained by the UIWebView would be shared with any other request done by a NSURLSessionDataTask running in any other thread.

In the past I suppressed the calls to the NSURLSessionDataTask work while the UIWebView session is active - but it seems that under some circumstances one of these calls still come through.

My question though is: How can I share the same session space used by the UIWebView with the NSURLSessionDataTask activities?

Unfortunately, due to the complexity of both implementations, I can't supply sample code…

konran
  • 588
  • 7
  • 20
  • Are you sure the cookie storage is getting corrupted? Did you compare the `NSHTTPCookieStorage.sharedHTTPCookieStorage.cookies` array before (when it's still working) and after (when it doesn't anymore)? – izerik Mar 22 '17 at 19:46
  • @izerik, once I've tested it, the NSHTTPCookieStorage.sharedHTTPCookieStorage.cookies in the global queue were empty while the main thread's values of this array used by the UIWebView had the correct data. That was weird, as I assumed that the shared storage is a singleton that should deliver the same data … maybe it's not thread safe? – konran Mar 23 '17 at 09:08

1 Answers1

0

It mostly seems, that calling [NSURLSessionConfiguration defaultSessionConfiguration] as the web session used for the NSURLSessionDataTask breaks into the data of the UIWebView … at least it gets corrupted then and is no longer usable.

Using [NSURLSessionConfiguration ephemeralSessionConfiguration] instead does the trick and UIWebView's data stay intact pretty well.

konran
  • 588
  • 7
  • 20