Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Android GCM :: How to detect the need to remove the DeviceToken/DeviceRegId from my database with the bundle? #151

Open
2Taps opened this issue Nov 18, 2016 · 2 comments

Comments

@2Taps
Copy link

2Taps commented Nov 18, 2016

Hey guys,

I got push notification working with gcm but now i need to find the way to remove the DeviceToken/DeviceRegId from my database when for example the user uninstalled the app from his device.

In ios i am using the feedback service but i found nothing in the bundle docs about how to do this in android gcm, i also would like to know how to handle this with 'use_multi_curl' enabled.

In my parameters i have:

rms_push_notifications:
android:
timeout: 5
gcm:
api_key: xxxxxxxx
use_multi_curl: true
dry_run: false

Thank you!

@2Taps
Copy link
Author

2Taps commented Nov 28, 2016

Hey guys,

I found a way to make it work for now, hope it helps someone.
I know is now the best way but it can make it until Rich or someone more experienced answer the issue.
First i changed the config property use_multi_curl to false.
Then your code can look like the sample bellow:

if($platform == 'gcm') {
$pushResponses = $pushNotificationService->getResponses('rms_push_notifications.os.android.gcm');
$pushResponse = (isset($pushResponses[0])?$pushResponses[0]:'');
if($pushResponse) {
$pushResponseContent = $pushResponse->getContent();
if(strpos($pushResponseContent, 'NotRegistered') !== false) {
//Remove the token from your database here
}
}
}

@dueddel
Copy link

dueddel commented Apr 11, 2017

@GuilhermeMoura1 Thanks for the snippet. With that one I came up to the following implementation for checking the response in general (not only for "NotRegistered"). This is just an action method in one of my controllers I have been using to test the push services (I just post this here in case of anyone is interested):

/**
 * @Route("/push-test")
 *
 * @return \Symfony\Component\HttpFoundation\JsonResponse
 */
public function pushTestAction() {
	//	… use RMS here to send push notifications

	//	now get the response for android similar to the code above by GuilhermeMoura1

	/** @var Response[] $pushResponses */
	$pushResponses = $this->get('rms_push_notifications')->getResponses('rms_push_notifications.os.android.gcm');
	$responses = [];

	foreach ($pushResponses as $pushResponse) {
		//	this is a JSON string
		$responseContent = $pushResponse->getContent();
		//	let's decode it
		$responseData = json_decode($responseContent, true);
		//	add to list of responses
		$responses[] = $responseData;
	}

	return $this->json([
		'respones' => $responses,
	]);
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant