summaryrefslogtreecommitdiff
path: root/uialert.mm
blob: a72cbd4b41747a6403c918a89cd1cac458b5fda1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <UIKit/UIKit.h>
#include <unistd.h>

int argc_;
char **argv_;

@interface AlertSheet : UIApplication {
}

- (void) alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button;
- (void) applicationDidFinishLaunching:(id)unused;
@end

@implementation AlertSheet

- (void) alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button {
    [sheet dismiss];
    exit(button);
}

- (void) applicationDidFinishLaunching:(id)unused {
    NSMutableArray *buttons = [NSMutableArray arrayWithCapacity:(argc_ - 3)];
    for (size_t i(0); i != argc_ - 3; ++i)
        [buttons addObject:[NSString stringWithCString:argv_[i + 3]]];

    UIAlertSheet *sheet = [[[UIAlertSheet alloc]
        initWithTitle:[NSString stringWithCString:argv_[1]]
        buttons:buttons
        defaultButtonIndex:0
        delegate:self
        context:self
    ] autorelease];

    [sheet setBodyText:[NSString stringWithCString:argv_[2]]];

    [sheet setShowsOverSpringBoardAlerts:YES];
    [sheet popupAlertAnimated:YES];
}

@end

int main(int argc, char *argv[]) {
    argc_ = argc;
    argv_ = argv;

    char *args[] = {
        "AlertSheet", NULL
    };

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    UIApplicationMain(1, args, [AlertSheet class]);
    [pool release];
    return 0;
}