在 macOS 10.13 中运行我的 macOS 应用程序,我看到打印到控制台:
Scheduling the NSURLDownload loader is no longer supported.
这是什么意思?
在 macOS 10.13 中运行我的 macOS 应用程序,我看到打印到控制台:
Scheduling the NSURLDownload loader is no longer supported.
这是什么意思?
在我发现的实例中,Sparkle Updater 似乎是罪魁祸首。我猜 Sparkle 开发团队会继续努力,希望 Sparkle 更新后我们不会再看到该消息。
这似乎意味着您刚刚创建了已弃用的类 NSURLDownload 的实例。
为了展示这一点,在 Xcode 中创建一个新的 Cocoa 命令行工具项目,并将 main.m 中的代码替换为以下代码:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSURL* url = [[NSURL alloc] initWithString:@"https://example.com"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30.0];
NSLog(@"Will print strange sentence to console") ;
[[NSURLDownload alloc] initWithRequest:request
delegate:nil];
NSLog(@"Did print strange sentence to console") ;
}
return 0;
}
构建并运行。我在控制台中得到以下结果(删除了时间戳):
Will print strange sentence to console:
Scheduling the NSURLDownload loader is no longer supported.
Did print strange sentence to console
我会说“修复”是用 NSURLSession 替换已弃用的 NSURLDownload。
您可以直接在 Sparkle 的源代码中更正它。在第 82 行更新 SUAppcast.m 文件,将 NSURLDownload 替换为以下内容:
NSURLSessionDownloadTask *downloadTask = [[NSURLSession sharedSession] downloadTaskWithRequest:request completionHandler:^(NSURL *location, __unused NSURLResponse *response, NSError *error) {
if (location) {
NSString *destinationFilename = NSTemporaryDirectory();
if (destinationFilename) {
// The file will not persist if not moved, Sparkle will remove it later.
destinationFilename = [destinationFilename stringByAppendingPathComponent:@"Appcast.xml"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *anError = nil;
NSString *fromPath = [location path];
if ([fileManager fileExistsAtPath:destinationFilename])
[fileManager removeItemAtPath:destinationFilename error:&anError];
BOOL fileCopied = [fileManager moveItemAtPath:fromPath toPath:destinationFilename error:&anError];
if (fileCopied == NO) {
[self reportError:anError];
} else {
self.downloadFilename = destinationFilename;
dispatch_async(dispatch_get_main_queue(), ^{
[self downloadDidFinish:[[NSURLDownload alloc] init]];
});
}
}
} else {
[self reportError:error];
}
}];
[downloadTask resume];