本文转自: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. mousewheel

    判断鼠标往上还是往下滚动 html代码: <div class="div"> </div> css代码: .div{ position:absolute; ...

  2. URL(统一资源定位符)结构和注意事项

    URL的常见结构: http://localhost/项目名称/文件1/文件2... 注意事项: 当我们在项目中在书写URL的时候,一般会出现两种情况: 第一种:在路径前面加上/,表示直接连在loca ...

  3. Spring AOP专业术语解析

    一. 连接点(Joinpoint) 连接点就是程序执行的某个特定的位置,如:类开始初始化前.类初始化后.类的某个方法调用前.类的某个方法调用后.方法抛出异常后等.Spring 只支持类的方法前.后.抛 ...

  4. linux命令学习使用记录

    1.文件批量重命名:把所有.xml文件重命名.txt,第一个参数为文件名中字符串,第二个参数为替换后文件名,第三个为当前目录文件列表 rename .xml .txt *.xml 2.解压不显示过程: ...

  5. 制作具有SSH、MySQL功能的Chroot

    由于工作需求,需要在Linux上建立SSH.MySQL两个用户. 使这两个账户连接到跳板机后仅能执行有限的命令(SSH用户只能执行SSH命令,MySQL用户只能执行MySQL命令). MySQL账户C ...

  6. ios 颜色转图片

    - (UIImage *)imageWithColor:(UIColor*) color{    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);    ...

  7. OC 类方法,对象方法,构造方法以及instancetype和id的异同

    OC 类方法,对象方法,构造方法以及instancetype和id的异同 类方法: 类方法是可以直接使用类的引用,不需要实例化就可以直接使用的方法.一般写一些工具方法. 类方法: 声明和实现的时候,以 ...

  8. GHOST WIN7系统64位经典优化版 V2016年

    来自系统妈:http://www.xitongma.com 深度技术GHOST win7系统32,64位经典优化版 V2016年3月 系统概述 深度技术ghost win7系统64位经典优化版适用于笔 ...

  9. iOS之 开发常用到的宏定义

    不久前做过一个小项目种用到了就记录下来方便自己以后使用,一个非常实用的宏定义来打印函数名称等 #ifdef DEBUG #define DebugLog(fmt, ...) NSLog((@" ...

  10. SQL server 2014安装以及解决连接数据库失败问题

    安装教程:http://jingyan.baidu.com/article/3a2f7c2e653d5926afd61197.html 安装好之后打开SQL server 2014 Managemen ...