Emoji and CTFramesetterCreateWithAttributedString bug

I was surprised when I saw that

CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)self.attributedString);

caused my application to be unresponsive when the attributed string contains emojis.

I filed a bugreport. What can I do in the meanwhile as a quickfix ?


Sometimes you need to "sweeten" the cache. Assuming you are using a CGFontRef, get it to render the same Emoji characters. Often Apple waits til the last minute before doing something costly. If you know you are going to need it, if you force the work early on, perhaps in a thread, then later when you need those characters they will have been rendered somewhere and cached.

In my app, in applicationDidLaunch, I spawn off a block that does something like this.

EDIT: In your applicationDidLaunch, get a CTFontRef to the font you will use later to render Emoji characters. Create an attributed string of a whole bunch of Emoji characters and set the font to your CTFontRef. Use:

CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)theAttributedString);

to have it (hopefully) sweeten the font cache. When you first do this, it may cause some delay as you've seen before. That's OK - we just want to remove the delay from the place where you see the delay. If in fact this works, then you can take the above code and put it in a dispatch block and send it to the default queue from applicationDidLaunch.

If the issue is your initial view is slow to draw because it shows Emoji characters, well, you're out of luck. If the delay is later on techniques like this can work. I had a similar problem.

链接地址: http://www.djcxy.com/p/81942.html

上一篇: CTFrameGetLineOrigin令人难以置信的奇怪的错误

下一篇: Emoji和CTFramesetterCreateWithAttributedString错误