app和js的交互,自动登录

//////////////////////////===webview界面

       //创建webView

       self.webView.frame = self.view.bounds

       self.view.addSubview(self.webView)

       let reqeust = NSMutableURLRequest(URL: NSURL(string: url)!)

       reqeust.setValue("\(tickets)", forHTTPHeaderField: "userTicket")

      webView.loadRequest(reqeust)

////////////////====appdelegate界面

   func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

self.setuserAgen()

}

  func setuserAgen(){

       let webview = UIWebView(frame: CGRectZero)

       let secretAgent = webview.stringByEvaluatingJavaScriptFromString("navigator.userAgent")

       let newUagent = NSString(string: "\(secretAgent) YclBrowser/1.0")

       let dictionary = NSDictionary(object: newUagent, forKey: "UserAgent")

       NSUserDefaults.standardUserDefaults().registerDefaults(dictionary as! [String : AnyObject])

   }

你可能感兴趣的:(app和js的交互,自动登录)