I am building an iOS app and generating a server side notification request with the PHP API. the notification is received fine (I can see it popup) when the app is active. but the PushNotificationEvent.PUSH_NOTIFICATION_RECEIVED_EVENT is not fired. when sending a test push through the control panel, the PushNotificationEvent.PUSH_NOTIFICATION_RECEIVED_EVENT is fired fine and i can see the trace.

where did I go wrong? here's my code:

pushwoosh = PushNotification.getInstance();
trace("::::" , pushwoosh.isPushNotificationSupported);  // trace is true
pushwoosh.addEventListener(PushNotificationEvent.PERMISSION_GIVEN_WITH_TOKEN_EVENT, onToken);
pushwoosh.addEventListener(PushNotificationEvent.PERMISSION_REFUSED_EVENT, onError);
pushwoosh.addEventListener(PushNotificationEvent.PUSH_NOTIFICATION_RECEIVED_EVENT, onPushReceived);

pushwoosh.onDeviceReady();
pushwoosh.registerForPushNotification();

var pushToken:String = pushwoosh.getPushToken();
if(pushToken == null)
{
    trace( "\n Push TOKEN: not registered" );       
}
else
{
    trace( "\n Registered for pushes: " + pushwoosh.getPushToken() + " ");
}
trace("\n Pushwoosh HWID: " + pushwoosh.getPushwooshHWID() + " ");

// listeners
public function onToken(e:PushNotificationEvent):void{
    trace( "\n TOKEN received: " + e.token + " ");              
}
public function onError(e:PushNotificationEvent):void{
    trace("\n TOKEN error: " + e.errorMessage+ " ");
}
public function onPushReceived(e:PushNotificationEvent):void{
    trace( "\n Push Received: " + JSON.stringify(e.parameters) + " ");
}

Which, as you can see, is identical to the example app. and my php code:

function sendNotification($lang , $message , $device)
{
    $this->pwCall('createMessage', [
                                'application' => 'XXXXX-XXXXX',
                                'auth' => 'xxxx',
                                'notifications' => [
                                                    [
                                                        'send_date' => 'now',
                                                        'content' =>  [ 'test'],
                                                        'data' => ['custom' => 'json data'],
                                                        "platforms"=> [1],
                                                        "ios_badges"=> 1,
                                                        "ios_sound"=> "sound.caf",
                                                        "ios_ttl"=> 3000,
                                                        'devices' => [ $device  ]
                                                ]
                                            ]
                                ] 
    );
}

function pwCall($method, $data )
{
    $url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
    $request = json_encode(['request' => $data]);

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

    print "[PW] request: $request\n";
    print "[PW] response: $response\n";
    print "[PW] info: " . print_r($info, true);

}
asked 20 Oct '15, 16:11
morscad's gravatar image

morscad
112

Update: if the application is active, and I click on the banner notification, the event is fired. if the application is active and I let the notification disappear without clicking on it, the event is not fired at all, so it is as if the notification was never received if the application is not active, and the notification is received as an alert in the middle of the screen (with buttons), clicking on the "ok" button opens the application, and the evet is fired upon the click

permanent link
answered 20 Oct '15, 22:21
morscad's gravatar image

morscad
112

edited 21 Oct '15, 03:52

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×33
×15
×4

question asked: 20 Oct '15, 16:11

question was seen: 917 times

last updated: 21 Oct '15, 03:52