1

我正在尝试更新分布在应用商店之外的 mac 应用程序,因此按照此处建议的过程 执行下载 .pkg 文件后,我正在打开使用[[NSWorkspace sharedWorkspace] openFile:filePath.path];,但成功安装后应用程序没有打开,所以我需要做什么才能这样做应用更新后,我希望应用重新启动


    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

    NSURL *URL = [NSURL URLWithString:@"http://macappsupdate/localapp.pkg"];
    NSURLRequest *request = [NSURLRequest requestWithURL:URL];

    NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {

        NSLog(@"downloading in progress %@",downloadProgress);

    } destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {

        NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
        NSLog(@"documentsDirectoryURL %@",documentsDirectoryURL);
        return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];

    } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {

        NSLog(@"File downloaded to: %@", filePath);
        NSAlert *alert = [NSAlert new];
        alert.messageText = @"You are currently using an old version of the app.\nTo enjoy the latest features please Upgrade!";
        [alert addButtonWithTitle:@"Update"];

        NSModalResponse response1 = [alert runModal];
        if(response1 == NSAlertFirstButtonReturn) {
            [[NSWorkspace sharedWorkspace] openFile:filePath.path];
            [NSApp terminate:nil];

        }


    }];
    [downloadTask resume];

有什么建议么 ?

提前致谢 !!

4

0 回答 0