diff options
author | Teddy Wing | 2018-10-25 20:49:39 +0200 |
---|---|---|
committer | Teddy Wing | 2018-10-25 20:49:39 +0200 |
commit | 6c06b4311ff1e5781d53f777ac00e196038c75e2 (patch) | |
tree | b005e0d1ed2cb3a0cedaac17d5eb5635d7a8c203 | |
parent | b854b50348c566cb1c3fb3f8f76610e90492bae6 (diff) | |
download | DomeKey-6c06b4311ff1e5781d53f777ac00e196038c75e2.tar.bz2 |
LicenseHandler(addLicense:): Use `NSWorkspace` to move to trash
The `trashItemAtURL:resultingItemURL:error:` method in `NSFileManager`
is only available starting from Mac OS X 10.8.
Replace this with a more compatible API call. At first I was thinking
about using `NSWorkspace`
`performFileOperation:source:destination:files:tag:`, since it works
starting from 10.0. However, I'd need to remove the `license.plist` path
component from the `NSURL` from `licensePath` in order to pass it to the
`source:` argument. I found `NSURL` `URLByDeletingLastPathComponent`,
which would make perfect sense, except it's only implemented starting in
10.6.
At that point, I figured why not use `NSWorkspace`
`recycleURLs:completionHandler:`, which exists starting in 10.6, and has
a simpler interface than
`performFileOperation:source:destination:files:tag:`.
Import AppKit in order to be able to use `NSWorkspace`.
-rw-r--r-- | DomeKey/LicenseHandler.h | 1 | ||||
-rw-r--r-- | DomeKey/LicenseHandler.m | 15 |
2 files changed, 8 insertions, 8 deletions
diff --git a/DomeKey/LicenseHandler.h b/DomeKey/LicenseHandler.h index 4d86923..90d308e 100644 --- a/DomeKey/LicenseHandler.h +++ b/DomeKey/LicenseHandler.h @@ -6,6 +6,7 @@ // Copyright © 2018 tw. All rights reserved. // +#import <AppKit/AppKit.h> #import <Foundation/Foundation.h> #import "AquaticPrime.h" diff --git a/DomeKey/LicenseHandler.m b/DomeKey/LicenseHandler.m index 021c7d4..b18bd77 100644 --- a/DomeKey/LicenseHandler.m +++ b/DomeKey/LicenseHandler.m @@ -53,14 +53,13 @@ static NSString * const LICENSE_FILE_NAME = @"license.plist"; printf("Thank you for registering DomeKey!\n"); } else { - BOOL trashed = [[NSFileManager defaultManager] - trashItemAtURL:[self licensePath] - resultingItemURL:nil - error:&error]; - - if (!trashed) { - eprintf("%s\n", [[error localizedDescription] UTF8String]); - } + [[NSWorkspace sharedWorkspace] + recycleURLs:[NSArray arrayWithObject:[self licensePath]] + completionHandler:^(NSDictionary<NSURL *,NSURL *> *newURLs, NSError *error) { + if (error) { + eprintf("%s\n", [[error localizedDescription] UTF8String]); + } + }]; } // Copy license file into path |