本文转自:https://www.npmjs.com/package/com.devicepush.cordova-phonegap

Device Push Notification Plugin

DESCRIPTION

This plugin is for use with Cordova, and allows your application to receive push notifications on Android and iOS devices.

Important - Push notifications are intended for real devices. The registration process will fail on the iOS simulator. Notifications can be made to work on the Android Emulator, however doing so requires installation of some helper libraries, as outlined here, under the section titled "Installing helper libraries and setting up the Emulator".

Contents

Automatic Installation

Below are the methods for installing this plugin automatically using command line tools. For additional info, take a look at the Plugman Documentation and Cordova Plugin Specification.

This requires phonegap/cordova 5.0+

Supported Platforms

  • Android
  • iOS

Platforms Under Development

  • WP8

Cordova and PhoneGap CLI

The plugin can be installed via the Cordova command line interface:

  1. Navigate to the root folder for your phonegap project.

  2. Run the command:

cordova plugin add com.devicepush.cordova-phonegap

or

phonegap plugin add com.devicepush.cordova-phonegap

PhoneGap Build Support

The plugin can be installed via PhoneGap Build:

  1. Open config.xml file of your project.

  2. Add this line:

<gap:plugin name="com.devicepush.cordova-phonegap" source="npm" />

If you want to specify a particular version of the plugin you can add the version attribute to the gap tag.

<gap:plugin name="com.devicepush.cordova-phonegap" source="npm" version="0.3.8" />

Plugin API

Whitelist

Add *.devicepush.com domain in the config.xml file:

<access origin="*.devicepush.com" />
<allow-navigation href="*.devicepush.com" />

To register a new device

When the device is ready, you must call the register function.

    var app = {
        initialize: function() {
            this.bindEvents();
        },
        bindEvents: function() {
            document.addEventListener('deviceready', this.onDeviceReady, false);
        },
        onDeviceReady: function() {
            app.receivedEvent('deviceready');
            devicePush.register({
                idUser: 'USER_ID', // Your User ID in Device Push 
                idApplication: 'APPLICATION_ID', // Aplication ID in Device Push 
                position: true // Activate or deactivate gps position record. Default value is false 
                additionalData: {} // Currently in development 
            });
        },
        receivedEvent: function(id) {}
    };

To get id or token device

You can get the device id or token of the device.

    document.addEventListener("deviceRegistered", successDeviceRegistered, false);
 
    function successDeviceRegistered(evt){
        console.log("Device Id" + evt.devicePushId);
        var id = evt.devicePushId;
        console.log("Device Token" + evt.devicePushToken);
        var tokenDevice = evt.devicePushToken;
    }

With this ID you can send notification from your server.

To manager a notification received

You can manage notifications received with the next method

    document.addEventListener('notificationReceived', successNotificationReceived, false);
 
    function successNotificationReceived(evt){
        // evt.data.message,  
        // evt.data.title,  
        // evt.data.count,  
        // evt.data.sound,  
        // evt.data.additionalData 
        console.log(evt.data.message) // data is your text sent 
    }

To show a dynamic and floating notification, you have to add the following function into the function successNotificationReceived.

    devicePush.showNotification(evt.data.message);

To activate or not gps position record

You can activate or deactivate gps position record.

    devicePush.setPosition(true); //Active gps position record, true o false. Default value is false. 

To put additional user data for segmentation

To activate the segmentation of notifications, you will have to send additional user data, such as personal data.

    // Currently in development 
    devicePush.putAdditionalData({
        additionalData: {
            name: '',
            surnames: '',
            age: '',
            gender: ''
        } 
    });

You can see more information about this at: http://www.devicepush.com/documentation-push-notification/

Looking at the above message handling code for Android, a few things bear explanation. Your app may receive a notification while it is active (INLINE). If you background the app by hitting the Home button on your device, you may later receive a status bar notification. Selecting that notification from the status will bring your app to the front and allow you to process the notification (BACKGROUND). Finally, should you completely exit the app by hitting the back button from the home page, you may still receive a notification. Touching that notification in the notification tray will relaunch your app and allow you to process the notification (COLDSTART). In this case the coldstart flag will be set on the incoming event. You can look at the foreground flag on the event to determine whether you are processing a background or an in-line notification. You may choose, for example to play a sound or show a dialog only for inline or coldstart notifications since the user has already been alerted via the status bar.

Since the Android notification data models are much more flexible than that of iOS, there may be additional elements beyond message. You can access those elements and any additional ones via the payload element. This means that if your data model should change in the future, there will be no need to change and recompile the plugin.

Testing

The notification system consists of several interdependent components.

[转]com.devicepush.cordova-phonegap Device Push Notification Plugin的更多相关文章

  1. [Phonegap+Sencha Touch] 移动开发77 Cordova Hot Code Push插件实现自己主动更新App的Web内容

    原文地址:http://blog.csdn.net/lovelyelfpop/article/details/50848524 插件地址:https://github.com/nordnet/cord ...

  2. iOS上简单推送通知(Push Notification)的实现

    iOS上简单推送通知(Push Notification)的实现 根据这篇很好的教程(http://www.raywenderlich.com/3443/apple-push-notification ...

  3. Send push notification on Apple (APNS) on c#.net

    原文: http://apns-c-sharp-net-vikram-jain.blogspot.com ======================= Please, Install your ce ...

  4. 远程通知APNs(Apple Push Notification Server)

    推送通知是由应用服务提供商发起的,通过苹果的APNs(Apple Push Notification Server)发送到应用客户端.下面是苹果官方关于推送通知的过程示意图: 推送通知的过程可以分为以 ...

  5. apple 官方文档 Push Notification Programming

    iOS Developer LibraryDeveloper Search Local and Push Notification Programming Guide PDF Table of Con ...

  6. push notification for iphone

    由于公司业务需求,以前一直做PHP开发,突然让我研究push notification ,一下子迷糊啦,不知所措,抓狂!但是在自己的努力下还是初有成效!现拿出来显摆一下! 1:push notific ...

  7. Provider Communication with Apple Push Notification Service

    This chapter describes the interfaces that providers use for communication with Apple Push Notificat ...

  8. (转)How to build an Apple Push Notification provider server (tutorial)

    转自:https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/ ...

  9. (转)Apple Push Notification Services in iOS 6 Tutorial: Part 2/2

    转自:http://www.raywenderlich.com/32963/apple-push-notification-services-in-ios-6-tutorial-part-2 Upda ...

随机推荐

  1. 12款响应式的 jQuery 旋转木马(传送带)插件

    在企业网站,作品集网站,电子商务网站或任何其他类型的网站内容显示图片可以使用 jQuery 旋转木马(传送带)插件来实现. jQuery 旋转木马插件允许开发人员以水平或垂直的方式显示内容,视频和图像 ...

  2. imagesLoaded – 检测网页中的图片是否加载

    imagesLoaded 是一个用于来检测网页中的图片是否载入完成的 JavaScript 工具库.支持回调的获取图片加载的进度,还可以绑定自定义事件.可以结合 jQuery.RequireJS 使用 ...

  3. 【初窥javascript奥秘之事件机制】论“点透”与“鬼点击”

    前言 最近好好的研究了一番移动设备的点击响应速度,期间不断的被自己坑,最后搞得焦头烂额,就是现在可能还有一些问题,但是过程中感觉自己成长不少, 最后居然感觉对javascript事件机制有了更好的认识 ...

  4. float 和 inline-block的心得

    float 优点: 横向排列时比较方便,不存在浏览器兼容问题. 缺点: 1)多行横向排行时,换行后经常不能顶行显示. 2)浮动后会跳出当前流,造成父元素高度塌陷,解决办法比较成熟统一 ,不存在浏览器兼 ...

  5. SharePoint Online 创建门户网站系列之定制栏目

    前 言 SharePoint Online自带的库就带有二级页面和详细页面,也就是Allitems页面和DispForm页面,但是实在不够美观,尤其对于门户网站这一企业门面来说,更是无法接受. 下面, ...

  6. JavaScript学习07 内置对象

    JavaScript内置对象 图像对象 导航对象 窗口对象 屏幕对象 事件对象 历史对象 文件对象(重要) 锚点对象 链接对象 框架对象 表单对象(重要) 位置对象 JS Window 窗口对象:ht ...

  7. 通知 - NSNotificationCenter

    1.每一个应用程序都有一个通知中心(NSNotificationCenter)实例,专门负责协助不同对象之间的消息通信: 2.任何一个对象都可以向通知中心发布通知(NSNotification), 描 ...

  8. 【代码笔记】iOS-点击搜索跳转到另外一个页面

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  9. GCD中的dispatch_group函数的详解

    <一>引入dispatch_group函数的目的 在追加到dispatch_Queue中的多个处理全部结束后想要执行结束的处理,这种需求经常会在我们的程序中出现 (第一种情况)只使用一个S ...

  10. Java 线程池

    系统启动一个线程的成本是比较高的,因为它涉及到与操作系统的交互,使用线程池的好处是提高性能,当系统中包含大量并发的线程时,会导致系统性能剧烈下降,甚至导致JVM崩溃,而线程池的最大线程数参数可以控制系 ...