You are here

public function FirebaseGroupManagerService::createGroup 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::createGroup()

Method for creation new device group.

Parameters

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

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 54

Class

FirebaseGroupManagerService
Service for managing device groups.

Namespace

Drupal\firebase\Service

Code

public function createGroup($groupName, array $deviceTokens = []) {
  if (!$groupName || empty($deviceTokens)) {
    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' => 'create',
    'notification_key_name' => $groupName,
    'registration_ids' => $deviceTokens,
  ];
  return $this
    ->send();
}