1

Now I can use the following method UIWebView display a webpage and get the page's html file length correctly.

    let urlAsString = "http://www.yahoo.com"
    let testurls = NSURL(string: urlAsString)
    let session_config = NSURLSessionConfiguration.defaultSessionConfiguration()
    let mysession = NSURLSession(configuration: session_config, delegate: self, delegateQueue: NSOperationQueue.mainQueue())

    tv_statusinfo.text = ""
    if let v = testurls
    {

        let mytask = mysession.dataTaskWithURL(v, completionHandler: nil
        mytask.resume()

    }

func URLSession(session: NSURLSession,
     dataTask: NSURLSessionDataTask,
    didReceiveData data: NSData)
{
    totallength += data.length
    pagedata.appendData(data)
    println("data length:\(data.length)")
    self.mywebview.loadData(pagedata, MIMEType: currentresponse.MIMEType, textEncodingName: currentresponse.textEncodingName, baseURL: currentresponse.URL)

    timeused = NSDate().timeIntervalSince1970 -  starttime
    println("timeused = \(timeused)")
}

The next step is : 1,I want get the number of resource file numbers such as how many png files and how many css files etc. 2, I want know the total length of the resource files. I have no idea about those two problems. since the I cannot get the session delegate after the UIWebview load data. please help me, thanks.

Victor LI
  • 31
  • 3

0 Answers0