在 iOS 10 之前,下面的代码给出了正确的结果,但在 iOS 10 之后却没有。不知道 iOS 版本怎么会导致这个问题。
NSString *string = @"<img width=\"30%\" src=\"https://private_server.com/sample_endpoint/example.png\" border=\"3\" />";
NSError *error = nil;
[_textView setAttributedText:[[NSAttributedString alloc] initWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:&error]];
分配 NSAttributedString 时没有观察到错误,但在下面的控制台中打印警告。
objc[88018]: Class PLBuildVersion is implemented in both /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x1111a4998) and /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x110639d38). One of the two will be used. Which one is undefined.
让我为此伤脑筋好几个小时。任何帮助将不胜感激。
最佳答案
这似乎是一个错误,检查错误报告:
http://www.openradar.me/27820992
问题可能是因为 PLBuildVersion
在 PhotoLibraryServices.framework
和 AssetsLibraryServices.framework
中都有定义,所以使用哪个是未定义的。
可能的解决方案可能是:
将以下键设置到您的 Info.plist 文件中
照片
键:隐私 - 照片库使用说明值:$(PRODUCT_NAME) 照片使用
相机
Key:Privacy - Camera Usage Description Value:$(PRODUCT_NAME) 相机使用
希望这会有所帮助:)
关于ios - “NSAttributedString initWithData: options: documentAttribute: error:” 在 iOS 10 中给出 <img src/> 标签时不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40170172/