Adds a new device Token to the list of device tokens to identify the devices to send the notification to.

@param string $device the new device Token to add.

@return \Gomoob\Pushwoosh\Model\Notification\Notification this instance.
176320
public function addDevice($device)
    {
        if (!isset($this->devices)) {
            $this->devices = [];
        }

        $this->devices[] = $device;

        return $this;
    }
810516
protected function sendAddNotifySignal($widget)
    {
        $this->notifyOfAdd($widget);

        if ($this->parent !== null && $this->parent instanceof SwatContainer) {
            $this->parent->sendAddNotifySignal($widget);
        }
    }
255349
public function addToken($token)
    {
        if (!in_array($token, $this->tokens)) {
            $this->tokens[] = $token;
        }

        return $this;
    }
652531
public function add(array $data)
    {
        $data = $this->resolverFactory->createNotificationResolver()->resolve($data);

        return $this->api->request('POST', '/notifications', [
            'Authorization' => 'Basic '.$this->api->getConfig()->getApplicationAuthKey(),
        ], json_encode($data));
    }
449736
public function setDevices(array $devices)
    {
        $this->devices = $devices;

        $this->hostConfig = array_merge($this->hostConfig, ['Devices' => $devices]);

        return $this;
    }
1252484
public function addToken($token)
    {
        if (count($this->tokens) + 1 > self::MULTICAST_MAX_TOKENS) {
            throw new \RuntimeException(sprintf('Max token number reached. %s tokens max.', self::MULTICAST_MAX_TOKENS));
        }

        return parent::addToken($token);
    }
1288549
def add_device_callback(self, callback):
        """"""
        _LOGGER.debug('Added new callback %s ', callback)
        self._cb_new_device.append(callback)
1151858
public function push(PushInterface $push)
    {
        $client = $this->getOpenedServiceClient();

        $pushedDevices = new DeviceCollection();

        foreach ($push->getDevices() as $device) {
            /** @var \ZendService\Apple\Apns\Message $message */
            $message = $this->getServiceMessageFromOrigin($device, $push->getMessage());

            try {
                /** @var \ZendService\Apple\Apns\Response\Message $response */
                $response = $client->send($message);

                $responseArr = [
                    'id'    => $response->getId(),
                    'token' => $response->getCode(),
                ];
                $push->addResponse($device, $responseArr);

                if (ServiceResponse::RESULT_OK === $response->getCode()) {
                    $pushedDevices->add($device);
                } else {
                    $client->close();
                    unset($this->openedClient, $client);
                    // Assign returned new client to the in-scope/in-use $client variable
                    $client = $this->getOpenedServiceClient();
                }

                $this->response->addOriginalResponse($device, $response);
                $this->response->addParsedResponse($device, $responseArr);
            } catch (\RuntimeException $e) {
                throw new PushException($e->getMessage());
            }
        }

        return $pushedDevices;
    }
550938
protected function notifyDanger($content) {
        $notification = NotificationFactory::newDangerNotification($content);
        return $this->notify(NotificationEvents::NOTIFICATION_DANGER, $notification);
    }
584023
public function sendNotification($notification)
    {
        if (!$notification instanceof DeviceNotification && !$notification instanceof TopicNotification) {
            throw new \InvalidArgumentException('Notification must be of type DeviceNotification or TopicNotification');
        }

        $message = (new Message())
            ->setNotification($notification)
            ->setData($notification->getData())
            ->setPriority($notification->getPriority())
            ->setJsonData($notification->getJsonData())
            ->setContentAvailable($notification->getContentAvailable())
            ->setCollapseKey($notification->getCollapseKey());

        // Check for the type of Notification
        if($notification instanceof DeviceNotification){
            foreach ($notification->getDeviceTokens() as $deviceToken) {
                $message->addRecipient(new Device($deviceToken));
            }
        } else if ($notification instanceof TopicNotification) {
            $message->addRecipient(new Topic($notification->getTopic()));
        }

        return $this->client->send($message);
    }
548112
public function subscribeDevicesToTopic($topicId = null, $deviceTokens = array())
    {
        if(!$topicId || empty($deviceTokens)){
            throw new \InvalidArgumentException("Please check arguments!");
        }

        return $this->client->addTopicSubscription($topicId, $deviceTokens);
    }
615223
private function patchDevice(ModelDeviceInterface $device, ModelDeviceInterface $patchingDevice)
    {
        return $this->devicePatcher->patch($device, $patchingDevice);
    }
532550
private static function normalizeBrowser(Device $device)
    {
        if ($device->getBrowser()->name === 'IE' && preg_match('#Trident/([\d\.]+)#', $device->getDeviceUa(), $matches)) {
            if (array_key_exists($matches[1], self::$trident_map)) {
                $compatibilityViewCheck = self::$trident_map[$matches[1]];

                if ($device->getBrowser()->version !== $compatibilityViewCheck) {
                    $device->getBrowser()->version = $compatibilityViewCheck . '(Compatibility View)';
                }

                return;
            }
        }
    }
18006
public function push(PushInterface $push)
    {
        $client = $this->getOpenedClient();

        $ecdsaCryptoKey = $this->getECDSACryptoKey();
        $orign = null;
        $token = null;

        $message = $this->createMessageBody($push->getMessage());

        foreach ($push->getDevices() as $device) {
            $endPoint = $device->getToken();

            $newOrigin = $this->getOrigin($endPoint);
            if (is_null($token) || $orign != $newOrigin) {
                $origin = $newOrigin;
                $token = $this->createSignatureToken($origin);
            }

            $headers = $client->getRequest()->getHeaders();
            $headers
                ->addHeaderLine('Crypto-Key', 'p256ecdsa="'.$ecdsaCryptoKey.'"')
                ->addHeaderLine('Authorization', 'Bearer '.$token)
            ;

            if (!empty($message)
                && !empty($device->getParameter('publicKey'))
                && !empty($device->getParameter('authToken'))
            ) {
                $encryptor = $this->getMessageEncryptor();
                $body = $encryptor->encrypt(
                    $message,
                    $device->getParameter('publicKey'),
                    $device->getParameter('authToken')
                );

                $headers
                    ->addHeaderLine('Content-Encoding', 'aesgcm')
                    ->addHeaderLine('Encryption', 'keyid="p256dh";salt="'.$encryptor->getSalt().'"')
                ;
                $cryptoKeyHead = $headers->get('Crypto-Key');
                $cryptoKeyValue = 'keyid="p256dh";dh="'.$encryptor->getServerPublicKey().'"'.';'.$cryptoKeyHead->getFieldValue();
                $headers->addHeaderLine('Crypto-Key', $cryptoKeyValue);

                $encType = 'application/octet-stream';
            } else {
                $body = '';
                $encType = null;
            }

            $messageObj = $push->getMessage();
            if ($messageObj instanceof BaseOptionedModel) {
                $headers->addHeaderLine('TTL', $messageObj->getOption('ttl', $this->getParameter('ttl')));

                if ($messageObj->hasOption('urgency')) {
                    $headers->addHeaderLine('Urgency', $messageObj->getOption('urgency'));
                }
                if ($messageObj->hasOption('topic')) {
                    $headers->addHeaderLine('Topic', $messageObj->getOption('topic'));
                }
            }

            $this->response = $client->setUri($endPoint)
                                     ->setHeaders($headers)
                                     ->setMethod('POST')
                                     ->setRawBody($body)
                                     ->setEncType($encType)
                                     ->send();

            switch ($this->response->getStatusCode()) {
                case 500:
                    throw new PushException('500 Internal Server Error');
                    break;
                case 503:
                    $exceptionMessage = '503 Server Unavailable';
                    if ($retry = $this->response->getHeaders()->get('Retry-After')) {
                        $exceptionMessage .= '; Retry After: '.$retry;
                    }

                    throw new PushException($exceptionMessage);
                    break;
                case 401:
                    throw new PushException('401 Forbidden; Authentication Error');
                    break;
                case 400:
                    throw new PushException('400 Bad Request; invalid message');
                    break;
                case 410:
                    // FCM returns 410 on sending to the unsubscribed endpoint.
                    $this->notRegisteredDevices->add($device);

                    break;
            }

            if ($this->response->isSuccess()) {
                $this->pushedDevices->add($device);
            }
        }

        return $this->pushedDevices;
    }
947141
public static function detect(Device $device, UserAgent $userAgent)
    {
        $device->setName($device::UNKNOWN);

        /*iphone，ipad，windowphone*/
        $flag = self::checkIpad($device, $userAgent) ||self::checkIphone($device, $userAgent) || self::checkWindowsPhone($device, $userAgent);
        if( $flag ){
        	return true;
		}
        /*android*/
		if (stripos($userAgent->getUserAgentString(), 'android') !== false) {
			$device->setName(Device::Android);
			foreach (self::$androidList as $androidName ) {
				$funcName = 'check'. $androidName;
				if ( self::$funcName( $device, $userAgent ) ) {
					return true;
				}
			}
		}

		return false;

    }
104227
public function sendAll($notification) {
		$pushEntity = $this->prepareSend($notification);
		
		$usersList = \App::$domain->account->fireUser->all();
		$targetTokens = [];
		foreach($usersList as $users) {
			if(!empty($users->device_token)) {
				$targetTokens[] = $users->device_token;
			}
		}
		$fireBase = new FireBaseSend();
		return $fireBase->sendMultiple($targetTokens, $pushEntity->toArray());
	}
683705
public function getDevice(string $device) : Device
    {
        if (!array_key_exists($device, $this->devices)) {
            throw new \OutOfBoundsException(
                'Device "' . $device . '" does not exist in data'
            );
        }

        return $this->devices[$device];
    }