jkister
jkister

Reputation: 18

Simple UIAlertView app fail on ios 5.0.1

I'm currently using Cycript to pop up a springboard alert window like:

#!/usr/bin/cycript -p SpringBoard
var message = [[UIAlertView alloc] init];
message.title = "Title";
message.message = "Message";
[message addButtonWithTitle:@"Dismiss"];

[message show];

But I'd like to get away from this method since Cycript isnt meant for production.

Using theos, i made a tool project and my main.mm is:

int main(int argc, char **argv, char **envp) {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        NSLog(@"Start");

        UIAlertView *alert = [[UIAlertView alloc] init];
        NSLog(@"1");
        [alert setTitle:@"Title"];
        NSLog(@"2");
        [alert setMessage:@"Message"];
        [alert addButtonWithTitle:@"Dismiss"];
        [alert show];
        [pool release];
        return 0;
}

Makefile is:

include theos/makefiles/common.mk

TOOL_NAME = cmdWindow
cmdWindow_FILES = main.mm
cmdWindow_FRAMEWORKS = UIKit Foundation

include $(THEOS_MAKE_PATH)/tool.mk

it compiles fine, but when i run it on my iphone, i see:

iPhone:/tmp root# ./cmdWindow 
2012-03-25 06:33:18.801 cmdWindow[2845:707] Start
2012-03-25 06:33:18.851 cmdWindow[2845:707] 1
Trace/BPT trap: 5

Any Ideas why this is crashing ? Is it because there's no logic to hook the command line tool to springboard (like the -p switch of cycript) ?

I've tried both rpetrich and my own custom 5.0.1 headers in /opt/theos/include - same behavior.

Upvotes: 0

Views: 721

Answers (1)

rpetrich
rpetrich

Reputation: 32336

You can't show an alert or any UI until you have a runloop spun up and UIApplication bootstrapped. Do both of those things from an application properly registered and launched from SpringBoard and your alert will show.

Alternatively, have SpringBoard show the alert on your behalf using the CFUserNotification family of APIs.

Upvotes: 3

Related Questions