ios - Writing NSMutableAttributedString to rtf file could not open? -


my tried code given below:-

#define fontfamily(fname,fsize) [uifont fontwithname:fname size:fsize] #define themered [uicolor colorwithred:189.0f/255.0f green:0.0f/255.0f blue:12.0f/255.0f alpha:1] #define helveticabold @"helveticaneue-bold" #define helveticareg @"helveticaneue" #define m 16.0f #define l 20.0f 

code writing attributedstring

 nsstring *docdir = [nshomedirectory() stringbyappendingpathcomponent:@"tmp/myuser"];     nsfilemanager *fm = [nsfilemanager defaultmanager];      if (![fm fileexistsatpath:docdir]) {         [fm createdirectoryatpath:docdir withintermediatedirectories:no attributes:nil error:nil];     }      nsstring *filepath  = [docdir stringbyappendingpathcomponent:@"wrp.rtf"];      nsstring *noteasattachment = [freehandttl.text stringbyappendingstring:[nsstring stringwithformat:@"\n%@",freehandtxt.text]];      nsmutableattributedstring *attributedstr = [[nsmutableattributedstring alloc] initwithstring:noteasattachment];      [attributedstr addattribute:nsfontattributename value:fontfamily(helveticabold, l) range:nsmakerange(0, freehandttl.text.length)];     [attributedstr addattribute:nsforegroundcolorattributename value:themered range:nsmakerange(0, freehandttl.text.length)];      [attributedstr addattribute:nsfontattributename value:fontfamily(helveticareg, m) range:nsmakerange(freehandttl.text.length+1, freehandtxt.text.length)];      nslog(@"attr str %@",attributedstr);      [attributedstr filewrapperfromrange:nsmakerange(0, [attributedstr length])  documentattributes:@{nsdocumenttypedocumentattribute: nsrtfdtextdocumenttype} error:nil];      nsfilewrapper *filewrapper = [[nsfilewrapper alloc] init];      bool success = [filewrapper writetourl:[nsurl fileurlwithpath:filepath] options:nsfilewrapperwritingatomic originalcontentsurl:nil error:nil]; 

my string value given below:--

attr str file title {     nscolor = "uidevicergbcolorspace 0.741176 0 0.0470588 1";     nsfont = "<uictfont: 0xa140f00> font-family: \"helvetica neue\"; font-weight: bold; font-style: normal; font-size: 20.00pt"; } { }lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. nam liber te conscient factor tum poen legum odioque civiuda.{     nsfont = "<uictfont: 0x8ea1fc0> font-family: \"helvetica neue\"; font-weight: normal; font-style: normal; font-size: 16.00pt"; } 

and success variable of type bool shows yes , file written successfully. when try open rtf file @ folder location shows error message displayed below:-

enter image description here

this code doesn't make sense:

[attributedstr filewrapperfromrange:nsmakerange(0, [attributedstr length])                  documentattributes:@{nsdocumenttypedocumentattribute: nsrtfdtextdocumenttype}                               error:nil];  nsfilewrapper *filewrapper = [[nsfilewrapper alloc] init];  bool success = [filewrapper writetourl:[nsurl fileurlwithpath:filepath]                                options:nsfilewrapperwritingatomic                    originalcontentsurl:nil                                  error:nil]; 

as asking attributed string file wrapper , ignoring returns , creating new one, no content. has more chance of success:

nsfilewrapper *filewrapper = [attributedstr filewrapperfromrange:nsmakerange(0, [attributedstr length])                  documentattributes:@{nsdocumenttypedocumentattribute: nsrtfdtextdocumenttype}                               error:nil];  bool success = [filewrapper writetourl:[nsurl fileurlwithpath:filepath]                                options:nsfilewrapperwritingatomic                    originalcontentsurl:nil                                  error:nil]; 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -