func getUserDataFromTwitterWithUser(user : PFUser) {//NRLoader.showLoader()let strTwURL = "https://API.twitter.com/1.1/users/show.Json? screen_name="+PFTwitterUtils.twitter()!.screenname! + "&access_token="+PFTwitterUtils.twitter()!.authToken!let twURL = NSURL (string: strTwURL)let request = NSMutableURLRequest(URL: twURL!,cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy,timeoutInterval: 2.0) as NSMutableURLRequestPFTwitterUtils.twitter()?.signRequest(request)let session = NSURLSession.sharedSession()session.dataTaskWithRequest(request,completionHandler: {(data,response,error) in if error == nil { var Jsonoptional = Dictionary<String,AnyObject>() do { Jsonoptional = try NSJsONSerialization.JsONObjectWithData(data!,options:NSJsONReadingOptions.MutableContainers ) as! Dictionary<String,AnyObject> // use JsonData } catch { // report error } var username = "" if let screenname = Jsonoptional["screen_name"] as? String{ username = screenname } else if let name = Jsonoptional["name"] as? String{ username = name } var profilePicUrl = "" if let picUrl = Jsonoptional["profile_image_url"] as? String{ profilePicUrl = picUrl } AppUser.currentUser()?.username = username AppUser.currentUser()?.profileAwsURL = profilePicUrl //NRLoader.hIDeLoader() //if ParseUtils.isLoggedInUserIsAnonymous() { let signUpVC:SignmeUpVIEwController = self.storyboard!.instantiateVIEwControllerWithIDentifIEr("SignmeUpVIEwController") as! SignmeUpVIEwController signUpVC.isFromLogin = true self.navigationController!.pushVIEwController(signUpVC,animated: true) //} else { // self.pushTosubmitDreamVIEwController() //} } else { //NRLoader.hIDeLoader() NRToast.showToastWithMessage(error!.description) }}).resume() }解决方法 dataTaskWithRequest调用在后台运行,然后从同一个线程调用完成处理程序.更新UI的任何内容都应该在主线程上运行,因此所有当前的处理程序代码都应该在dispatch_async中回到主队列中:
dispatch_async(dispatch_get_main_queue()) { // Do stuff to UI}
斯威夫特3:
dispatchQueue.main.async() { // Do stuff to UI}
因此,理想情况下,如果error == nil,当前所有代码都应该在另一个函数中关闭,比如称为handleRequest,因此您当前的代码变为:
session.dataTaskWithRequest(request,error) in if error == nil { dispatch_async(dispatch_get_main_queue(),{ self.handleRequest(...)I }) }总结
以上是内存溢出为你收集整理的xcode – 此应用程序正在从后台线程修改autolayout引擎,这可能导致引擎损坏全部内容,希望文章能够帮你解决xcode – 此应用程序正在从后台线程修改autolayout引擎,这可能导致引擎损坏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)