使用EULA屏幕创建macos应用程序

时间:2018-02-23 04:22:34

标签: objective-c macos cocoa

我想用EULA屏幕创建一个macos app(example.app)。不想要.dmg,因为我想直接运行应用程序。点击该应用程序将显示EULA屏幕,然后启动它。

我有什么方法可以做到吗?请帮忙。

1 个答案:

答案 0 :(得分:0)

在XIB中创建另一个窗口。使用新属性EULAwindow将新窗口链接/连接到AppDelegate.m文件。确保两个窗口都设置为在启动时不可见。

#import "AppDelegate.h"

@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSWindow *EULAwindow;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    BOOL hasUserAgreedToEULA = [[NSUserDefaults standardUserDefaults] boolForKey:@"userHasAgreedEULA"];
    if (hasUserAgreedToEULA) {
        [self showAppWindow];
    } else {
        [[self EULAwindow] orderFront:nil];
    }
}

- (IBAction)userAgreesAction:(NSButton *)sender {
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"userHasAgreedEULA"];
    [[self EULAwindow] close];
    [self showAppWindow];
}

- (IBAction)userDisagreesAction:(NSButton *)sender {
    [NSApp terminate:nil];
}

- (void)showAppWindow
{
    [[self window] orderFront:nil];
}

enter image description here