My app saves the file URLs obtained from UIDocumentPickerViewController
as bookmark data and reads them on the "history screen".
In the "history screen", whenever viewWillAppear
is called in ViewController, URLByResolveBookmarkData
is called for all bookmarks to check if the file has been deleted or moved. (Please see code below)
- (void)refresh {
NSManagedObjectContext* context = self.managedObjectContext;
// read all bookmarks
NSArray<HistoryItem*>* all = [self histories];
[all enumerateObjectsUsingBlock:^(HistoryItem * _Nonnull item, NSUInteger idx, BOOL * _Nonnull stop) {
BOOL isStale;
NSURL* url = [NSURL URLByResolvingBookmarkData: item.bookmark
options: 0
relativeToURL: nil
bookmarkDataIsStale: &isStale
error: nil];
if(url == nil) {
// file is deleted
[context deleteObject: item];
} else {
item.filename = url.lastPathComponent;
if(isStale) {
// file is moved
NSData *data = [url bookmarkDataWithOptions: 0
includingResourceValuesForKeys: 0
relativeToURL: nil
error: nil];
if(data != nil) {
item.bookmark = data;
}
}
}
}];
[context save: nil];
}
Then, after many calls to viewWillAppear
, calling startAccessingSecurityScopedResource
on the URL obtained by URLByResolvingBookmarkData
returns NO.
I suspect that URLByResolveBookmarkData
is consuming some resources, because the problem reproduces even if I change the code inside the block to only call URLByResolveBookmarkData
, and it doesn't reproduce when I empty the block.
Does URLByResolvingBookmarkData
consume any resources? If so, how do I release the consumed resources?
OS: iOS 15 Xcode: 15.0