Good Morning ,
We have 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 we are getting Status code as 401. Any body facing same issues or any solution for this ? .
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 in back end.
Sample Source as below
func makeServiceCallNative(withURL urlStr:String ,withHTTPMethod method:String, withBodyContent bodyContent : NSDictionary? ,withHeaderFields headerFields : NSDictionary?,withSuccessBlock:(successBlock), withFailureBlock:(failureBlock) ,withSessionFailureBlock:(sessionfailureBlock))
{
let url = NSURL(string: urlStr)
let request:NSMutableURLRequest = NSMutableURLRequest(URL: url!)
request.HTTPMethod = method
if bodyContent != nil
{
do {
let data = try NSJSONSerialization.dataWithJSONObject(bodyContent!, options: [])
request.HTTPBody = data
}
catch let error as NSError {
print("json error: \(error.localizedDescription)")
}
}else if headerFields != nil
{
request.allHTTPHeaderFields = headerFields! as? [String : String]
}
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.timeoutIntervalForRequest = 30
let urlSession = NSURLSession.init(configuration: configuration)
let task = urlSession.dataTaskWithRequest(request) { (data : NSData?, response :NSURLResponse?, error :NSError?) -> Void in
if error != nil {
withFailureBlock!(error: error)
}else if error == nil && data != nil && response != nil{
do {
let jsonResult: NSDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as! NSDictionary
if let responseDict:NSDictionary = jsonResult{
/
if let errorCode = responseDict["errorCode"] as? Int{
if errorCode == TOKEN_CREATION_ERROR{
withSessionFailureBlock!()
}
else{
withSuccessBlock!(responseData: responseDict , response: response!)
}
}
else{
withSuccessBlock!(responseData: responseDict , response: response!)
}
}
}
catch let parseError as NSError{
if let dataSrt = String(data: data!, encoding: NSUTF8StringEncoding){
/
/
if dataSrt == GlobalConstants.invalid_Session_Error_Message{
withSessionFailureBlock!()
}
else{
withSuccessBlock!(responseData: dataSrt , response: response!)
}
}
else{
withFailureBlock!(error: parseError)
}
/
/
/
}
}
else{
withFailureBlock!(error: nil)
}
}
task.resume()
}