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
BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Pushing to application, push and forget?

Try the push using Application level reliability instead of application-preferred.  It sounds like it is falling back to transport level reliability, which just checks if the push made it to the device and not the application.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
jmace
Posts: 482
Registered: ‎10-24-2008
My Device: 9300

Re: Pushing to application, push and forget?

I changed the line below. Pushed a message with the application open : success 200

 

I then closed the app and pushed another message:  failed , still 200

 

HttpWReq.Headers.Add("X-Rim-Push-Reliability", "Application");

 

_________________________________________
www.jasonmace.com/blackberry
BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Pushing to application, push and forget?

[ Edited ]

After some further digging, I have verified that currently Widgets support only transport level push reliability.  Even if application level is specified, it will act the same as transport level.

 

This was incorrect.  See my next post below.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
jmace
Posts: 482
Registered: ‎10-24-2008
My Device: 9300

Re: Pushing to application, push and forget?

Thanks Mark.

 

That's what I was beginning to suspect as well. Appreciate all of your help.

_________________________________________
www.jasonmace.com/blackberry
BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Pushing to application, push and forget?

So, the Widget push API code DOES use the accept/decline code available to a Java application.  It does so when the JavaScript handler function returns an integer.

http://www.blackberry.com/developers/docs/widgetapi/

Under the openPushListener details...

“The function that is assigned as the callback function will be called with one parameter passed to it. The object passed to the callback function is of type blackberry.push.Data which has a payload property that is a Blob as described in Gears. The developer can then retrieve the data either as the Blob or use ".toString()" if the data contained in the blob is a string. Furthermore, the callback function must return an integer (one of constants described in blackberry.push.Data) indicating if the push message is accepted or declined.”

The constants it's referring to are also listed in the spec.

const Number  ACCEPT  = 0  
const Number  DECLINE_USERDCR  = 1  
const Number  DECLINE_USERDCU  = 2  
const Number  DECLINE_USERPND  = 3  
const Number  DECLINE_USERREQ  = 4  
const Number  DECLINE_USERRFS  = 5  

The DECLINE codes (USERDCR, USERDCU, etc.) are taken straight from the java constants as well - http://docs.blackberry.com/en/developers/deliverables/6022/net/rim/device/api/io/http/PushInputStrea...

This return value was missed in our original sample and will be corrected.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Member
ziffusion
Posts: 1
Registered: ‎08-16-2010
My Device: Not Specified

Re: Pushing to application, push and forget?

Hi

 

Can you please clarify the call to MdsCredentials() in your code? Is this simply NetworkCredential() or does MDS require other processing? Is the code for MdsCredentials() available?

 

Thanks!

Developer
jmace
Posts: 482
Registered: ‎10-24-2008
My Device: 9300

Re: Pushing to application, push and forget?

ziffusion, 

 

I've attached the MDSCredentials class below. Enjoy

 

 

public class MdsCredentials : System.Net.ICredentials
{
  private string username = string.Empty;
  private string password = string.Empty;

  public MdsCredentials(string username, string password)
  {
    this.username = username;
    this.password = password;
  }

  public System.Net.NetworkCredential GetCredential(Uri uri, string authType)
  {
    if (authType.Equals("basic"))
    {
      return new System.Net.NetworkCredential(UserName, Password);
    }
    else
    {
      return null;
    }
  }

  public string UserName
  {
    get
    {
      return username;
    }
    set
    {
      username = value;
    }
  }

  public string Password
  {
    get
    {
      return password;
    }
    set
    {
      password = value;
    }
  }
}

 

 

_________________________________________
www.jasonmace.com/blackberry
New Developer
VariousArtist
Posts: 22
Registered: ‎08-18-2010
My Device: Not Specified

Re: Pushing to application, push and forget?

How far did you get with this?

 

I'm working on an app that involves push messaging where much of the push code was outsourced and written in Java.

 

I'd love to move the server push code over to C#.NET as well as add logic to handle the push status information that is available to the "Push Plus" messaging level.

 

Are there any good examples of these?  

i.e. either C#.NET and/or better handling of push status?

 

My research online points to some examples to do with .NET but then I see other information that some of the MDS is deprecated with respect to Visual Studio or uses .NET 1.1.  

New Contributor
anilat87
Posts: 3
Registered: ‎05-09-2013
My Device: 9700

Push Notification Is not working in Blackberry

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Net;

namespace BlackberryPUSH
{
public partial class _Default : System.Web.UI.Page
{

 

protected void Page_Load(object sender, EventArgs e)
{
// pushMessage("hi", "220");

}


public void pushMessage(string pushedMessage, string pushPin)
{

string appid = "3457-B730k4394m49rOr96r33M8t74303c51k728";
string password = "smnBIWO3";

 


String BESAddress = "http://pushapi.eval.blackberry.com/mss/PD_pushRequest";
String BESWebserverListenPort = "pushPort";
String widgetNotificationUrl = "https://pushapi.eval.blackberry.com/mss/PD_pushRequest";

String pushUserName = "pushUserName";
String pushPassword = "pushPassword";
String pushPort = "pushPort ";
string Boundary = "Boundary ";
string DeliverBefore = DateTime.UtcNow.AddMinutes(5).ToString("s",

System.Globalization.CultureInfo.InvariantCulture) + "Z";
Response.Write(DeliverBefore);

bool success = true;
StringBuilder Data = new StringBuilder();
Data.AppendLine("--" + Boundary);
Data.AppendLine("Content-Type: application/xml; charset=utf-8");
Data.AppendLine("");
Data.AppendLine("<?xml version=\"1.0\"?>");
Data.AppendLine("<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP 2.1//EN\">");
Data.AppendLine("<pap>");
Data.AppendLine("<push-message push-id=" + (char)34 + ID + (char)34 + " deliver-before-timestamp=" +

(char)34 + DeliverBefore + (char)34 + " source-reference=" + (char)34 + pushUserName + (char)34 + ">");
Data.AppendLine("<address address-value=\"" + pushPin + "\"/>");
Data.AppendLine("<quality-of-service delivery-method=\"unconfirmed\"/>");
Data.AppendLine("</push-message>");
Data.AppendLine("</pap>");
Data.AppendLine("--" + Boundary);
Data.AppendLine("Content-Type: text/plain");
Data.AppendLine("Push-Message-ID: " + ID);
Data.AppendLine("");
Data.AppendLine(pushedMessage);
Data.AppendLine("--" + Boundary + "--");
Data.AppendLine("");
byte[] bytes = Encoding.ASCII.GetBytes(Data.ToString());

Stream requestStream = null;
HttpWebResponse HttpWRes = null;
HttpWebRequest HttpWReq = null;

try
{
//http://<BESName>:<BESPort>/push?DESTINATTION=<PIN/EMAIL>&PORT=<PushPort>&REQUESTURI=/
// Build the URL to define our connection to the BES.
string httpURL = BESAddress + ":" + BESWebserverListenPort
+ "/push?DESTINATION=" + pushPin + "&PORT=" + pushPort
+ "&REQUESTURI=/";

//make the connection
HttpWReq = (HttpWebRequest)WebRequest.Create(httpURL);
HttpWReq.Method = ("POST");
//add the headers nessecary for the push
HttpWReq.ContentType = "text/plain";
HttpWReq.ContentLength = bytes.Length;
// ******* Test this *******
HttpWReq.Headers.Add("X-Rim-Push-Id", pushPin + "~" + DateTime.Now); //"~" +pushedMessage +
HttpWReq.Headers.Add("X-Rim-Push-Reliability", "application-preferred");
HttpWReq.Headers.Add("X-Rim-Push-NotifyURL", (widgetNotificationUrl + pushPin + "~" + pushedMessage

+ "~" + DateTime.Now).Replace(" ", ""));

// *************************

HttpWReq.Credentials = new MDSCredentials(pushUserName, pushPassword);
Console.WriteLine(pushedMessage);
requestStream = HttpWReq.GetRequestStream();
//Write the data from the source
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
//get the response
HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();

//if the MDS received the push parameters correctly it will either respond with okay or accepted
if (HttpWRes.StatusCode == HttpStatusCode.OK || HttpWRes.StatusCode == HttpStatusCode.Accepted)
{
success = true;
}
else
{
success = false;
}
//Close the streams

HttpWRes.Close();
requestStream.Close();
}
catch (System.Exception e)
{
success = false;
}

return success;
}

}
}

 

 

Code is debugging Properly and getting Sucess reponse  But not able to Get Notifcation on my Blackberyy device 

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

Re: Push Notification Is not working in Blackberry

Please create a new thread with your question.  

 

You need to register from your application on the device to be able to receive pushes.