Domanda

I'm using the Push Notification service of Shephertz's App42.

I'm trying to send the push notification to a user whenever another player beat his score. What I'm doing is, player1 register his score and facebook id to mySQL server. Player1 also register facebook id as userId of App42 Push Notification. Then player2 do the same, but with score more than player1. Then the PHP code that manage user score will check that player2's score is more than player1's. So I use this PHP code to send Push Notification to player1

$pushNotification = $pushNotificationService->sendPushMessageToUser($user,$message);

If player1 has registered his userId with AppHQ, then it's working very fine.

But, in some case including the test, player1 haven't registered to AppHQ just yet (maybe he didn't want to allow push notification). The problem occur here and I got this error :

Fatal error: Uncaught exception 'com\shephertz\app42\paas\sdk\php\App42NotFoundException' in /home/vhosts/www.kanpot2002.com/1.2/RestClient.class.php:324 Stack trace:

#0 /home/vhosts/www.kanpot2002.com/1.2/PushNotificationService.php(239): com\shephertz\app42\paas\sdk\php\connection\RestClient::post('https://api.she...', Array, NULL, NULL, 'application/jso...', 'application/jso...', '{"app42":{"push...')

#1 /home/vhosts/www.kanpot2002.com/PushNotificationManager.php(34): com\shephertz\app42\paas\sdk\php\push\PushNotificationService->sendPushMessageToUser(563043561, 'FIRST_NAME has ...')

#2 /home/vhosts/www.kanpot2002.com/addbestscore.php(85): PushNotificationManager->SendMessageToUser(563043561, 'FIRST_NAME has ...')

#3 {main} thrown in /home/vhosts/www.kanpot2002.com/1.2/RestClient.class.php on line 324

Then I try using this

try{ $pushNotification = $pushNotificationService->sendPushMessageToUser($user,$message); } catch(Exception $e){}

The result is better. The first user with no userId is catched and has no error. But the second user gave me this error (as if it ignore the try catch statement)

Fatal error: Call to a member function __get() on a non-object in /home/vhosts/www.kanpot2002.com/1.2/PushNotificationResponseBuilder.php on line 23

I'm really stucked at this. Please help!

Thanks,

kanpot2002

È stato utile?

Soluzione

Create a new instance of service when ever you call method of it Like this:

$pushService= $api->buildPushNotificationService();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top