Question

I am creating a project in which i have to change the main.m file, so that UIApplication doesnt appear straight away, so i deleted the following line from main.m

int retVal = UIApplicationMain(argc, argv, nil, nil);

and deleted these lines from AppDelegate

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch
    [window makeKeyAndVisible];
}

And i have added some lines of mine. Now UIWindow doesnt appear by default, and rightly so. But now after my code is executed, i want to create a Window and display some message.

How to create a UIWindow when there is no UIApplication in main.m?

Was it helpful?

Solution

If you want to launch an app from a daemon, use SBSLaunchApplicationWithIdentifier.

BOOL SBSLaunchApplicationWithIdentifier(NSString* identifier,
                                        BOOL      please_pass_NO_here);

If you want to launch a URL, use -[UIApplication openURL:] or the lower-level GSEventSendApplicationOpenURL.

mach_port_t GSGetPurpleSystemEventPort();
void GSEventSendApplicationOpenURL(CFURLRef url, mach_port_t port);

If you simply want to display an alert, use CFUserNotification. (Yes it works on iPhoneOS.)

http://developer.apple.com/mac/library/documentation/CoreFoundation/Reference/CFUserNotificationRef/Reference/reference.html

OTHER TIPS

Most likely, not starting UIKit is not the solution you are looking for. Try just not showing any UI (don't return from applicationDidFinishLaunching:) and do what you need to do in there (or in something called from that). Or, you could just show a nice loading screen with a UIActivityIndicatorView.

Also, note that if your application has not fully launched within 20 seconds of startup (showing some sort of UI and responding to events), SpringBoard or the OS will automatically quit your application. In addition, users don't like to wait :).

Edit: Since you are not making a UIKit app, stop dreaming of being able to start UIKit in the middle: you can't. This requires a separate component hooking SpringBoard to accomplish.

WHy are you trying to open a window from a daemon? It seems like a super-bad idea, and as you note hard to actually do.

Instead, create an app to do what you want to do and launch it from the daemon when you want to show a window - either via URL handling or some other means. But basically that app and your daemon can communicate once it's up and running, and it can do all the UI stuff away from the domain of the daemon.

i achieved what i was trying to do, thanks to KennyTM for his great advices.

This is what i did

1) i created my app in which i did all the stuff for my app and then wrote all those settings to a text file and made my app create and place that txt file to /private/var/mobile/SomeFile.txt (This is the place where as a mobile user, your app can write without messing with permissions)

2) Then i created another app in xcode, (Window Based), deleted delegate (h/m) files and wrote my own main function, in which i read from the file my other app create and wrote at in the 1st step (/private/var/mobile/SomeFile.txt).

3) I created a plist (You can find help on creating a LaunchDaemon here http://www.tuaw.com/2008/02/21/tuaw-responds-iphone-lojack/)

4) I made that plist to read my app in step 2 every 60 sec(1 min) and if condition is true, the app in the 2nd step will display an Alert using CFUserNotificationDisplayAlert (thanks to KennyTM for his guidance).

The only problem i am currently having is that i have to place that launchDaemon in /Library/LaunchDaemons directory manually but SSH using root, because i cant / my app cant write to that directory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top