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
Contributor
andrewbc
Posts: 11
Registered: ‎04-11-2014
My Device: Z-10

pushCaptureBasics: I can register, I can initiate push - but never see a push message

[ Edited ]

I'm working with the pushCaptureBasics example and WebWorks 2.0. I'm able to get both pushClient and pushInitiator building and running.

 

However, I haven't yet seen a push come to the device. Here's what I'm doing:

 

1. Deleting both pushClient and pushInitiator from the device.

 

2. Running pushClient (using webworks run)

 

3. When pushClient runs, I see a dialog box with an IPv4 address of 169.254.0.1:1337 and an IPv6 address that starts with fe80::94eb. That's confusing to me, since I can browse the web with my connection.


4. I click "Force Register" on the pushClient app and see:

[16:00:56] Creating PushService object.

[16:00:56] PushService created successfully.

[16:00:56] Expired Push Channel registration.

[16:00:56] Creating Push Channel.

[16:00:56] Application will be launched on push.

[16:00:56] Successfully created Push Channel.

 

5. Next I launch pushInitiator with webworks run. (I leave pushClient up and running.)

 

6. pushInitiator also launches with a dialog box with IPv4 and IPv6 addresses which are the same as pushClient, this time on port 1338.

 

7. I click "Send Push" and get

[16:03:59] PushInitiator success: 200

 

At this point, I kind of expect something to happen... but nothing does. I've tried this with both my company's wifi and an AT&T SIM. If I look up whatismyip.com in my browser, I see valid IPv4 addresses from either my company or AT&T, depending on what I have active.

 

I can see the BlackBerry icon in the upper right of the Z-10 screen next to the Wifi icon. Both are the same colour, which looks white to me.

 

 Incidentally, I've tried this with an invalid password in pushInitiator (just to see what happens). In that case I get a 401 instead of a 200, so I don't think it's a password/app ID issue. I also verified that my appIDs are identical between the initiator and the client.

 

I guess I have a few questions:

- am I doing something in the wrong order?

- what should I see after I register and send push? I was expecting a push notification to appear somehow.

- what's with the link-local IP addresses? Is that a problem?

 

 

 

BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10

Re: pushCaptureBasics: I can register, I can initiate push - but never see a push message

Hi there,

Those IP addresses are simply for Web Inspector because you are running in debug mode. If you are on the same WiFi network, you can browse to those addresses to see a Web Inspector console for the app (i.e. HTML elements, console output, network traffic, etc.) The reason the port went from 1337 to 1338 is because WebWorks will default to 1337, but if another app already has a debug mode open on that port, it will increment by one until it find an available port.

The 200 you're getting means that the BlackBerry infrastructure has accepted the push for processing, but it does *not* mean:
1) The device is registered to receive pushes.
2) The push was sent to the device.
3) The device received the push.

However, based on the details in Step 4 above, it certainly does appear that the device is registered and waiting for pushes.

When a push comes in, you can find the code that is executing here:
https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/pushCaptureBasics/pushClient/www/pus...

As you can see, the client application *should* be logging incoming pushes by inserting <div> elements onto the screen. If you're not seeing those appear, either the device is not receiving the pushes, or some of the code is failing.

Actually, my checking Web Inspector for the client application, you can check the Console to see if any errors are being thrown. I would recommend repeating the steps above, but when you launch the Client app, also launch Google Chrome and navigate to the IPv4 URL where you should see three links. Click the 2nd (middle) URL to open the Web Inspector for your application. From there, open the Console panel and hit CTRL+r to reload the application. The reason for this is to ensure that there aren't any start-up errors, though again given the previous log, there likely won't be.

Then, after you send the push, double check the Console panel for the client to ensure that there wasn't any failure.


One other thing, the initiator is designed to send the push back to itself (i.e to the same device):
https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/pushCaptureBasics/pushInitiator/www/...

You could try replacing that with a hard-coded PIN of your device to rule out anything on that front.


That would be my recommendation for investigating this anyways.

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.
Contributor
andrewbc
Posts: 11
Registered: ‎04-11-2014
My Device: Z-10

Re: pushCaptureBasics: I can register, I can initiate push - but never see a push message

[ Edited ]

Thanks, Erik. I ran through the tests you suggested and saw no errors. The PIN of the receiving device appeared to be determined correctly in pushInitiator, but just to be safe I hard-coded mine instead. (I tried both lowercase and uppercase alpha characters in the PIN.)

 

On the client console, I saw:

Creating PushService object. utils.js:27
PushService created successfully. utils.js:27
Expired Push Channel registration. utils.js:27
Creating Push Channel. utils.js:27
Application will be launched on push. utils.js:27
Successfully created Push Channel. utils.js:27

 

On the initiator console, I added a couple of prints of the URL and the postData, so I saw:

https://cpXXXX.pushapi.eval.blackberry.com/mss/PD_pushRequest utils.js:27
--qwertyuiop
Content-Type: application/xml; charset=UTF-8
<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 1.0//EN" "http://www.openmobilealliance.org/tech/DTD/pap_1.0.dtd">
<pap>
<push-message push-id="1398183971508"
        source-reference="XXXX-my_real_appid"
        deliver-before-timestamp="2020-12-31T23:59:59Z" >
<address address-value="my_real_pin"/>
<quality-of-service delivery-method="unconfirmed"/>
</push-message>
</pap>
--qwertyuiop
Content-Type: text/plain

{"subject":"Breaking News!","body":"Squirrel beats man at chess. It was nuts!"}
--qwertyuiop-- utils.js:27
PushInitiator success: 200 utils.js:27

 

 

("XXXX", "my_real_pin" and "my_real_appId" were the correct strings for my app.) It looks right on the device side... is there a way to debug what's going on with the infrastructure?

 

I've also tried changing the deliver-before-timestamp to something close to now (2014-04-22T16:59:59Z) just in case that does something - I guess I'll find out in a few minutes.

Contributor
andrewbc
Posts: 11
Registered: ‎04-11-2014
My Device: Z-10

Re: pushCaptureBasics: I can register, I can initiate push - but never see a push message

[ Edited ]

Hmm... this may be an issue with the pushClient. I'm actually seeing the pushClient get launched when I send a push from pushInitiator - it was showing up behind the running pushInitiator app - so some sort of message is getting through to the phone. However, when pushClient launches I don't see onInvoke or processQueue being called (based on utils.log() statements I added).

 

I've tried building pushClient as a release rather than debug build, in case the problem has to do with the dialog at the beginning, but even with that I don't see onInvoke or processQueue being called.

 

So I'm down to three questions (I think :smileyhappy: )

1. How do I detect the data that's being passed into pushClient when it's opened by a push?

2. How do I force pushClient to open on top when it's opened by a push?

3. Is there a way to push a simple text message that a user can view and then open an app by selecting it? (similar to Apple APNS)

BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10

Re: pushCaptureBasics: I can register, I can initiate push - but never see a push message

[ Edited ]

Hm, can you elaborate on this?

 

...it was showing up behind the running pushInitiator app...

 

Both should be appearing as two unique, separate applications. If the Push Initiator is open, the Push Client will also open, though it won't take the foreground, is that what you mean?

 

In your "running applications" grid on the home screen of the device, there are two unique applications running, correct? (After sending a push.)

 

The fact that it's opening means that the application is receiving the push, as it is responding to the configuration we set allow launch on push.

 

That nothing is showing up seems to indicate that there is some failure in the onInvoke function:

https://github.com/oros/BB10-WebWorks-Samples/blob/WebWorks-2.0/pushCaptureBasics/pushClient/www/pus...

 

The main issue with logging/alerts is that it's difficult to connect Web Inspector in time for an automatically starting application following a push, and alerts won't display if the app is not in the foreground; hence the reliance on the utils.log approach.

 

Perhaps placing a utils.log call on Line 240 witih simply any text will at least indicate whether that function is being called:

https://github.com/oros/BB10-WebWorks-Samples/blob/WebWorks-2.0/pushCaptureBasics/pushClient/www/pus...

 

I would be very surprised if it isn't though, as the channel registration / background launching appears to be working just fine.

 

 

That being said, we are assuming that the utils.log function itself is not failing...

 

We can see that it makes use of el:

https://github.com/oros/BB10-WebWorks-Samples/blob/WebWorks-2.0/pushCaptureBasics/pushClient/www/uti...

 

Which is defined here (following the window load event):

https://github.com/oros/BB10-WebWorks-Samples/blob/WebWorks-2.0/pushCaptureBasics/pushClient/www/ind...

 

I wouldn't rule out that a race condition has been introduced in where el is attempting to be used by utils.log inside of the onInvoke function, but perhaps the window load event hasn't been triggered yet, thus el would not be initialized, and the logging calls are failing.

 

If you have the Push Client application open before sending the push, and you switch to it after sending the push, do you see the push logs then? In this scenario, you can connect Web Inspector to the client prior to sending the push just to ensure no errors are being seen.

 

 

For your questions.

 

1. The onInvoke function in pushClient.js will be called when a push comes in. It's easier to test this while the Push Client application is running, as it ensures logging (console.log and utils.log) should be active/ready to be used.

 

2. The 1.0 APIs used to have an application.requestForeground function that you would be able to use but I am not seeing the same for the 2.0 APIs. I'm looking into this whether it's just a docs oversight or some change occurred.

 

EDIT: This API is not available for BlackBerry 10; the documentation is for the prior OS (i.e. Legacy BBOS.)

 

3. You can combine a push with basic text that will trigger onInvoke which in turn can leverage the HTML5 Notification API to create a notification in the BlackBerry Hub. That Notification, when opened, could proceed to open a specific application.

 

WebWorks: http://developer.blackberry.com/html5/apis/v2_0/blackberry.notification.html

Cordova: http://developer.blackberry.com/html5/apis/v2_0/cordova_notification_notification.md.html


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.
Contributor
andrewbc
Posts: 11
Registered: ‎04-11-2014
My Device: Z-10

Re: pushCaptureBasics: I can register, I can initiate push - but never see a push message

[ Edited ]

Elaborating on "it was showing up behind the running pushInitiator app" - yes, both applications are shown as running after push on the home screen. I was expecting something like "requestForeground" but absent that, it sounds like a Notification is the right thing to do.

 

I added a line which did utils.log when onInvoke was entered, but am not seeing it ever get called. I've tried both when pushClient is started with a push message, and also when it's already running. When pushClient is already running I have verified that utils.log() works by entering utils.log('hi') in the browser console. My 'hi' message gets added on the device screen as well as on the debug console. If I press the "Send Push" button in pushInitiator after that, I don't see any additional messages.

 

It does indeed look as if the pushClient onInvoke is not getting sent. Could this be due to my invokeTargetId? I'm using:

        'invokeTargetId': 'com.mycompany.pushclient.invoke.push',
which is the same as what I have in my config.xml:

         <rim:invoke-target id="com.mycompany.pushclient.invoke.push">

 

 I just noticed that the readme on Github (https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/pushCaptureBasics#how-to-build) used a different invokeTargetId:

    id="com.@@@@@@@@.pushclient"

    id="com.@@@@@@@@.pushclient.invoke.push"

pushClient.js: Update the ops variable with your own client push credentials; replace the @ symbols.

    'ops': {
        'invokeTargetId': 'com.@@@@@@@@.pushcapturebasics.invoke.push',

 Note the pushcapturebasics in invokeTargetId vs pushclient in config.xml.

 

BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10

Re: pushCaptureBasics: I can register, I can initiate push - but never see a push message

The target IDs should be unique. Are you using:

com.mycompany.pushclient.invoke.push

 


If so, that's fairly generic and, maybe some other developer has used it and there are issues from that? Try making it as unique as possible. I would recommend trying a fresh (unique) value for all of the following:

 

And, on the server:

 

What should be happening is that your client registers your Client invoke target to be invoked whenever a push comes in from the corresponding credentials. The function that gets called is determined when we call:

 

document.addEventListener('invoked', pushClient.onInvoke);

Source: https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/pushCaptureBasics/pushClient/www/ind...

 

This requires WebWorks 2.0 and that for the Client project, you've added:

 

webworks plugin add com.blackberry.invoked
webworks plugin add com.blackberry.push

 

Since the client is registering successfully, and the server is pushing successfully, the primary area of focus that I see is:

  1. Ensuring that the invoked event listener is successfully being added on the client side.
  2. Ensuring that the respective target IDs are matching so that the device can properly route the push to your app, which will in turn call the invoke function.

 

By "starting over" with completely new IDs everywhere, and ensuring they are absolutely unique by using non-generic IDs, that should eliminate the majority of avenues. If it still does not work, I'll gather some information from you and can reach out to our infrastructure team to trace a specific push and ask them to identify if any issues are arising in the infrastructure.


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.
Contributor
andrewbc
Posts: 11
Registered: ‎04-11-2014
My Device: Z-10

Re: pushCaptureBasics: I can register, I can initiate push - but never see a push message

Good to know. I didn't use mycompany - but I did use something that may have been used before. I'll try what you suggested with more entropy in identifiers and see if things change.

Contributor
andrewbc
Posts: 11
Registered: ‎04-11-2014
My Device: Z-10

Re: pushCaptureBasics: I can register, I can initiate push - but never see a push message

I've tried with a unique ID, and still see the same behaviour. The pushClient app launches when I run the pushInitiator and send a push, but I don't see the print I put on line 240 in onInvoke.

 

However, I think the fact that the app gets launched tells me enough for my current purposes. The onInvoke issue can wait for some later day.

BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10

Re: pushCaptureBasics: I can register, I can initiate push - but never see a push message

Alright, I have a (more or less) fail-safe way to check whether onInvoked is being called. You can see this based on the example code:

 

<!DOCTYPE html>
<html>
    <head>
        <title>Invoked Test</title>
    </head>

    <body>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript">
			/*global window, document */
			var wasInvoked = new Date().getTime();
			window.localStorage[wasInvoked] = 'A';

			window.addEventListener('load', function onLoad() {
				document.addEventListener('invoked', function onInvoked() {
					wasInvoked = new Date().getTime();
					window.localStorage[wasInvoked] = 'B';
				}, false);
			}, false);
        </script>
    </body>
</html>

 

What this entails is getting the time that the bolded lines of code are executed at, and then logging this in localStorage with an identifier (A or B) to indicate which line was responsible for the log.

 

Then, with the application loaded in debug mode, you can connect Web Inspector and execute the following in the Console:

window.localStorage

 

This should display a Storage object that you can expand and you should see the elements with keys based no the time logged, and either or B to indicate which code logged it.

 

If we see A then B, it means everything fired as expected.

If we see B then A, it means there is a timing issue with the invoked function being executed before application launch (would be very odd.)

If we see just A, then there is some missing piece that is preventing onInvoked from being fired.

If we see just B, then well, we really really shouldn't see just B.

 

Could you try, one more time, a similar approach in yours just to really, really make sure that onInvoked is not being fired?

 

That the application is opening, it means the push is being received by the device/app. That the onInvoked function is not being triggered, means that either some code is failing or the registration/configuration of the invoke-target is not properly being hooked into the device.


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.