Application crashes on launch using push notification

I have built-in push notifications for my application. To catch notifications, I used this delegate.

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo in my application.

So, when the application is running in the background, if a notification appears, and when I click on it, this delegate starts. If the application does not work even in the background, if you click on ntification, then it starts

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

Sophar worked well. Then I wanted to get a notification in the background. Therefore i found

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

it works for him.

So, I just changed my previous method didReceiveto this new method didReceive. Now my problem is when the application starts with a push notification (if the application does not work in the background or underground and when I click on the notification when it arrives), my application crashes. Even I cannot debug and catch this situation.

What is the difference between these two delegates. My second delegate starts when the application starts with a notification? Please help me.

+4
source share
1 answer

, , ( ) - (void) : (UIApplication *) didReceiveRemoteNotification: (NSDictionary *) userInfo

, notificatin, didFinishLaunchingWithOptions i thsi , , , didReceiveRemoteNotification.

UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if (notification) {
    [self application:application didReceiveRemoteNotification:(NSDictionary*)notification];
}
+1

Source: https://habr.com/ru/post/1611539/


All Articles