Почему didReceiveRemoteNotification не вызывается, если приложение находится в фоновом режиме - PullRequest
0 голосов
/ 21 июня 2019

Я пытаюсь отправить push-уведомление в мое приложение, используя pushy.me.Когда приложение работает в фоновом режиме, я ничего не могу сделать с полученными данными, если я не нажму на баннер уведомлений или приложение не будет на переднем плане ..

Вот моя полезная нагрузка уведомления

   {
  "registration_ids": [
  "692d1e6c16d483a4613193"
   ],
   "data": {
   "title": "Test Notification",
   "message": "hello"
  },
  "notification": {
    "body": "Hello World ✌",
    "badge": 1,
    "content-available" : "1",
   "mutable-content" : "1",
    "sound": "ping.aiff"
  }
}

Код:

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

    NSLog(@"%@", pushInfo);

    if(application.applicationState == UIApplicationStateInactive) {

        NSLog(@"Inactive - the user has tapped in the notification when app was closed or in background");
        //do some tasks
      //  [self manageRemoteNotification:userInfo];
        completionHandler(UIBackgroundFetchResultNewData);
    }
    else if (application.applicationState == UIApplicationStateBackground) {
        //NOT WORKING
        NSLog(@"application Background - notification has arrived when app was in background");
        NSString* contentAvailable = [NSString stringWithFormat:@"%@", [[pushInfo valueForKey:@"aps"] valueForKey:@"content_available"]];


        if([contentAvailable isEqualToString:@"1"]) {
            // do tasks


        //    [self manageRemoteNotification:userInfo];
            NSLog(@"content-available is equal to 1");
        //    completionHandler(UIBackgroundFetchResultNewData);
        }
    }
    else {
        NSLog(@"application Active - notication has arrived while app was opened");
        //Show an in-app banner
        //do tasks
     //   [self performFetchWithCompletionHandler];
        completionHandler(UIBackgroundFetchResultNewData);
    }
}
...