本文转自: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. 纯CSS3写的10个不同的酷炫图片遮罩层效果

    这个是纯CSS3实现的的10个不同的酷炫图片遮罩层效果,可以欣赏一下 在线预览 下载地址 实例代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...

  2. 赞!带进度条的 jQuery 文件拖放上传插件

    jQuery File Uploader 是一个 jQuery 文件拖放上传插件,包括 Ajax 上传和进度条效果.作者编写这个插件的想法是要保持它非常简单,不像其他的插件,很多的标记,并提供一些 H ...

  3. HTML中表单提交数据GET、POST的区别

    表单提交数据Get和Post的区别: GET和POST是表单提交数据其中的两种方式,除此之外还有PUT.DELETE等. GET: GET的请求起因于正常的URL请求,或是没有指定METHOD的HTM ...

  4. python任务执行之线程,进程,与协程

    一.线程 线程为程序中执行任务的最小单元,由Threading模块提供了相关操作,线程适合于IO操作密集的情况下使用 #!/usr/bin/env python # -*- coding:utf-8 ...

  5. 也来谈谈wap端瀑布流布局

    Definition 瀑布流布局,在视觉上表现为参差不齐的多栏布局,随着页面滚动条向下滚动,新数据不断被加载进来. 瀑布流对于图片的展现,是高效而具有吸引力的,用户一眼扫过的快速阅读模式可以在短时间内 ...

  6. 【原】iOS动态性(二):运行时runtime初探(强制获取并修改私有变量,强制增加及修改私有方法等)

    OC是运行时语言,只有在程序运行时,才会去确定对象的类型,并调用类与对象相应的方法.利用runtime机制让我们可以在程序运行时动态修改类.对象中的所有属性.方法,就算是私有方法以及私有属性都是可以动 ...

  7. Autodesk 360 Viewer 已经发布到Autodesk 360平台

    我们之前已经在小范围内透露过,Autodesk 将发布一款完全无需插件的三维模型浏览器 Autodesk 360 Viewer,比如我们的Meetup线下小聚会,或者黑客马拉松(hackathon)的 ...

  8. 使用Autodesk OAuth服务在用户认证的示例

    大家知道以Autodesk 360为核心的Autodesk 云服务已经陆续发布,ReCap API.InfraWorks API和PLM 360 REST API已经开始的Pilot项目供第三方开发者 ...

  9. Java虚拟机JVM学习01 流程概述

    Java虚拟机JVM学习01 流程概述 Java虚拟机与程序的生命周期 一个运行时的Java虚拟机(JVM)负责运行一个Java程序. 当启动一个Java程序时,一个虚拟机实例诞生:当程序关闭退出,这 ...

  10. sqlite锁的机制

     reserved state 进入reserved state以后,sqlite可以修改数据库中的内容,不过把修改以后的内容写到pager的缓存里,大小由page cache指定. 进入这个状态以 ...