Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry Push Development

Reply
New Developer
Posts: 33
Registered: ‎08-29-2008
My Device: Not Specified

Cannot receive push message when the WebWorks app is closed

I am developing a BB10 WebWorks application. The application will receive the push message then create a notification on the Hub. The user can receive the push message and get the notification only the first time the application is installed. After the application is closed, it cannot receive push message. Restart the application, it still cannot receive push message.

 

Any idea about this issue? Thanks.

Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Cannot receive push message when the WebWorks app is closed

Did you register to launch for when a push is received? Does the app launch in the background when a push is received?

Garett
@garettBeuk
--
Goodbye everybody!
New Developer
Posts: 33
Registered: ‎08-29-2008
My Device: Not Specified

Re: Cannot receive push message when the WebWorks app is closed

Yes. I set launchapp = true for launchApplicationOnPush(launchapp, launchApplicationCallback);

 

When the app is closed, the app will be launched by a push message. After launching the app, I do not see the new message on the message list. At this situation, the app won't receive the other push messages.  The app receives push messages only at the first time when it is installed.

Highlighted
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Cannot receive push message when the WebWorks app is closed

[ Edited ]

Hi there,

 

It sounds like you have background push notifications working, but the issue arises after re-launching the application, that push notifications aren't recevied at all (in foreground, background, or from a closed state.) Is that correct?

 

For completeness, here are a few things to double-check.

 

config.xml contains:

 

  • The _sys_use_consumer_push permission. Example:
<rim:permissions>
    <rim:permit>post_notification</rim:permit>
    <rim:permit system="true">_sys_use_consumer_push</rim:permit>
</rim:permissions>

 

  • A push invocation target. Example: 

 

<rim:invoke-target id="open.pushSample.invoke.push">
    <type>APPLICATION</type>
    <filter>
        <action>bb.action.PUSH</action>
        <mime-type>application/vnd.push</mime-type>
    </filter>
</rim:invoke-target>

 

index.html

 

  • webworksready has triggered before any blackberry APIs (including push) have been used. Example:
<script type="text/javascript">
	/*global registerPush */

	/* Wait for the DOM content to be fully loaded. */
	window.addEventListener('DOMContentLoaded', function () {
		/* Wait for WebWorks to be initialized. */
		document.addEventListener('webworksready', function () {
			/* Register our BlackBerry Push Service. */
			registerPush();
		}, false);
	}, false);
</script>

JavaScript (i.e. Push implementation)

 

  • You are adding the event listener for invocation. Example:
blackberry.event.addEventListener('invoked', onInvoke);
  • You are creating a PushService object and, on success, indicating yoru desire to launch on incoming push. Example:
blackberry.push.PushService.create(
	{
		invokeTargetId: INVOKE_TARGET_ID,
		appId: BLACKBERRY_PUSH_APPLICATION_ID,
		ppgUrl: BLACKBERRY_PUSH_URL
	},
	createPushServiceSuccess,
	createPushServiceError,
	simChangeCallback,
	pushTransportReadyCallback
);
/* We created the PushService instance. */
function createPushServiceSuccess(service) {
	/* Store our PushService object. */
	pushService = service;

	/* We want to receive pushes while the application is not running. */
	pushService.launchApplicationOnPush(true, function (result) {
		console.log('Launch on push: ' + result);
	});

	/* Create channel to receive pushes. */
	pushService.createChannel(createChannelCallback);
}

 

You do not need to recreate the channel on each launch. This registration only needs to occur once and then intermittently (i.e. every 30 days) to validate the user is still registered.

 

  • You have implemented the onInvoke function you added as an event listener above. Example:
function onInvoke(invokeRequest, callback) {

/* More stuff in here. */

}

 

I'm curious whether you are doing any additional steps that may be unregistering the push channel. You can use localstorage to keep track of when you registered the channel as you don't want to recreate it every time. Recreating the channel shouldn't corrupt anything, but it's best practices to keep this minimal.

 

Beyond that, is there anything extra you are doing with the PushService object that may be impacting its functionality? Even if it doesn't seem like it would, let us know of any additional implemetnation and maybe something will become apparent.

 

Edit: Are you setting any custom flags to keep track of registration maybe? Also, if you could share the code you are using for when a push comes in (i.e. how is the app handling the data), there may be something in there that stands out as well.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.