iOS, получить изображение и сохранить или сохранить исходную ссылку URL, когда примет формат HTML в NSMutableAttributedString - PullRequest
0 голосов
/ 22 ноября 2018

для ios, target-c, здесь хотелось бы загрузить html-файл (aa.html) в UITextView, но я хотел бы сохранить URL-адрес изображения при выполнении преобразования для целей перезагрузки, но, похоже, он сокращаетсяссылка.Жду помощи.Большое спасибо.Ниже приведен код:

// aa.html is my local html format file
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"aa" ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]
                                               initWithData: [htmlString dataUsingEncoding:NSUTF8StringEncoding]
                                               options: @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
                                                          NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
                                               documentAttributes: nil
                                               error: nil
                                               ];
// retrieve image here
[attributedString enumerateAttribute:NSAttachmentAttributeName
                             inRange:NSMakeRange(0, [attributedString length])
                             options:0
                          usingBlock:^(id value, NSRange range, BOOL *stop)
 {
     // when it is NSTextAttachment(kind of image)
     if ([value isKindOfClass:[NSTextAttachment class]])
     {
         NSTextAttachment *attachment = (NSTextAttachment *)value;
         //the complete url is shorten after Encoding
         // the attachment here can only show "bb.jpg", but what i expect is the full url like: https://attach.mobile01.com/attach/201811/bb.jpg


     }
 }];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...