0

I've implemented apple watch app to run independently, So all web services made in Watch itself. It seems to be working fine in watch OS 2 But When request made in watch OS 3 getting Status code as 401.

The flow would be : 1. Making login follwed by get detials web services request in iPhone and share login details to watch app to initiate same request in watch os.

Watch OS 1 & 2.x - No issues Watch OS 3 - Getting sucess for Login request and 401 error for get details service call. Please Note : There is no code change made for Watch OS 2 & 3 , also there is no session mangement handled in back end.

Any body facing same issues or any solution for this ? .

Sugan S
  • 1,782
  • 7
  • 25
  • 47

1 Answers1

2

Finally got solution, after adding the below lines it worked for me.

 if let httpResponse = response as? HTTPURLResponse, let fields = httpResponse.allHeaderFields as? [String : String] {
                    let cookies = HTTPCookie.cookies(withResponseHeaderFields: fields, for: response!.url!)
                    HTTPCookieStorage.shared.setCookies(cookies, for: response!.url!, mainDocumentURL: nil)
                }

I presume Watch OS2 by default manages cookies but Watch OS3 not. So we manually have to store cookies it seems.

Sugan S
  • 1,782
  • 7
  • 25
  • 47
  • Thank you so much for this. I was having this exact same problem and I could not figure out why it would not work. This fixes all of my problems – Rudy B Mar 12 '17 at 18:46
  • saved my day :) – Yonatan Vainer Sep 17 '17 at 15:09
  • Can anyone confirm if this situation with Watch OS 3 + is a known bug? feature? acknowledged new behaviour from Apple ? Is it something we should await for its correction? – Isaac Jul 25 '19 at 07:09