Parse不支持直接保存NSAttributedStrings
。转换为HTML并不是最直接的。任何人都有友好的方法将NSAttributedStrings
(字体和上标)存储到Parse.com?
答案 0 :(得分:0)
谢谢大家,根据@Wain的评论,决定将rtf字符串保存到Parse上。
// convert NSAttributedString to RTFString and save to Parse
PFObject *note = [PFObject objectWithClassName:@"Note"];
NSAttributedString *noteAttributedText = self.noteTextView.attributedText;
NSDictionary *documentAttributes = [NSDictionary dictionaryWithObjectsAndKeys:NSRTFTextDocumentType,NSDocumentTypeDocumentAttribute, nil];
NSData *rtfData = [noteAttributedText dataFromRange:NSMakeRange(0, noteAttributedText.length) documentAttributes:documentAttributes error:NULL];
NSString *rtfString = [[NSString alloc] initWithData:rtfData encoding:NSUTF8StringEncoding];
note[@"noteTextAsRTFString"] = rtfString;
// convert RTFString to NSAttributedString after pulling from Parse
NSString *rtfString = [pfObject objectForKey:@"noteTextAsRTFString"];
NSData *data = [rtfString dataUsingEncoding:NSUTF8StringEncoding];
NSAttributedString *noteAttributedText = [[NSAttributedString alloc] initWithData:data options:@{NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType} documentAttributes:nil error:nil];