Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
cordova-plugin-leancloud-push
Advanced tools
A Cordova plugin for LeanCloud Push and Analytics services
基于 LeanCloud 推送和统计的 Cordova 插件
cordova plugin add https://github.com/wujun4code/cordova-plugin-leanpush.git --variable LEAN_APP_ID=<你的 App Id> --variable LEAN_APP_KEY=<你的 App Key>
在 gulpfile.js
里面添加如下代码:
gulp.task('lpush-install', function(done){
require('./plugins/cordova-plugin-leanpush/lpush-installer.js')(__dirname, done);
});
然后安装如下 2 个组件
npm install --save-dev xml2js thunks && npm install
最后执行以下 gulp 任务:
gulp lpush-install
完成
在 "deviceReady" 方法中初始化 LeanCloud(比如 $ionicPlatform.ready)
window.LeanPush.init();
Leancloud Push 开发指南](https://leancloud.cn/docs/ios_push_guide.html).
window.LeanPush.subscribe(channel, success, error) // 订阅频道 channel :string
window.LeanPush.unsubscribe(channel, success, error) //退订频道 channel :string
window.LeanPush.clearSubscription(success, error) //退订所有频道
一个 Installation 对象对应着一台设备,iOS 设备第一次启动 app 的时候会弹出提示,是否允许当前 app 使用推送,当用户点击 「允许」 之后,LeanCloud SDK 就会注册一个 iOS 设备推送的 DeviceToken 并且将它存储在 _Installation
表里。
window.LeanPush.getInstallation(function(data){
data = {
'deviceType':'android' or 'ios',
'installationId': 'android installation id' or 'ios deviceToken'// `installationId` 是保存之后从服务端返回的当前设备对应的 installation 表里面的 `objectId`
'deviceToken': 'ios deviceToken' or 'android installation id'
}
}, function(error) {
});
window.LeanPush.onNotificationReceived(function(data){
data = {
"alert": "消息内容",
"category": "通知分类名称",
"badge": "未读消息数目",
"sound": "声音文件名",
"content-available": "如果你在使用 Newsstand,设置为 1 来开始一次后台下载",
"prevAppState": 'background' or 'foreground' or 'closed'
// push到来的时候上一个App状态:
// android只有 'background' 和 'closed', 因为android所有push都要点击
// ios都有,因为ios如果app在前台,系统推送的alert不会出现
// 用户没有任何操作,app就自动执行notification的函数不好, 可以加个判断
};
});
假设服务端推送的格式如下:
{
"alert": "消息内容",
"category": "通知分类名称",
"badge": "未读消息数目",
"sound": "声音文件名",
"content-available": "如果你在使用 Newsstand,设置为 1 来开始一次后台下载"
}
客户端接收的格式如下:
{
"alert": "消息内容",
"category": "通知分类名称",
"badge": "未读消息数目",
"sound": "声音文件名",
"content-available": "如果你在使用 Newsstand,设置为 1 来开始一次后台下载"
"prevAppState": 'background' or 'foreground' or 'closed'
}
注:针对 iOS 特殊的接收格式在接收之后做了解包处理,保证和 Android 接收的格式是一样的。因此在 window.LeanPush.onNotificationReceived(callback)
可以统一处理格式,无需再判断 deviceType 是 iOS 而做特殊处理。
$rootScope.$on('leancloud:notificationReceived', callback) // 如果你用了angular, 一个notification会在scope上broadcast这个event
// callback:
// function(event, notice){
// // event is from angular, notice is same above
// }
感谢 Derek Hsu
可以参考 https://github.com/Hybrid-Force/cordova-plugin-leancloud.
关于统计部分的使用可以参考:https://github.com/BenBBear/cordova-plugin-leanpush/blob/master/www/LeanAnalytics.js I
See the Attention Below, the webview can't alert
when onResume
The onNotificationReceived callback
and the $rootScope.$emit('leancloud:notificationReceived')
will fires when
请确保一定要先执行 gulp 任务: lpush_installer.js
执行如下脚本:
cordova plugin rm cordova-plugin-leanpush
ionic platform rm android && ionic platform rm ios
ionic platform add android && ionic platform add ios
以下两种方法都可以获取通知:
onNotificationReceived
$rootScope.$emit('leancloud:notificationReceived')
You can choose one of them, but may not both.
在 platforms/android/build.gradle
找到 android
标签,然后添加如下内容:
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
使其内容如下:
android{
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
//其他 gradle 的设置
}
The MIT License (MIT)
Copyright (c) 2015 Xinyu Zhang, Derek Hsu,Wu Jun
FAQs
A Cordova plugin for LeanCloud Push and Analytics services
The npm package cordova-plugin-leancloud-push receives a total of 0 weekly downloads. As such, cordova-plugin-leancloud-push popularity was classified as not popular.
We found that cordova-plugin-leancloud-push demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.