数据更新重新安装App(Swift)

时间:2017-09-18 08:24:38

标签: ios rest web-services swift3 xcode8

我使用Bussiness Manager&下载管理器从Web服务获取数据。直到应用程序将在设备上重新安装,数据才会在整个应用程序上更新。我也使用viewDidAppear方法,但它也无法正常工作。这是一个严重的问题,请帮助我分享你的经验。谢谢你提前

业务经理方法

     class func downloadDataFromServer(_ parameter:String , urlString: String) ->NSDictionary
     {

    let urlRequest = NSMutableURLRequest()
    urlRequest.url = URL(string: urlString)
    urlRequest.setValue("application/json; charset=utf-8", forHTTPHeaderField:"Content-Disposition")
    urlRequest.httpMethod = "POST"

    let data = (parameter as NSString).data(using: String.Encoding.utf8.rawValue)
    urlRequest.httpBody = data

    var Error:NSError? = nil

    var returnData: Data?
    do {
        returnData = try NSURLConnection.sendSynchronousRequest(urlRequest as URLRequest, returning: nil)


    } catch let error as NSError {
        Error = error
        returnData = nil
   }

    if(Error == nil)
    {
        return self.validateResponds(returnData!)
    }
    let errorResult:NSDictionary = [
        "status" : "401",
        "message" : "Error message"
    ]

    return errorResult
}

下载管理员方法

    override func viewDidAppear(_ animated: Bool) {
    let data = UserDefaults.standard.object(forKey: kUserDetails) as! Data
    let userDic = NSKeyedUnarchiver.unarchiveObject(with: data) as! NSDictionary
    userIDStr = userDic.value(forKey: "customer_id") as! String

    print(userIDStr)

    BusinessManager.getProfileInformation(userIDStr, completionHandler: { (result) -> () in
        print(result)

        //        print(self.addressAry)
                    self.addressAry = result.value(forKey: "customer_address") as!
        NSMutableArray
                    self.tableView.reloadData()

                    let tempData = NSKeyedArchiver.archivedData(withRootObject: self.addressAry)
                    UserDefaults.standard.set(tempData, forKey: kAddToWishlist)

    })
}

她是我的viewDidAppear方法


<kendo-grid-column @click="clicked"></kendo-grid-column>

2 个答案:

答案 0 :(得分:0)

最后我找到了答案,我使用代码清除了整个App和Thats工作的清除cookie和缓存。感谢您的贡献

答案 1 :(得分:0)

我认为您应该使用此代码清除Cookie和缓存。

 URLCache.shared.removeAllCachedResponses()

    if let cookies = HTTPCookieStorage.shared.cookies {
        for cookie in cookies {
            HTTPCookieStorage.shared.deleteCookie(cookie)
        }
    }