Air 19.0 PushNotificationEvent.PUSH_NOTIFICATION_RECEIVED_EVENT not received when triggered by PHP API
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);
}
-
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
Please sign in to leave a comment.
Comments
1 comment