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怎么样,没试过。

Why NSAttributedString import html must be on main thread?的更多相关文章

  1. main thread starting…

    例的结果,下面的: main thread starting- Thrad 2 staring- Thrad 2 end- Thrad 4 staring- Thrad 4 end- Thrad 1 ...

  2. tensorflow_目标识别object_detection_api,RuntimeError: main thread is not in main loop,fig = plt.figure(frameon=False)_tkinter.TclError: no display name and no $DISPLAY environment variable

    最近在使用目标识别api,但是报错了: File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/script_o ...

  3. Sub Thread to update main Thread (UI) 2

    Sub Thread to update main Thread (UI)  2 Handler.post(somethread); Handler.sendMessage("Msg&quo ...

  4. Sub Thread to update main Thread (UI)

    Sub Thread to update main Thread (UI) main Thread :   A  has Hander.HandleMessage() to process the & ...

  5. celery 错误相关:Monkey-patching not on the main thread; threading.main_thread().join() will hang from a greenlet

    /Users/wangpingyang/.pyenv/versions/3.7.2/lib/python3.7/site-packages/httprunner/__init__.py:5: Monk ...

  6. 13、主线程任务太多导致异常退出(The application may be doing too much work on its main thread)

    今天花费了一天的时间来解决这个bug. 这种在程序运行期间出现的问题比较棘手,如果再没有规律的话就更难解决. 还好这个bug是由规律的,也就是说在程序执行半个小时左右后就会因为此异常而导致程序退出:那 ...

  7. reloadData should be in main thread

    reloadData should be called in main thread, so if you call it in work thread, you should call it as ...

  8. APP崩溃提示:This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.

    崩溃输出日志 2017-08-29 14:53:47.332368+0800 HuiDaiKe[2373:1135604] This application is modifying the auto ...

  9. Ajax.html:35 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org

    AJAX的容易错误的地方 Ajax.html:35 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated ...

随机推荐

  1. sql函数PadLeft与PadRight代码实例

    1.PadLeft函数向已知字符串左边补充字符,使整个字符串到达指定长度 CREATE FUNCTION PadLeft ( ),/*原始字符*/ @TotalLength int,/*总长度*/ ) ...

  2. MVC 4 用Nuget安装组件后的常见错误

    1,[A]System.Web.WebPages.Razor.Configuration.HostSection 无法强制转换为 [B]System.Web.WebPages.Razor.Config ...

  3. openurl 跳转

    1.拨打电话: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://68979"]]; ...

  4. wamp环境下phpmyadmin拒绝访问

    You don't have permission to access /phpmyadmin on this server. 找到 alias/phpmyadmin.conf  的配置文件 将 &l ...

  5. Flex debug版本浏览器选定问题

    原来都用IE进行调试的,今天安装了火狐浏览器,结果出现调试器找不到的错误,如下图 需要做下面设置 "窗口"—>"首选参数",下图位置勾选项改为IE,问题就 ...

  6. BSD Apache GPL LGPL MIT

    当Adobe.Microsoft.Sun等一系列巨头开始表现出对”开源”的青睐时,”开源”的时代即将到来! 最初来自:sinoprise.com/read.php?tid-662-page-e-fpa ...

  7. Exit函数

    1函数: exit() 函数名: exit() 所在头文件:stdlib.h 功 能: 关闭所有文件,终止正在执行的进程. exit(1)表示异常退出.这个1是返回给操作系统的. exit(x)(x不 ...

  8. Android 之 log

    android.util.Log常用方法: Log.v()  VERBOSE  任何消息都会输出 Log.d()  DEBUG  仅输出debug调试的意思,但他会输出上层的信息,过滤起来可以通过DD ...

  9. Objective-C( 语法二)

     分类(Category):可以给某一个类扩充一些方法(不修改原来类的代码)  作用:在不改变原来类内容基础上,可以为类增加一些方法  使用注意: 1. 只能增加方法,不能增加成员变量 2. 分类方法 ...

  10. ASP.NET Redis 开发 [转]

    Redis简介 Redis是一个开源的,使用C语言编写,面向“键/值”对类型数据的分布式NoSQL数据库系统,特点是高性能,持久存储,适应高并发的应用场景.Redis纯粹为应用而产生,它是一个高性能的 ...