Giter VIP home page Giter VIP logo

cordova-plugin-leanpush's Introduction

cordova-plugin-leanpush

Cordova plugin for LeanCloud push notification

Installation

  • Fetch from cordova npm
 cordova plugin add cordova-plugin-leanpush  --variable LEAN_APP_ID=<YOUR_LEANCOULD_APP_ID> --variable LEAN_APP_KEY=<YOUR_LEANCOULD_APP_KEY>
  • Add this to your gulpfile.js
gulp.task('lpush-install', function(done){
    require('./plugins/cordova-plugin-leanpush/lpush-installer.js')(__dirname, done);
});
  • npm install --save-dev xml2js thunks && npm install

  • Then exectue this gulp task by running gulp lpush-install in shell.

  • Done.

Known Android Build Issue

See Attention/Android Build Issue

Usage

Init

Put the initialization Code in your "deviceReady" Code Block (like $ionicPlatform.ready)

window.LeanPush.init();

Push Related API

Coresponding to the Leancloud Push documentation.

window.LeanPush.subscribe(channel, success, error)  // 订阅频道 channel :string 
window.LeanPush.unsubscribe(channel, success, error) //退订频道 channel :string
window.LeanPush.clearSubscription(success, error) //退订所有频道 

window.LeanPush.getInstallation(success, error)  //Installation 表示一个允许推送的设备的唯一标示, 对应数据管理平台中的 _Installation 表
// success callback:
// function(data){
//   data = {
//        'deviceType':'android' or 'ios',
//        'installationId': 'android installation id' or 'ios deviceToken'
//        'deviceToken':    'ios deviceToken' or 'android installation id'
//   }
// }


window.LeanPush.onNotificationReceived(callback) // 一个notification到来的回调函数
// callback:
// function(notice){
//  notice = {
//     'prevAppState': 'background' or 'foreground' or 'closed',

//      push到来的时候上一个App状态:
//      android只有 'background' 和 'closed', 因为android所有push都要点击
//      ios都有,因为ios如果app在前台,系统推送的alert不会出现
//      用户没有任何操作,app就自动执行notification的函数不好, 可以加个判断

//     'alert':'Notice Text',
//     'file_url':'Push File',
//     'key':'value'   if you send JSON Type Push, they will map to here.
//   }
// }
    

$rootScope.$on('leancloud:notificationReceived', callback) // 如果你用了angular, 一个notification会在scope上broadcast这个event
// callback:
// function(event, notice){
//    // event is from angular, notice is same above 
// }

Many Thanks to Derek Hsu XD 😁

About Sending Push

Use the JS API: AV.Push that leancloud provide.

LeanAnalytics API

Corresponding code is forked from https://github.com/Hybrid-Force/cordova-plugin-leancloud.

Only a novice for leancloud I am, so

is the better way to go.


Screen Recording

Android

IOS

See the Attention Below, the webview can't alert when onResume

One

  • notice from close
  • notice while foreground

Two

  • notice from background
mobile

console.log

The debugger in screenshot is GapDebug, debug phonegap in browser :D

Behavior

The onNotificationReceived callback and the $rootScope.$emit('leancloud:notificationReceived') will fires when

IOS

  • app in the foreground, notice comes (won't show the system notification alert)
  • app in the background, tap the notification to resume it
  • app closed, tap the notification to open it

Android

  • app in the foreground, tap the notification to see it
  • app in the background, tap the notification to resume it
  • app closed, tap the notification to open it

Attention

Android Quirk

In order to receive push from android, I change the default MainActivity and Application Entry in that gulp task. Details in the lpush_installer.js.

So if you use another plugin that also goes this way, then there gonna be conflicts.

Uninstall

For fully uninstallation:

cordova plugin rm cordova-plugin-leanpush
ionic platform rm android && ionic platform rm ios
ionic platform add android && ionic platform add ios

Don't Use Alert in the IOS inside Notification Callback

alert is a blocking function.

IOS UIWebView

It will cause the app to freeze when you resume the app by clicking notification. (but it seems ok when the app is in the foreground or closed.)

For Android

As far as I try, alert is fine, guess is the difference of webView between IOS and android.

Notification Handler

There are two ways, both will be fired when notification comes

  • onNotificationReceived

  • $rootScope.$emit('leancloud:notificationReceived')

You can choose one of them, but may not both.

Android Build Issue

  • Error: duplicate files during packaging of APK

How to Solve:

insert following code into the android tag of platforms/android/build.gradle

 packagingOptions {
       exclude 'META-INF/LICENSE.txt'
 	   exclude 'META-INF/NOTICE.txt'
}

It should look like below

android{
   packagingOptions {
       exclude 'META-INF/LICENSE.txt'
 	   exclude 'META-INF/NOTICE.txt'
   }
    //stuff
}

LICENSE

The MIT License (MIT)

Copyright (c) 2015 Xinyu Zhang, Derek Hsu

cordova-plugin-leanpush's People

Contributors

hybrid-force avatar yesir1006 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-leanpush's Issues

Fetching from npm failed: certificate not trusted

Fetching plugin "cordova-plugin-leanpush" via npm
npm http GET https://registry.npm.taobao.org/cordova-plugin-leanpush
npm http GET https://registry.npm.taobao.org/cordova-plugin-leanpush
npm http GET https://registry.npm.taobao.org/cordova-plugin-leanpush
Fetching from npm failed: certificate not trusted
Error: certificate not trusted
at Error (native)
at TLSSocket. (_tls_wrap.js:929:36)
at TLSSocket.emit (events.js:104:17)
at TLSSocket._finishInit (_tls_wrap.js:460:8)

android error in app closed when tap the notification to open it

I found when tap the notification to open the closed app in android, it occurs error : ' Application Error - The connection to the server was unsuccessful. (file://android_asset/www/index.html ';
But the app run success when load it commonly.

(我发现点击推送,app启动的时候,会有如上的错误,但是平常正常启动APP是没有问题)

Cordova 6.1
Android 5.0

leancloud管理台没有installation数据

你好,
非常感谢分享这个插件,我

  1. 按照文档介绍安装好了这个插件
  2. 在$ionicPlatform.ready中加入了window.LeanPush.init();
  3. 在XCode里打包出IPA
  4. 在分发平台(蒲公英)分发并安装
  5. 启动App
    但是并没有在leancloud管理台中看到installation数据,请问一下我哪里做的有问题呢?我对这块也不太熟。

感谢!

是否支持声音播放

首先感恩这么好的插件(发自肺腑的感觉方便了很多工作!!!

想问下插件中是否支持声音?
简单搜索了一下sound,貌似并没有。

如果支持,求作者简单提示,剩下我自己查资料或补代码。
(已经用了插件,已经没脸做伸手坐等党了……但确实不会任何原生代码,项目时间也不允许现学

badge的数量为什么需要在每次打开APP时清除?

如题,badge的数量在打开APP时会自动清除,到时APP中维护badge的逻辑失效,请问是否有其他配置项配置这个地方?因为我们的APP的badge数量是根据未读状态的消息统计出来的,APP中以及server端会自动维护badge的数量,所以想问一下为何会需要自动清除badge的逻辑?

gulpfile文件是什么的

gulpfile.js是做什么用的?我用的是 visual studio 2015 生成cordova 工程,目录下没有这个文件。

Xcode真机运行报错

你好,我在使用这个插件的时候,发现Xcode编译总是会报错:
Undefined symbols for architecture arm64:
"OBJC_CLASS$_AVInstallation", referenced from:
objc-class-ref in CDVLeanPush.o
objc-class-ref in AppDelegate+LeanPush.o
"OBJC_CLASS$_AVOSCloud", referenced from:
objc-class-ref in AppDelegate+LeanPush.o
"OBJC_CLASS$_AVAnalytics", referenced from:
objc-class-ref in CDVLeanAnalytics.o
objc-class-ref in AppDelegate+LeanPush.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

xcode编译报错

使用xcode编译时报错:
Plugins/cordova-plugin-leanpush/CDVLeanPush.m:137:23: error: no visible @interface for 'UIView' declares the selector 'stringByEvaluatingJavaScriptFromString:'
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

本地环境:cordova 6.0.0

不知是否和cordova版本有关?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.