我已经从here获得推送演示,可以在模拟器中工作。
当我在使用UrbanAirship Test Push消息的黑莓设备(BlackBerry Bold 9000)上尝试时,我无法接收任何推送通知。
到目前为止,我所做的事情是: *将推送端口从100更改为29580 *将应用程序ID添加为config.xml中widget元素的属性 *申请已经上传,然后才能上传到手机。 *我假设代码中没有错误,因为启动/停止订阅警报消息都出现在应用程序启动/按钮单击上 * UrbanAirship发送测试消息时,没有网络活动的迹象。
我的config.xml文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<widget xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" id="{app_id}">
<name>Push Example</name>
<description>Samples of code</description>
<author href="http://www.rim.com/" rim:copyright="no copyright" email="webapi@rim.com">
Research in Motion - Web API Team
</author><content src="index.htm" />
<feature id="blackberry.system" required="true" version="1.0.0.0" />
<feature id="blackberry.app" required="true" version="1.0.0.0" />
<feature id="blackberry.invoke.JavaArguments" required="true" version="1.0.0.0" />
<feature id="blackberry.invoke.CalendarArguments" required="true" version="1.0.0.0" />
<feature id="blackberry.invoke" required="true" version="1.0.0.0" />
<feature id="blackberry.push" version="1.0.0"/>
<feature id="blackberry.identity" version="1.0.0"/>
<feature id="blackberry.utils" required="true" version="1.0.0.0" />
<rim:connection timeout="30000">
<id>MDS</id>
<id>BIS-B</id>
<id>TCP_WIFI</id>
<id>TCP_CELLULAR</id>
<id>WAP2</id>
<id>WAP</id>
</rim:connection>
<license href="http://www.license.com">This is a sample license</license>
</widget>
action.js文件如下所示:
//the port that the Push Listener will listen to on the MDS
//Open the rimpublic.property file, which is located in the MDS\config subdirectory
//of your BlackBerry Email and MDS Services Simulators installation directory.
//Ensure the "push.application.reliable.ports=100" line is NOT commented out.
var port = 29580;
function subscribe() {
//open the listener to listen if there is pushed data coming through
blackberry.push.openPushListener(handleReturnData, port);
try {
alert("push listening has started. push port = ("+port+") app id = (" + blackberry.app.id + ") pin = ("+blackberry.identity.PIN+")");
} catch (e) {
alert (e);
}
}
//handleReturnData - the function to call for the event of pushed data coming through
//port - the port to listen on
function handleReturnData(data) {
try {
if (data != null) {
var text = blackberry.utils.blobToString(data.payload);
alert("text recieved from push: " + text);
} else {
alert("No data from the push");
}
} catch (e) {
alert (e);
}
}
function unsubscribe() {
//stop listening for pushed data, a clean up step
blackberry.push.closePushListener(port);
alert("Push listening has stopped");
}
最后,我的index.html文件如下所示:
<html>
<head>
<title>Push Example</title>
<script src="Scripts/action.js" type="text/javascript"></script>
<link href="Styles/styles.css" rel="stylesheet" type="text/css" />
</head>
<body onload="javascript:subscribe();">
<button id="btnUnsubscribe" onclick="unsubscribe();">Unsubscribe</button>
</body>
</html>
有人知道我的代码/配置会出现什么问题吗?
干杯, 斯蒂芬