AppDelegate is not being called

I can't seem to get my appdelegate to be called at all. Using breakpoints it doesn't even seem like the first like is being called.

This is what I have in my main.m

int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegatename");
[pool release];
return retVal;
}

Upvotes: 0

Views: 3331

Answers (3)

hawkeyecoder
hawkeyecoder

Reputation: 571

I was migrating a legacy app to iOS 9.2 and ran into this problem. In my main method I had to pass the AppDelegate's class name as the principalClassName parameter as well as the delegateClassName parameter of UIApplicationMain.

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, NSStringFromClass([AppDelegate class]), NSStringFromClass([AppDelegate class]));
    }
}

Upvotes: 0

Rok Jarc
Rok Jarc

Reputation: 18875

Let say your AppDelegate is MyAppDelegate, defined in MyAppDelegate.h and MyAppDelegate.m.

Try with this:

#import <UIKit/UIKit.h>
#import "MyAppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool
    {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));
    }
}

EDIT: This is ofcourse ment for ARC-enabled app. In case you are not using ARC you should consider unsing it. If you insist with non-ARC approach then just replace your line:

int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegatename");

with

int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));

In both cases you have to replace MyAppDelegate with the real name of your application delegate class.

EDIT2:

According to your additional commands your main.m should look something like this:

#import <UIKit/UIKit.h>
#import "Radio99AppDelegate.h"

int main(int argc, char *argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([Radio99AppDelegate class]));
    [pool release];
    return retVal;
}

I'm not sure if you are using radio99AppDelegate or Radio99AppDelegate - the last one would be 'standard'. And if this is a new project it would be wise to consider 'translating' it to ARC. Much less hussle with memory management.

Upvotes: 2

Eric
Eric

Reputation: 4061

int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

Upvotes: 1

Related Questions