Sharing Session in App and in webview inside the app - IOS Swift -


hi have ios application written in swift has login , after successful login app segues activity has webview.

the app , website shares same api. process of login when supply correct username , password api return token

i managed app login correctly using alamofire framework http request

alamofire.request(.post, url, parameters: param).responsejson{ (request, response, jsondata, error) in             if error != nil {                 let result = ["error" : "unexpected error!"]                 callback(result: result)             } else {                 if response?.statuscode == 401 {                           println(401)                         let result = ["error" : "user not found!"]                         callback(result: result)                   } else if response?.statuscode == 200 {                     let responsedict = jsondata as! nsdictionary                     callback(result:responsedict)                 }             }         } 

and displaying of webview code

let requesturl = nsurl(string: "myurl") let request = nsmutableurlrequest(url: requesturl!)  webview.loadrequest(request) 

i need display website inside webview it's happening need share session webview since share same api app.

could me? how achieve this.

if want pass token body request can below.it in objective c,convert swift.

nsurl *url = [nsurl urlwithstring: @"http://your_url.com"]; nsstring *body = [nsstring stringwithformat: @"token=%@",vartoken]; nsmutableurlrequest *request = [[nsmutableurlrequest alloc]initwithurl: url]; [request sethttpmethod: @"post"]; [request sethttpbody: [body datausingencoding: nsutf8stringencoding]]; [webview loadrequest: request]; 

Comments