无法在带有cordova的Blackberry 10设备中获得推送通知

时间:2015-01-23 04:33:18

标签: spring blackberry-10 cordova-3 cordova-plugins

我正在尝试为BB10实施推送通知, 并且我已经将推送服务sdk作为推送启动器下载了BIS服务。

我正在使用下面的插件用于客户端代码,因为我正在使用cordova开发应用程序。

https://github.com/phonegap-build/PushPlugin.git

使用上面的插件我能够成功创建通道,但仍然无法获得通知。 为了referance,我添加了我的客户端代码。 我被我的客户端代码困住了, 请提供一些解决方案。

请注意:我正在使用cordova 3.6.X开发应用程序。

提前致谢,

index.js

var app = {
    initialize: function() {
        this.bindEvents();
    },

    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },

    onDeviceReady: function() { 

        // ******* BlackBerry10 ******* 
        function pushNotificationHandler(pushpayload) {
            var contentType = pushpayload.headers["Content-Type"],
                id = pushpayload.id,
                data = pushpayload.data;//blob
            alert(JSON.stringify(pushpayload));
            alert(id);
            alert(data);            
            if (pushpayload.isAcknowledgeRequired) {                
                pushpayload.acknowledge(true);
            }
        };        

        function successHandler(result) {
               alert('<li>success:' + JSON.stringify(result) + '</li>');
        }
        function errorHandler(error) {
              alert('<li>error:' + JSON.stringify(error) + '</li>');
        }
        function onPushTransportReady(result) {
            if (result == blackberry.push.PushService.SUCCESS) {
                        alert("successful Configuration");
                } else {                                
                    if (result == blackberry.push.PushService.INTERNAL_ERROR) {
                        alert("Error: An internal error occurred while calling launchApplicationOnPush. " + "Try restarting the application.");
                    } else if (result == blackberry.push.PushService.CREATE_SESSION_NOT_DONE) {
                        alert("Error: Called launchApplicationOnPush without an " +
                        "existing session. It usually means a programming error.");
                    } else {
                        alert("Error: Received error code (" + result + ") after " + "calling launchApplicationOnPush.");       
                    }
                }
        }
        function onSimChange() {
            alert("SIM card is changed!");
        }
        if (localStorage.getItem("regID") === undefined || localStorage.getItem("regID") === null) {
            try {
                    pushNotification = window.plugins.pushNotification;
                    alert('<li>registering ' + device.platform+' : '+pushNotification + '</li>');
                    if (device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos") {
                        pushNotification.register(successHandler, errorHandler, {   
                            "senderID": "###########",
                            "ecb": "onNotification"
                        });
                    }
                    else if (device.platform == 'blackberry10') {
                        alert('gone');
                        var options = {
                          invokeTargetId: "...",
                          appId: "XXXX-XXX...",
                          ppgUrl: "http://cpXXXX.pushapi.eval.blackberry.com", 
                          ecb: pushNotificationHandler,
                          simChangeCallback: onSimChange,
                          pushTransportReadyCallback: onPushTransportReady,
                          launchApplicationOnPush: true
                        }
                        pushNotification.register(successHandler, errorHandler,options);
                    }
                    else {                  
                        pushNotification.register(tokenHandler,errorHandler,
                                                  {
                                                  "badge": "true",
                                                  "sound": "true",
                                                  "alert": "true",
                                                  "ecb": "onNotificationAPN"
                                              });
                    }
                } catch (err) {
                    txt = "There was an error on this page.\n\n";
                    txt += "Error description: " + err.message + "\n\n";
                    alert(txt);
                }

        } else if (localStorage.getItem("registered") === undefined || localStorage.getItem("registered") === null) {
            //sendRegIdToServer();
        }
        app.receivedEvent('deviceready');

    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

app.initialize();

config.xml中

<?xml version='1.0' encoding='utf-8'?>
<widget id="MyPushDemo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:rim="http://www.blackberry.com/ns/widgets">
    <feature name="com.blackberry.utils" />
    <feature name="com.blackberry.push" value="com.blackberry.push" />
    <feature name="com.blackberry.invoked" value="com.blackberry.invoked" />
    <feature name="PushPlugin" value="PushPlugin" />
    <feature name="Device" value="Device" />
    <name>MyPushDemo</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <preference name="WebSecurity" value="disable" />
    <rim:permissions>
        <rim:permit>run_when_backgrounded</rim:permit>
        <rim:permit>read_device_identifying_information</rim:permit>
        <rim:permit>post_notification</rim:permit>
        <rim:permit system="true">_sys_use_consumer_push</rim:permit>
        <rim:permit>read_device_identifying_information</rim:permit>
    </rim:permissions>
    <rim:invoke-target id="MypushDemo">
        <type>APPLICATION</type>
        <filter>
            <action>bb.action.PUSH</action>
            <mime-type>application/vnd.push</mime-type>
            <mime-type>text/`enter code here`plain</mime-type>
        </filter>
    </rim:invoke-target>
</widget>

0 个答案:

没有答案