Skip to content

Commit

Permalink
Add canonical regisrtration Id field for GCM
Browse files Browse the repository at this point in the history
  • Loading branch information
drqwaso committed May 10, 2016
1 parent 066d06b commit 886a799
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
11 changes: 9 additions & 2 deletions Gcm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class Gcm extends AbstractApnsGcm
{
public $apiKey;

/**
* @var string Canonical registration ID.
* @link https://developers.google.com/cloud-messaging/registration#keeping-the-registration-state-in-sync
*/
public $canonicalId;

private $_client = null;

public function init()
Expand Down Expand Up @@ -75,6 +81,7 @@ public function send($token, $text, $payloadData = [], $args = [])
try {
// send a message
$result = $this->getClient()->send($message, $token, $this->retryTimes);
$this->canonicalId = $result->getCanonicalRegistrationId();
$this->success = $result->getErrorCode() != null ? false : true;
if (!$this->success) {
$this->errors[] = $result->getErrorCode();
Expand Down Expand Up @@ -154,7 +161,7 @@ public function sendMulti($tokens, $text, $payloadData = [], $args = [])
// send a message
$result = $this->getClient()->sendMulti($message, $tokens, $this->retryTimes);

$this->success = $result->getSuccess();;
$this->success = $result->getSuccess();
} catch (\InvalidArgumentException $e) {
$this->errors[] = $e->getMessage();
// $deviceRegistrationId was null
Expand Down Expand Up @@ -182,4 +189,4 @@ public function __call($method, $params)

return parent::__call($method, $params);
}
}
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ The preferred way to install this extension is through [composer](http://getcomp
Either run

```
php composer.phar require --prefer-dist bryglen/yii2-apns-gcm "1.0.3"
php composer.phar require --prefer-dist intersvyaz/yii2-apns-gcm "1.0.4"
```

or add

```
"bryglen/yii2-apns-gcm": "1.0.3"
"intersvyaz/yii2-apns-gcm": "1.0.4"
```

to the require section of your `composer.json` file.
Expand Down Expand Up @@ -46,7 +46,7 @@ in your main.php your configuration would look like this
// custom name for the component, by default we will use 'gcm' and 'apns'
//'gcm' => 'gcm',
//'apns' => 'apns',
],
]
]
```

Expand Down Expand Up @@ -120,4 +120,4 @@ $apnsGcm->send(\bryglen\apnsgcm\ApnsGcm::TYPE_APNS, $push_tokens, $message,
'badge' => 1
],
)
```
```
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "bryglen/yii2-apns-gcm",
"name": "intersvyaz/yii2-apns-gcm",
"description": "Yii 2 Apns and Gcm together",
"type": "yii2-extension",
"version": "1.0.4",
"version": "1.0.4.1",
"keywords": ["yii2"," extension"," apns"," gcm"],
"license": "MIT",
"authors": [
Expand Down

0 comments on commit 886a799

Please sign in to comment.