PSPDFFileManager

Objective-C

@protocol PSPDFFileManager <NSObject>

Swift

protocol FileManager : NSObjectProtocol

Wraps file system calls. Internal class cluster. Can be replaced with Enterprise SDK wrappers like Good Technology or MobileIron AppConnect.

  • If YES, then we can’t use certain more optimized methods like UIGraphicsBeginPDFContextToFile since they would use write methods that we can’t override.

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL usesEncryption;

    Swift

    var usesEncryption: Bool { get }
  • We query the file manager for exceptions where we require unencrypted files on disk. This method expects to return YES for any type if usesEncryption returns NO. Various features in PSPDFKit require unencrypted files while usage (Open In, QuickLook, Audio Recording)

    Declaration

    Objective-C

    - (BOOL)allowsPolicyEvent:(nonnull NSString *)policyEvent;

    Swift

    func allowsPolicyEvent(_ policyEvent: String) -> Bool
  • Copies a file to an unencrypted location if the security check passes.

    Declaration

    Objective-C

    - (nullable NSURL *)
        copyFileToUnencryptedLocationIfRequired:(nullable NSURL *)fileURL
                                    policyEvent:(nonnull NSString *)policyEvent
                                          error:
                                              (NSError *_Nullable *_Nullable)error;

    Swift

    func copyFile(toUnencryptedLocationIfRequired fileURL: URL?, policyEvent: String) throws -> URL
  • Cleans up a temporary file. Searches both in encrypted store (if encrypted) and default disk store.

    Declaration

    Objective-C

    - (BOOL)cleanupIfTemporaryFile:(nonnull NSURL *)URL;

    Swift

    func cleanupIfTemporaryFile(_ URL: URL) -> Bool
  • This method creates a data provider pointing to temporary data storage that is writable. Especially when processing documents, it might be necessary to create temporary files and using this, you can secure the temporary files however you like. By default, this creates a PSPDFFileDataProvider pointing to a temporary file.

    Declaration

    Objective-C

    - (nonnull id<PSPDFDataProviding>)createTemporaryWritableDataProviderWithPrefix:
        (nullable NSString *)prefix;
  • Current user’s Library directory path (~/Library).

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSString *_Nonnull libraryDirectory;

    Swift

    var libraryDirectory: String { get }
  • Current user’s Application Support directory path (~/Library/Application Support).

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSString *_Nonnull applicationSupportDirectory;

    Swift

    var applicationSupportDirectory: String { get }
  • Current user’s Caches directory path (~/Library/Caches).

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSString *_Nonnull cachesDirectory;

    Swift

    var cachesDirectory: String { get }
  • Current user’s Documents directory path (~/Documents).

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSString *_Nonnull documentDirectory;

    Swift

    var documentDirectory: String { get }
  • Creates and returns the path to a new directory in the Temporary directory for the current user with specified UID. This directory may or may not be encrypted. For an unencrypted directory, please see -[PSPDFFileManager unencryptedTemporaryDirectoryWithUID:].

    Declaration

    Objective-C

    - (nonnull NSString *)temporaryDirectoryWithUID:(nullable NSString *)UID;

    Swift

    func temporaryDirectory(withUID UID: String?) -> String
  • Creates and returns the path to a new unencrypted directory in the Temporary directory for the current user with specified UID. Alternately, please see -[PSPDFFileManager temporaryDirectoryWithUID:] for a possibly encrypted directory.

    Declaration

    Objective-C

    - (nullable NSString *)unencryptedTemporaryDirectoryWithUID:
        (nullable NSString *)UID;

    Swift

    func unencryptedTemporaryDirectory(withUID UID: String?) -> String?
  • Creates and returns the path to a new directory in the Cache directory (/Library/Caches).

    Declaration

    Objective-C

    - (nonnull NSString *)cacheDirectoryWithPath:(nullable NSString *)path;

    Swift

    func cacheDirectory(withPath path: String?) -> String
  • This method should return false for any special paths that represent resources outside of the native device file systems and true in all other cases.

    An example of a special path in the context of this method would be a file path managed by MDM software. This check will be used by components such as PSPDFProcessor and PSPDFConversionOperation. When the method returns false for a given path, PSPDFKit will use a file manager operation to write (/ move / copy) the file into the non-native destination. You should make sure that all file manager operations correctly handle those paths.

    Declaration

    Objective-C

    - (BOOL)isNativePath:(nullable NSString *)path;

    Swift

    func isNativePath(_ path: String?) -> Bool
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)fileExistsAtPath:(nullable NSString *)path;

    Swift

    func fileExists(atPath path: String?) -> Bool
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)fileExistsAtPath:(nullable NSString *)path isDirectory:(nullable BOOL *)isDirectory;

    Swift

    func fileExists(atPath path: String?, isDirectory: UnsafeMutablePointer<ObjCBool>?) -> Bool
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)fileExistsAtURL:(nullable NSURL *)url;

    Swift

    func fileExists(at url: URL?) -> Bool
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)fileExistsAtURL:(nullable NSURL *)url isDirectory:(nullable BOOL *)isDirectory;

    Swift

    func fileExists(at url: URL?, isDirectory: UnsafeMutablePointer<ObjCBool>?) -> Bool
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)createFileAtPath:(NSString *)path contents:(nullable NSData *)data attributes:(nullable NSDictionary<NSString *, id> *)attributes;

    Swift

    func createFile(atPath path: String, contents data: Data?, attributes: [String : Any]? = nil) -> Bool
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)createDirectoryAtPath:(NSString *)path withIntermediateDirectories:(BOOL)createIntermediates attributes:(nullable NSDictionary<NSString *, id> *)attributes error:(NSError **)error;

    Swift

    func createDirectory(atPath path: String, withIntermediateDirectories createIntermediates: Bool, attributes: [String : Any]? = nil) throws
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)createDirectoryAtURL:(NSURL *)url withIntermediateDirectories:(BOOL)createIntermediates attributes:(nullable NSDictionary<NSString *, id> *)attributes error:(NSError **)error;

    Swift

    func createDirectory(at url: URL, withIntermediateDirectories createIntermediates: Bool, attributes: [String : Any]? = nil) throws
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)writeData:(NSData *)data toFile:(NSString *)path options:(NSDataWritingOptions)writeOptionsMask error:(NSError **)error;

    Swift

    func write(_ data: Data, toFile path: String, options writeOptionsMask: NSData.WritingOptions = []) throws
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)writeData:(NSData *)data toURL:(NSURL *)fileURL options:(NSDataWritingOptions)writeOptionsMask error:(NSError **)error;

    Swift

    func write(_ data: Data, to fileURL: URL, options writeOptionsMask: NSData.WritingOptions = []) throws
  • Undocumented

    Declaration

    Objective-C

    - (nullable NSData *)dataWithContentsOfFile:(NSString *)path options:(NSDataReadingOptions)readOptionsMask error:(NSError **)error;

    Swift

    func data(withContentsOfFile path: String, options readOptionsMask: NSData.ReadingOptions = []) throws -> Data
  • Undocumented

    Declaration

    Objective-C

    - (nullable NSData *)dataWithContentsOfURL:(NSURL *)fileURL options:(NSDataReadingOptions)readOptionsMask error:(NSError **)error;

    Swift

    func data(withContentsOf fileURL: URL, options readOptionsMask: NSData.ReadingOptions = []) throws -> Data
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)copyItemAtURL:(NSURL *)sourceURL toURL:(NSURL *)destinationURL error:(NSError **)error;

    Swift

    func copyItem(at sourceURL: URL, to destinationURL: URL) throws
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)moveItemAtURL:(NSURL *)sourceURL toURL:(NSURL *)destinationURL error:(NSError **)error;

    Swift

    func moveItem(at sourceURL: URL, to destinationURL: URL) throws
  • Replaces the item at the original location with the item at the supplied location.

    Declaration

    Objective-C

    - (BOOL)replaceItemAtURL:(nonnull NSURL *)originalItemURL
               withItemAtURL:(nonnull NSURL *)newItemURL
              backupItemName:(nullable NSString *)backupItemName
                     options:(NSFileManagerItemReplacementOptions)options
            resultingItemURL:(NSURL *_Nullable *_Nullable)resultingURL
                       error:(NSError *_Nullable *_Nullable)error;

    Swift

    func replaceItem(at originalItemURL: URL, withItemAt newItemURL: URL, backupItemName: String?, options: FileManager.ItemReplacementOptions = [], resultingItemURL resultingURL: AutoreleasingUnsafeMutablePointer<NSURL?>?) throws

    Parameters

    originalItemURL

    URL of the item to be replaced.

    newItemURL

    URL of the item replacing the original item.

    backupItemName

    Name of the backup item of the original item being replaced.

    options

    Options to be used while replacing the original item.

    resultingURL

    Pointer to a URL containing the location of the new item. Can be different than originalItemURL in case writing to the original location is not allowed.

    error

    Pointer to an error object. Set to the error occured while replacing the item.

    Return Value

    YES if the replacement was successful or NO if an error occurred.

  • Undocumented

    Declaration

    Objective-C

    - (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error;

    Swift

    func removeItem(atPath path: String) throws
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)removeItemAtURL:(NSURL *)URL error:(NSError **)error;

    Swift

    func removeItem(at URL: URL) throws
  • Undocumented

    Declaration

    Objective-C

    - (nullable NSDictionary<NSString *, id> *)attributesOfFileSystemForPath:(NSString *)path error:(NSError **)error;

    Swift

    func attributesOfFileSystem(forPath path: String) throws -> [String : Any]
  • Undocumented

    Declaration

    Objective-C

    - (nullable NSDictionary<NSString *, id> *)attributesOfItemAtPath:(nullable NSString *)path error:(NSError **)error;

    Swift

    func attributesOfItem(atPath path: String?) throws -> [String : Any]
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)isDeletableFileAtPath:(NSString *)path;

    Swift

    func isDeletableFile(atPath path: String) -> Bool
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)isWritableFileAtPath:(NSString *)path;

    Swift

    func isWritableFile(atPath path: String) -> Bool
  • Undocumented

    Declaration

    Objective-C

    - (NSArray<NSString *> *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error;

    Swift

    func contentsOfDirectory(atPath path: String, error: NSErrorPointer) -> [String]
  • Undocumented

    Declaration

    Objective-C

    - (NSArray<NSString *> *)subpathsOfDirectoryAtPath:(NSString *)path error:(NSError **)error;

    Swift

    func subpathsOfDirectory(atPath path: String, error: NSErrorPointer) -> [String]
  • Undocumented

    Declaration

    Objective-C

    - (NSDirectoryEnumerator<NSString *> *)enumeratorAtPath:(NSString *)path;

    Swift

    func enumerator(atPath path: String) -> FileManager.DirectoryEnumerator
  • Undocumented

    Declaration

    Objective-C

    - (NSDirectoryEnumerator<NSURL *> *)enumeratorAtURL:(NSURL *)url includingPropertiesForKeys:(NSArray<NSString *> *)keys options:(NSDirectoryEnumerationOptions)mask errorHandler:(nullable BOOL (^)(NSURL *url, NSError *error))handler;

    Swift

    func enumerator(at url: URL, includingPropertiesForKeys keys: [String], options mask: FileManager.DirectoryEnumerationOptions = [], errorHandler handler: ((URL, Error) -> Bool)? = nil) -> FileManager.DirectoryEnumerator
  • Undocumented

    Declaration

    Objective-C

    - (NSString *)destinationOfSymbolicLinkAtPath:(NSString *)path error:(NSError **)error;

    Swift

    func destinationOfSymbolicLink(atPath path: String, error: NSErrorPointer) -> String
  • Returns the absolute path as C string.

    Declaration

    Objective-C

    - (nonnull const char *)fileSystemRepresentationForPath:
        (nonnull NSString *)path;

    Swift

    func fileSystemRepresentation(forPath path: String) -> UnsafePointer<Int8>
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)fileHandleForReadingFromURL:(NSURL *)url error:(NSError **)error withBlock:(BOOL (^)(NSFileHandle *))reader;

    Swift

    func fileHandleForReading(from url: URL, withBlock reader: @escaping (FileHandle) -> Bool) throws
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)fileHandleForWritingToURL:(NSURL *)url error:(NSError **)error withBlock:(BOOL (^)(NSFileHandle *))writer;

    Swift

    func fileHandleForWriting(to url: URL, withBlock writer: @escaping (FileHandle) -> Bool) throws
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)fileHandleForUpdatingURL:(NSURL *)url error:(NSError **)error withBlock:(BOOL (^)(NSFileHandle *))updater;

    Swift

    func fileHandle(forUpdating url: URL, withBlock updater: @escaping (FileHandle) -> Bool) throws
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)setUbiquitous:(BOOL)flag itemAtURL:(NSURL *)url destinationURL:(NSURL *)destinationURL error:(NSError **)error;

    Swift

    func setUbiquitous(_ flag: Bool, itemAt url: URL, destinationURL: URL) throws
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)isUbiquitousItemAtURL:(NSURL *)url;

    Swift

    func isUbiquitousItem(at url: URL) -> Bool
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)startDownloadingUbiquitousItemAtURL:(NSURL *)url error:(NSError **)error;

    Swift

    func startDownloadingUbiquitousItem(at url: URL) throws
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)evictUbiquitousItemAtURL:(NSURL *)url error:(NSError **)error;

    Swift

    func evictUbiquitousItem(at url: URL) throws
  • Undocumented

    Declaration

    Objective-C

    - (nullable NSURL *)URLForUbiquityContainerIdentifier:(nullable NSString *)containerIdentifier;

    Swift

    func url(forUbiquityContainerIdentifier containerIdentifier: String?) -> URL?
  • Undocumented

    Declaration

    Objective-C

    - (nullable NSURL *)URLForPublishingUbiquitousItemAtURL:(NSURL *)url expirationDate:(NSDate *_Nullable *_Nullable)outDate error:(NSError **)error;

    Swift

    func urlForPublishingUbiquitousItem(at url: URL, expirationDate outDate: AutoreleasingUnsafeMutablePointer<NSDate?>?) throws -> URL
  • Undocumented

    Declaration

    Objective-C

    @property (nullable, readonly, copy) id<NSObject, NSCopying, NSCoding> ubiquityIdentityToken

    Swift

    @NSCopying var ubiquityIdentityToken: (NSCoding & NSCopying & NSObjectProtocol)? { get }
  • If the file manager is coordinated, this will temporarily disable coordination for more control.

    Declaration

    Objective-C

    - (void)performBlockWithoutCoordination:(nonnull void (^)(void))block;

    Swift

    func performBlockWithoutCoordination(_ block: @escaping () -> Void)