zoukankan      html  css  js  c++  java
  • Why NSAttributedString import html must be on main thread?

    The HTML importer should not be called from a background thread (that is, the options dictionary includesNSDocumentTypeDocumentAttribute with a value of NSHTMLTextDocumentType). It will try to synchronize with the main thread, fail, and time out. Calling it from the main thread works (but can still time out if the HTML contains references to external resources, which should be avoided at all costs). The HTML import mechanism is meant for implementing something like markdown (that is, text styles, colors, and so on), not for general HTML import.

    Multicore considerations: 

    Since OS X v10.4, NSAttributedString has used WebKit for all import (but not for export) of HTML documents. Because WebKit document loading is not thread safe, this has not been safe to use on background threads. For applications linked on OS X v10.5 and later, if NSAttributedString imports HTML documents on any but the main thread, the use of WebKit is transferred to the main thread via performSelectorOnMainThread:withObject:waitUntilDone:. This makes the operation thread safe, but it requires that the main thread be executing the run loop in one of the common modes. This behavior can be overridden by setting the value of the standard user default NSRunWebKitOnAppKitThread to either YES(to obtain the new behavior regardless of linkage) or NO (to obtain the old behavior regardless of linkage).


    在主线程中加载的网页如果很大,就会很慢 ,唉,在做时尚周刊时,那里面加载了html页面,不知道core text怎么样,没试过。

  • 相关阅读:
    阅读13-17章
    阅读<构建之法>10、11、12章
    作业5.2
    作业5.1
    作业四:构建之法的困惑和思考(5-7)
    做汉堡
    作业三:构建之法的困惑和思考(1-5)
    实验二 合作:王宏财 http://www.cnblogs.com/wanghongcai/
    实验一--四则运算
    数独九宫格
  • 原文地址:https://www.cnblogs.com/ioriwellings/p/3556990.html
Copyright © 2011-2022 走看看