首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >macOS 10.13:“不再支持调度NSURLDownload加载器。”

macOS 10.13:“不再支持调度NSURLDownload加载器。”
EN

Stack Overflow用户
提问于 2017-09-07 13:59:57
回答 3查看 1.2K关注 0票数 2

在macOS 10.13中运行我的macOS应用程序,我看到打印到控制台:

代码语言:javascript
复制
Scheduling the NSURLDownload loader is no longer supported.

这是什么意思?

EN

回答 3

Stack Overflow用户

发布于 2017-10-13 07:54:45

在我发现的实例中,Sparkle Updater似乎是罪魁祸首。我猜Sparkle开发团队会关注它,希望在Sparkle更新后我们不会再看到这条消息。

票数 5
EN

Stack Overflow用户

发布于 2017-09-07 14:01:53

这似乎意味着您刚刚创建了一个已弃用的类NSURLDownload的实例。

为了显示这一点,在Xcode中创建一个新的Cocoa命令行工具项目,并将main.m中的代码替换为以下代码:

代码语言:javascript
复制
#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;
}

构建并运行。我在控制台中得到了以下结果(去掉时间戳):

代码语言:javascript
复制
Will print strange sentence to console:
Scheduling the NSURLDownload loader is no longer supported.
Did print strange sentence to console

我要说的是,“修复”是用NSURLSession替换过时的NSURLDownload。

票数 3
EN

Stack Overflow用户

发布于 2017-11-23 04:36:05

您可以直接在Sparkle的源代码中对其进行更正。通过将NSURLDownload替换为以下内容来更新第82行的SUAppcast.m文件:

代码语言:javascript
复制
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];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46088843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档