From 6c06b4311ff1e5781d53f777ac00e196038c75e2 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 25 Oct 2018 20:49:39 +0200 Subject: 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`. --- DomeKey/LicenseHandler.h | 1 + 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 #import #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 *newURLs, NSError *error) { + if (error) { + eprintf("%s\n", [[error localizedDescription] UTF8String]); + } + }]; } // Copy license file into path -- cgit v1.2.3