Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS崩溃报告“;意外启动状态“;例外?_Ios_Crash_Nsmutableattributedstring_Nsexception - Fatal编程技术网

iOS崩溃报告“;意外启动状态“;例外?

iOS崩溃报告“;意外启动状态“;例外?,ios,crash,nsmutableattributedstring,nsexception,Ios,Crash,Nsmutableattributedstring,Nsexception,我发现了几个故障报告,原因是意外启动状态。我的代码如下所示: NSRange range = [content rangeOfString:@"<html>"]; if (range.location != NSNotFound) { NSString *htmlStr = [content substringFromIndex:range.location]; NSAttributedString *attStr = [[NSAttributedString a

我发现了几个故障报告,原因是
意外启动状态
。我的代码如下所示:

NSRange range = [content rangeOfString:@"<html>"];

if (range.location != NSNotFound) {
    NSString *htmlStr = [content substringFromIndex:range.location];

    NSAttributedString *attStr = [[NSAttributedString alloc] initWithData:[htmlStr dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];

    return attStr.string;
}
NSRange range=[内容范围字符串:@”“;
if(range.location!=NSNotFound){
NSString*htmlStr=[content substringfromfromindex:range.location];
NSAttributedString*attStr=[[NSAttributedString alloc]initWithData:[htmlStr dataUsingEncoding:NSInocDestringEncoding]选项:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType}DocumentAttribute:nil错误:nil];
返回attStr.string;
}
崩溃报告如下所示:

NSRange range = [content rangeOfString:@"<html>"];

if (range.location != NSNotFound) {
    NSString *htmlStr = [content substringFromIndex:range.location];

    NSAttributedString *attStr = [[NSAttributedString alloc] initWithData:[htmlStr dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];

    return attStr.string;
}

只需在后台线程中调用函数:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
    // here, call your function

    dispatch_async(dispatch_get_main_queue(), ^{
        // do updates on main thread
    });
});

看起来您正在加载的数据无效或已损坏,或者无法分析。为您的文档加载器提供一个带有错误处理程序的try/catch怎么样?非常感谢。我将尝试它,看看它是否发挥了一部分我有一个类似的问题,你能解决这个问题吗?你的html有效吗?你在主线程上调用这个代码吗?这里也是。有更新吗?我无法复制。请参阅文档: