Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

didFinishLaunchingWithOptions not called

I'm having trouble enabling push notifications.

with this code I try to enable the notification:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    return YES;
}

It doesnt work, so I added a breakpoint in the line

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

But it seems this part of the code is never execute.

why is this not working?

like image 849
user1256477 Avatar asked Dec 04 '25 17:12

user1256477


1 Answers

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

This should be implemented in your UIApplicationDelegate, not in your UIViewController. If you have it in your UIViewController, it will never get called. Take the code out of there and put it in your UIApplicationDelegate instead.

like image 135
Nick Bull Avatar answered Dec 06 '25 08:12

Nick Bull



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!