[ios] Address bad access exception in MGLAttributionInfo (#13300)

* [ios] move creation of attributed string to global queue]

* [ios] check if on main queue
This commit is contained in:
Jordan Kiley
2018-11-13 16:07:19 -08:00
committed by GitHub
parent 01d9005c3b
commit d44be9a91b

View File

@@ -65,10 +65,20 @@
NSData *htmlData = [styledHTML dataUsingEncoding:NSUTF8StringEncoding];
#if TARGET_OS_IPHONE
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData:htmlData
options:options
documentAttributes:nil
error:NULL];
__block NSMutableAttributedString *attributedString;
dispatch_block_t initialization = ^{
// This initializer should be called from a global or main queue. https://developer.apple.com/documentation/foundation/nsattributedstring/1524613-initwithdata
attributedString = [[NSMutableAttributedString alloc] initWithData:htmlData
options:options
documentAttributes:nil
error:NULL];
};
if (![[NSThread currentThread] isMainThread]) {
dispatch_sync(dispatch_get_main_queue(), initialization);
} else {
initialization();
}
#else
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithHTML:htmlData
options:options