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
Developer
javayoung
Posts: 313
Registered: ‎05-31-2010
My Device: Alpha 10, Bold 9900, Storm 9530, Tour 9630, Curve 9320, Curve 8900

Re: PushCollector

[ Edited ]

Regarding your question "I have another questions... can I collect a push notification when the application is closed so that I can send the notification to the hub when the user doesn't have the app open?", the answer is yes. Actually you don't need to take care whether the application is open or not,  It can be shown at Hub if the client side application is closed. but the message is different from the message you sent. It always show "New .txt push received" whatever the message you sent.  But when the users open the application again, the application can show the same message which you sent.




p(^_^)q
Good good study, day day up
Contributor
ShareVestor
Posts: 17
Registered: ‎02-14-2013
My Device: Blackberry 10

Re: PushCollector

[ Edited ]

Hi everyone,

 

Thanks for the continued help...  I realized that the phone I had was defective! So I got a replacement.

 

Now on the client, the push collector works! I am now able to connect to register and connect to the push channel. However, when I send a message from the server (just running some code on a .NET web page), the phone is not receiving the push. Here is the code I am using (which I got from an example from this forum for .NET push).

 

Can you maybe spot why from this code, the push is not being sent correctly?  By the way, no exceptions are being thrown with this code, authentication works correctly, and I get an "OK" as a reply.

 


HttpWebResponse HttpWRes = null;
HttpWebRequest HttpWReq = null;

string pin = device_pin; // or actual pin of device

string applicationID = application_id_from_push_service_registration_email;
string BOUNDARY = "not_sure_what_this_is;
string msg = "testing"; // the message to send

string userName = application_id_from_push_service_registration_email;
string userPW = password_from_push_service_registration_email;

string url = "https://cpxxxx.pushapi.eval.blackberry.com/mss/PD_pushRequest";

HttpWReq = (HttpWebRequest)WebRequest.Create(url);
HttpWReq.Method = ("POST");
HttpWReq.Accept = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";

string rawCredentials = string.Format("{0}:{1}", userName, userPW);
HttpWReq.Headers.Add("Authorization",
string.Format(
"Basic {0}",
Convert.ToBase64String(Encoding.UTF8.GetBytes(rawCredentials))));


HttpWReq.PreAuthenticate = true;
HttpWReq.ContentType = "multipart/related; boundary=" + BOUNDARY + "; type=application/xml";

StringBuilder dataToSend = new StringBuilder();

dataToSend.AppendLine("--" + BOUNDARY);
dataToSend.AppendLine("Content-Type: application/xml; charset=UTF-8");

dataToSend.AppendLine("");
dataToSend.AppendLine("<?xml version=\"1.0\"?>");
dataToSend.AppendLine("<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP 2.1//EN\" \"http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd\">");
dataToSend.AppendLine("<pap>");
string myPushId = DateTime.Now.ToFileTime().ToString();
dataToSend.AppendLine("<push-message push-id=\"" + myPushId + "/source-reference=\"" + applicationID + "\">");
dataToSend.AppendLine("<address address-value=\"" + pin + "\"/>");
dataToSend.AppendLine("<quality-of-service delivery-method=\"unconfirmed\"/>");
dataToSend.AppendLine("</push-message>");
dataToSend.AppendLine("</pap>");
dataToSend.AppendLine("--" + BOUNDARY);

dataToSend.AppendLine("Content-Type: text/plain");
dataToSend.AppendLine("Push-Message-ID: " + myPushId);
dataToSend.AppendLine("");

dataToSend.AppendLine(msg);

dataToSend.AppendLine("--" + BOUNDARY + "--");
dataToSend.AppendLine("");

Stream requestStream = null;
string pushResult = "";
try
{
requestStream = HttpWReq.GetRequestStream();
}
catch (Exception ex)
{
pushResult = "Push failed! " + ex.ToString();
}
byte[] outStr = new ASCIIEncoding().GetBytes(dataToSend.ToString());
requestStream.Write(outStr, 0, outStr.Length);
requestStream.Close();

try
{
HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();
}
catch (Exception ex)
{
//push failed
}

if (HttpWRes != null)
{
HttpWRes.Close();
}
}

 

 

 

 

 

Retired
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: PushCollector

Hi,

 

Your code that sends out the push looks correct to me from a quick glance at it.  By the way, the boundary is used to separate the pieces of content.  In the Push Service SDK, we typically just use an arbitrary string of 20 characters for this.

 

Did you have your application closed when you sent the push?  When you configured the Push Collector sample on the config screen, did you check off the "Launch Application on New Push"?  This has to be checked off in order for you to receive pushes when the application is closed (it will launch the app to the background).      

 

If you send me a private message with the PIN you're trying to send the push to, the push ID, and your application ID I can look it up and see why it was not delivered.

 

Thanks,

 

Matt

Contributor
ShareVestor
Posts: 17
Registered: ‎02-14-2013
My Device: Blackberry 10

Re: PushCollector

Hi mdandrea,

 

Ok, I sent you a private message containing all information that I received from my push subscription confirmation email. Let me know what you come up with.

 

Thanks,

Peter

Retired
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: PushCollector

Thanks,  I will check it out.  But, did you see the question I asked in my last post?  Did you send the push when the application was closed and did you have the "Launch application on new push" checkbox checked?

 

Thanks,

 

Matt

Contributor
ShareVestor
Posts: 17
Registered: ‎02-14-2013
My Device: Blackberry 10

Re: PushCollector

Hi mdandrea,

 

I had the application open on the device when I ran the server-side push code... but I will try what you mentioned... I will check that checkbox and close the app as well to see if that works.

 

Thanks,

Peter

Contributor
ShareVestor
Posts: 17
Registered: ‎02-14-2013
My Device: Blackberry 10

Re: PushCollector

Hi,

 

I have tried everything mentioned and I still can't seem to get the push client to work.

 

What do you recommend I do as a next step? I think the problem is with the push client... I sent some pushes last night, if someone would like to see if they went through (I got 'Ok' on my end, but the device never received the push).

 

mdandrea - I tried checking the 'Open app on push' checkbox, closing the app, leaving the app open and did not recieve any push notifications. 

 

On the device, everything seems to work ok (push channel created succesfully, registration works ok).

 

btw... I am using the following sample: 

https://github.com/blackberry/Cascades-Samples/tree/master/pushCollector

and following the directions exactly as specified.

 

I do get one 'warning' message when I start debugging... something about an SDK version mismatch - doesn't seem to be a major problem, but could this cause problems? 

 

I was thinking of downloading the push sample again and just starting over... any other ideas?

 

Thanks,

Peter

 

 

 

Retired
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: PushCollector

Hi Peter,

 

Do you have the push IDs for the pushes you sent out that you said were not delivered?  Please send me a private message with those details as well as the device PIN you sent it to and your application ID and I can look it up for you to see the delivery status.

 

Also, for your device, what OS version are you running on your BlackBerry 10 and what version of the BlackBerry 10 Native SDK are you using?

 

Thanks,

 

Matt