Skip to content
This repository has been archived by the owner on Jan 10, 2020. It is now read-only.

Commit

Permalink
Fixes for Android GCM. Should also fix issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed May 8, 2014
1 parent fd342e5 commit 069f84f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function setAndroidConfig(array $config)
// GCM
$this->container->setParameter("dab_push_notifications.android.gcm.enabled", isset($config["android"]["gcm"]));
if (isset($config["android"]["gcm"])) {
$this->container->setParameter("dab_push_notifications.android.gcm.api_key", $config["android"]["gcm"]["api_key"]);
$this->container->setParameter("dab_push_notifications.android.gcm.api_keys", $config["android"]["gcm"]["api_keys"]);
}
}

Expand Down
5 changes: 5 additions & 0 deletions Resources/doc/1-setting_up_the_bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ dab_squared_push_notifications:
apps:
your_app_free: {name: 'Your App Free', internal_app_id: 0000001 }
your_app_premium: {name: 'Your App Premium', internal_app_id: 0000002 }
android:
gcm:
api_keys:
your_app_free: { api_key: 'YOUR ANDROID SERVER KEY HERE', internal_app_id: 0000001 }
your_app_premium: { api_key: 'YOUR ANDROID SERVER KEY HERE', internal_app_id: 0000002 }
ios:
certificates:
dev_free: { sandbox: true, pem: %kernel.root_dir%/../pushcerts/dev/certificate.pem, passphrase: ~, internal_app_id: 0000001}
Expand Down
6 changes: 5 additions & 1 deletion Resources/doc/5-integration_with_ios.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Step 5: Integration With iOS
=======================================

### Accepting pull requests with better iOS Docs.


In the AppDelegate file do the following:


Expand Down Expand Up @@ -158,5 +162,5 @@ In the AppDelegate file do the following:
}
```

[Step 6: Integration with Safari](6-integration_with_safari.md).
[Step 6: Integration with Android](6-integration_with_android.md).

18 changes: 18 additions & 0 deletions Resources/doc/6-integration_with_android.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Step 6: Integration With Android
=======================================


### Accepting pull requests with better Android Docs.


### A) Register For Notifications:

Make a call to the GCM Google Play services with a unique device identifier


### B) Register With Server:

When you register with the server you use the gcm Registration ID as the deviceToken and a custom set unique device id as the deviceIdentifier.


[Step 7: Integration with Safari](7-integration_with_safari.md).
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Step 6: Integration With Safari (Requires FOSUserBundle or Some Type Of User System)
Step 7: Integration With Safari (Requires FOSUserBundle or Some Type Of User System)
=======================================


Expand Down Expand Up @@ -44,4 +44,4 @@ document.body.onload = function() {

```

Once that is in the webservices routing should cover the rest. Make sure you imported the safari routing files.
Once that is in the webservices routing should cover the rest. Make sure you imported the safari routing files.
6 changes: 4 additions & 2 deletions Service/OS/AndroidGCMNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function send(MessageInterface $message)

foreach($this->apiKeys as $anAPIKey) {
if($message->getDevice()->getAppId() == $anAPIKey['internal_app_id']) {
$apiKey = $anAPIKey;
$apiKey = $anAPIKey['api_key'];
break;
}
}
Expand All @@ -80,19 +80,21 @@ public function send(MessageInterface $message)
"Authorization: key=" . $apiKey,
"Content-Type: application/json",
);

$data = array_merge(
$message->getGCMOptions(),
array("data" => $message->getMessageBody())
);

$device = $message->getDevice();
// Chunk number of registration IDs according to the maximum allowed by GCM
$chunks = array_chunk(array($device->getDeviceIdentifier()), $this->registrationIdMaxCount);
$chunks = array_chunk(array($device->getDeviceToken()), $this->registrationIdMaxCount);

// Perform the calls (in parallel)
$this->responses = array();
foreach ($chunks as $registrationIDs) {
$data["registration_ids"] = $registrationIDs;

// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
Expand Down

0 comments on commit 069f84f

Please sign in to comment.