LoginSignup
6
4

More than 5 years have passed since last update.

NSURL のブックマークの細かい挙動についてのメモ

Last updated at Posted at 2014-04-11

同一のファイルを指す fileURL と fileReferenceURL から作ったブックマークは等しい:

NSURL *URL = [NSURL fileURLWithPath:...];
NSData *b1 = [URL bookmarkDataWithOptions:0 includingResourceValuesForKeys:nil relativeToURL:nil error:NULL];
NSData *b2 = [URL.fileReferenceURL bookmarkDataWithOptions:0 includingResourceValuesForKeys:nil relativeToURL:nil error:NULL];

NSAssert([b1 isEqual:b2], @"");

同一のファイルを指す URL について、 security scope がないものとあるものから作ったブックマークは等しくない(後者のほうがサイズが大きい)。しかし、それらのブックマークを解決して得た security scope つき URL は等しい:

NSURL *URL = [NSURL fileURLWithPath:...];
NSData *b1 = [URL bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:NULL];

NSURL *secURL1 = [NSURL URLByResolvingBookmarkData:b1 options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:NULL error:NULL];
NSData *b2 = [secURL1 bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:NULL];

NSAssert(! [b1 isEqual:b2], @"");

NSURL *secURL2 = [NSURL URLByResolvingBookmarkData:b2 options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:NULL error:NULL];

NSAssert([secURL1 isEqual:secURL2], @"");

その他の挙動をチェックするときのためにテスト用アプリを作っておいた: https://github.com/uasi/BookmarkTest

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4