You are here

public function FirebaseGroupManagerService::addToGroup in Firebase Push Notification (FCM) 8

Same name and namespace in other branches
  1. 3.0.x src/Service/FirebaseGroupManagerService.php \Drupal\firebase\Service\FirebaseGroupManagerService::addToGroup()

Method for adding new devices to an existing group.

Parameters

string $groupName: Unique name for the group of devices.

string $groupToken: The token for identify group in FCM.

array $deviceTokens: Device or devices tokens, which should be combined into one group.

Return value

bool|array Result from FCM.

File

src/Service/FirebaseGroupManagerService.php, line 84

Class

FirebaseGroupManagerService
Service for managing device groups.

Namespace

Drupal\firebase\Service

Code

public function addToGroup($groupName, $groupToken, array $deviceTokens) {
  if (!$groupName || empty($deviceTokens) || !$groupToken) {
    return FALSE;
  }
  if (count($deviceTokens) > self::MAX_DEVICES) {
    throw new \OutOfRangeException('Device in group limit exceeded. Firebase supports a maximum of %u devices in one group.', self::MAX_DEVICES);
  }
  $this->body = [
    'operation' => 'add',
    'notification_key_name' => $groupName,
    'notification_key' => $groupToken,
    'registration_ids' => $deviceTokens,
  ];
  return $this
    ->send();
}