ios - “NSAttributedString initWithData: options: documentAttribute: error:” 在 iOS 10 中给出 <img src/> 标签时不工作

标签 ios objective-c xcode

在 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.

让我为此伤脑筋好几个小时。任何帮助将不胜感激。

enter image description here enter image description here

最佳答案

这似乎是一个错误,检查错误报告:

http://www.openradar.me/27820992

问题可能是因为 PLBuildVersionPhotoLibraryServices.frameworkAssetsLibraryServices.framework 中都有定义,所以使用哪个是未定义的。

可能的解决方案可能是:

将以下键设置到您的 Info.plist 文件中

  1. 照片

    键:隐私 - 照片库使用说明值:$(PRODUCT_NAME) 照片使用

  2. 相机

    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/

相关文章:

xcode - xcode Assets 切片中线的含义?

ios - 在 NSMutableString 上使用 substringFromIndex

ios - 以编程方式创建的 UIImageView

ios - objective-c - int 的奇怪行为

iphone - 在 MFMailComposeViewController 中更改导航的主标题颜色

iphone - 运行iPhone App帮助时出错-__NSCFConstantString错误含义

ios - 更改嵌套在 NSMutableDictionary 和 NSMutableArray 中的 NSNumber

ios - iPhone 6 及其 750x1334px 和横向的两个 UIButton

objective-c - 向 RACSubscriber 发送错误时需要返回吗?

iOS 约束 - 中心图像和动态文本