Hello!
New macOS app trying to allow user access to files they opened with NSOpenPanel at a later date | sessioin.
I can successfully use the code below to write a bookmark at the same location that behaves as expected.
I can do this AS LONG AS I do NOT use 'NSURLBookmarkCreationWithSecurityScope'.
Yes I have: com.apple.security.app-sandbox==true in my entitlements file
How do I go about understanding what is wrong?
NSURLBookmarkCreationOptions bookmarkCreationOptions = (NSURLBookmarkCreationOptions)NSURLBookmarkCreationWithSecurityScope;
NSURLBookmarkResolutionOptions bookmarkReadingOptions = (NSURLBookmarkResolutionOptions)(NSURLBookmarkResolutionWithoutUI|NSURLBookmarkResolutionWithoutMounting|NSURLBookmarkResolutionWithSecurityScope);
self.attributedRTFString=[[NSMutableAttributedString alloc] initWithString:kMacEnactEmptyString];
if ([self.attributedRTFString readFromURL:self.documentCurrentURL options:tDictDocDefaultRTFDocAttrs documentAttributes:&myDictionary error:&myError]==YES) {
NSLog(@"readFromURL SUCCESS errorDesc:%@",[myError debugDescription]);
if(myDictionary!=nil) NSLog(@"usedAttibutes: %@",myDictionary);
tString_ = self.attributedRTFString.string;
[[NSUserDefaults standardUserDefaults] setURL:self.documentCurrentURL forKey:@"rtfURL"];
myError=nil;
currentDocumentExtendedAttrs = [self.documentCurrentURL extendedAttributesWithError:&myError];
if(myError!=nil) NSLog(@"extendedAttributedRTFString ERROR: %@",[myError debugDescription]);
myError=nil;
NSLog(@"ready to: bookmarkDataWithOptions bookmarkCreationOptions:%ld",bookmarkCreationOptions);
myData = [self.documentCurrentURL bookmarkDataWithOptions:bookmarkCreationOptions
includingResourceValuesForKeys:nil
relativeToURL:nil
error:&myError];
if(myError!=nil) NSLog(@"bookmarkDataWithOptions ERROR errorDesc:%@",[myError debugDescription]);
else NSLog(@"bookmarkDataWithOptions SUCCESS errorDesc:%@",[myError debugDescription]);
myError=nil;
NSLog(@"ready to: writeBookmarkData bookmarkCreationOptions:%ld",bookmarkCreationOptions);
myBool= [NSURL writeBookmarkData:myData toURL:[self bookmarkURLForType:myType] options:bookmarkCreationOptions error:&myError];
if((myBool==NO)&&(myError==nil)) NSLog(@"writeBookmarkData SUCCESS STALE:%hhd errorDesc:%@",myBool,[myError debugDescription]);
else if((myBool==YES)||(myError!=nil)) NSLog(@"writeBookmarkData ERROR STALE:%hhd errorDesc:%@",myBool,[myError debugDescription]);
} else {
if(myError!=nil) NSLog(@"readFromURL ERROR errorDesc:%@",[myError debugDescription]);
tString_ = kMacEnactEmptyString;
self.attributedRTFString = [[NSMutableAttributedString alloc] initWithString:tString_];
[[NSUserDefaults standardUserDefaults] setURL:nil forKey:@"rtfURL"];
}
NSLog(@"attributedRTFString: %@",self.attributedRTFString);
-------
2016-12-14 08:44:51:654 macEnact[13368:6889260] rURL: file:///Users/steve/Documents/Untitled.rtf
2016-12-14 08:44:51.654555 macEnact[13368:6889260] documentRTFURL: file:///Users/steve/Documents/Untitled.rtf
2016-12-14 08:44:51.655558 macEnact[13368:6889260] readFromURL SUCCESS errorDesc:(null)
2016-12-14 08:44:51.655697 macEnact[13368:6889260] usedAttibutes: {
BottomMargin = 72;
CocoaRTFVersion = 1504;
DefaultTabInterval = 0;
DocumentType = NSRTF;
HyphenationFactor = 0;
LeftMargin = 90;
PaperSize = "NSSize: {612, 792}";
RightMargin = 90;
TopMargin = 72;
UTI = "public.rtf";
UsesScreenFonts = 0;
}
2016-12-14 08:44:51.656058 macEnact[13368:6889260] ready to: bookmarkDataWithOptions bookmarkCreationOptions:2048
2016-12-14 08:44:51.661549 macEnact[13368:6889260] bookmarkDataWithOptions SUCCESS errorDesc:(null)
2016-12-14 08:44:51.661588 macEnact[13368:6889260] ready to: writeBookmarkData bookmarkCreationOptions:2048
2016-12-14 08:44:51.662415 macEnact[13368:6889260] writeBookmarkData ERROR STALE:0 errorDesc:Error Domain=NSCocoaErrorDomain Code=512 "The file couldn’t be saved."
2016-12-14 08:44:51.662880 macEnact[13368:6889260] attributedRTFString: tMutAttrString_{
NSFont = "\"Geneva 39.20 pt. P [] (0x600000249bd0) fobj=0x100d41930, spc=13.07\"";
…