1

I am trying to update the mac app which is distributed outside app store so followed the process as suggested here After downloading the .pkg file i am opening the using [[NSWorkspace sharedWorkspace] openFile:filePath.path]; but after successfully installed app is not getting opened so what do i need to do so that after app update i want app to restart


    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];

Any Suggestions ?

Thanks in Advance !!

jarvis12
  • 134
  • 9
  • It is Swift. But perhaps it helps: https://stackoverflow.com/questions/27479801/restart-application-programmatically – ivion Feb 08 '19 at 11:02
  • @ivion how to trigger that app update is completed successfully so that i can relaunch. – jarvis12 Feb 08 '19 at 11:06
  • 1
    Look at projects Sparkle or Squirrel. They have been the norm for updating apps and they can handle relaunch. – Marek H Feb 08 '19 at 12:58

0 Answers0