Giter Club home page Giter Club logo

jpush-phonegap-plugin's Introduction

JPush PhoneGap / Cordova Plugin

Build Status release platforms weibo

极光官方支持的 cordova 推送插件。

注意:插件从 v3.4.0 开始支持 cordova-android 7.0.0,因 cordova-android 7.0.0 修改了 Android 项目结构,因此不兼容之前的版本,升级前请务必注意。

如果需要在cordova-android 7.0.0之前版本集成最新插件,参照这篇文章

如果需要安装之前版本的插件,请先安装 v1.2.0 以下版本(建议安装 v1.1.12)的 cordova-plugin-jcore,再安装旧版本插件(比如 v3.3.2),否则运行会报错。

Cordova Android版本与原生版本对应表

Install

注意:

  • 应用的包名一定要和 APP_KEY 对应应用的包名一致,否则极光推送服务无法注册成功。
  • 在使用 8 或以上版本的 Xcode 调试 iOS 项目时,需要先在项目配置界面的 Capabilities 中打开 Push Notifications 开关。
  • 通过 Cordova Plugins 安装,要求 Cordova CLI 5.0+:

    cordova plugin add jpush-phonegap-plugin --variable APP_KEY=your_jpush_appkey
  • 或直接通过 url 安装:

    cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable APP_KEY=your_jpush_appkey
  • 或下载到本地安装:

    cordova plugin add Your_Plugin_Path --variable APP_KEY=your_jpush_appkey

参数

  • APP_KEY: 必须设置,JPush 上注册的包名对应的 Appkey

    --variable APP_KEY=your_jpush_appkey
  • CHANNEL: 可以不设置,v3.6.0+ 版本开始支持(Android Only),方便开发者统计 APK 分发渠道,默认为 developer-default.

    --variable CHANNEL=your_channel
  • 同时动态配置 APP_KEY 和 CHANNEL 示例

    cordova plugin add jpush-phonegap-plugin --variable APP_KEY=your_jpush_appkey --variable CHANNEL=your_channel

Ionic

如果使用了 Ionic,可以再安装 @jiguang-ionic/jpush 包,适配 ionic-native:

npm install --save @jiguang-ionic/[email protected]

# npm install --save @jiguang-ionic/[email protected] for ionic4+

然后在 app.module.ts 中增加:

// @jiguang-ionic/[email protected]+
import { JPush } from '@jiguang-ionic/jpush';

// @jiguang-ionic/[email protected]+
import { JPush } from '@jiguang-ionic/jpush/ngx';
...
  providers: [
    ...
    JPush,
    ...
  ]

具体可参考 ./ionic/example 中的文件。

Usage

API

Demo

插件项目中包含一个简单的 Demo。若想参考,可以在 /example 文件夹内找到并拷贝以下文件:

example/index.html -> www/index.html
example/css/* -> www/css
example/js/* -> www/js

关于 PhoneGap build 云服务

该项目基于 Cordova 实现,目前无法使用 PhoneGap build 云服务进行打包,建议使用本地环境进行打包。

FAQ

如果遇到了疑问,请优先参考 Demo 和 API 文档。若还无法解决,可到 Issues 提问。

Android

在 Eclipse 中 import 工程之后出现:Type CallbackContext cannot be resolved to a type

右键单击工程名 -> Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。

无法获取到 Registration Id

检查 AppKey 和应用包名是否对应、是否调用了 init 方法。

如何自定义通知声音?

Android 因为各 Rom 的高度定制化,不像 iOS 一样能有一个统一的管理,如果在 Android 中想自定义通知铃声,推荐通过 JPush 推送自定义 消息,之后在 jpush.receiveMessage 事件监听中通过 Cordova Local-Notification Plugin 触发通知,再配合 Cordova Background Plugin 插件保证应用的后台运行。

如何让通知内容像 iOS 一样自动换行展示?

#267

关闭 App 后收不到通知

Android 的推送通过长连接的方式实现,只有在保持连接的情况下才能收到通知。而有的第三方 ROM 会限制一般应用服务的自启动,也就是在退出应用后,应用的所有服务均被杀死,且无法自启动,所以就会收不到通知。

目前 JPush 是做了应用互相拉起机制的,也就是当用户打开其他集成了 JPush 的应用时,你的应用也能同时收到推送消息。

如果你的应用希望随时都能收到推送,官方推荐是通过文案的方式引导用户在设置中允许你的应用能够自启动,常见机型的设置方法可以参考这里

或者自己实现应用保活,网上有很多相关文章(不推荐)。

为什么 QQ、微信之类的应用退出后还能够收到通知?因为这些大厂应用,手机厂商默认都会加入自启动白名单中,也不会在应用退出后杀死它们的相关服务。 如果你多加留意,就会发现非大厂的应用如果你一段时间不用都是收不到推送的。

iOS

XCode 10 收不到推送怎么办?

打开 xcode -> file -> WorkSpace Settings… -> Build System 改成 Legacy Build System 然后卸载 App 重新运行。

打包时遇到 i386 打包失败怎么办?

cordova platform update ios

PushConfig.plist 文件中的字段都是什么意思?

  • Appkey:应用标识。
  • Channel:渠道标识。
  • IsProduction:是否生产环境。
  • IsIDFA:是否使用 IDFA 启动 SDK。

刚集成完插件收不到推送怎么办?

请首先按照正确方式再次配置证书、描述文件,具体可参考 iOS 证书设置指南

iOS 集成插件白屏、或无法启动插件、或打包报错无法找到需要引入的文件怎么办?

按照以下步骤逐个尝试:

  • 升级至最新版本 Xcode
  • 删除插件、再重装插件(先使用 cordova platform add ios,后使用 cordova plugin add

Support

Contribute

Please contribute! Look at the issues.

License

MIT © JiGuang

jpush-phonegap-plugin's People

Contributors

annilq avatar darkterrorooo avatar hailiang-wang avatar huangminlinux avatar huangshuni avatar javenfang avatar joshlipan avatar lcterry avatar lhw5123 avatar lincolnlk avatar pikacode avatar recharlee avatar reyoung avatar weiruiyang avatar wgjtyu avatar withwind8 avatar yaonie084 avatar zhangqinghe avatar zikko2017 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  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

jpush-phonegap-plugin's Issues

附加字段的自定义消息,json格式问题

{
"message": "a",
"extras": {
"cn.jpush.android.MSG_ID": "941365619",
"cn.jpush.android.EXTRA": "{"b":"c"}",
"cn.jpush.android.CONTENT_TYPE": ""
}
}
这个是通过控制台发送的 一条 自定义 附加字段的信息
添加字段b 内容 为c

这一行的 json 在JSON.parse() 会报错
是不是应该 去掉 extra 后面那个大括号的 双引号
"cn.jpush.android.EXTRA": {"b":"c"},

监听新安装应用的权限问题

我打包了一个包含jpush库的Android app,提交到豌豆荚,但是提示:
请补充「监听新安装应用」权限的用途解释.

我在jpush网站看了下好像是jpush库添加的,如果是没有用的,可以删掉么?
我对phonegap插件不熟,我手动在AndroidManifest.xml里面删掉下面这一段:

<intent-filter>
    <action android:name="android.intent.action.PACKAGE_ADDED"/>
    <action android:name="android.intent.action.PACKAGE_REMOVED"/>
    <data android:scheme="package"/>
</intent-filter>

然后用cordova build --release android。好像还是会另外一个包含上面这段内容的的元素被添加上去添加上去,导致有两个同样的receiver元素,编包出错。

请问这个怎么解决?谢谢

cordova build android 失败

-compile:
[javac] Compiling 7 source files to /Users/zhanghong/dev/androidapp/pushtest/platforms/android/ant-build/classes
[javac] /Users/zhanghong/dev/androidapp/pushtest/platforms/android/src/cn/jpush/phonegap/JPushPlugin.java:139: cannot find symbol
[javac] symbol : method isPushStopped(android.content.Context)
[javac] location: class cn.jpush.android.api.JPushInterface
[javac] JPushInterface.isPushStopped(this.cordova.getActivity().getApplicationContext());
[javac] ^
[javac] /Users/zhanghong/dev/androidapp/pushtest/platforms/android/src/cn/jpush/phonegap/JPushPlugin.java:269: package R does not exist
[javac] this.cordova.getActivity(), R.layout.test_notitfication_layout,
[javac] ^
[javac] /Users/zhanghong/dev/androidapp/pushtest/platforms/android/src/cn/jpush/phonegap/JPushPlugin.java:270: package R does not exist
[javac] R.id.icon, R.id.title, R.id.text);
[javac] ^
[javac] /Users/zhanghong/dev/androidapp/pushtest/platforms/android/src/cn/jpush/phonegap/JPushPlugin.java:270: package R does not exist
[javac] R.id.icon, R.id.title, R.id.text);
[javac] ^
[javac] /Users/zhanghong/dev/androidapp/pushtest/platforms/android/src/cn/jpush/phonegap/JPushPlugin.java:270: package R does not exist
[javac] R.id.icon, R.id.title, R.id.text);
[javac] ^
[javac] /Users/zhanghong/dev/androidapp/pushtest/platforms/android/src/cn/jpush/phonegap/JPushPlugin.java:272: package R does not exist
[javac] builder.layoutIconDrawable = R.drawable.jpush_notification_icon;
[javac] ^
[javac] 6 errors

BUILD FAILED
/usr/local/Cellar/android-sdk/22.3/tools/ant/build.xml:720: The following error occurred while executing this line:
/usr/local/Cellar/android-sdk/22.3/tools/ant/build.xml:734: Compile failed; see the compiler error output for details.

Total time: 9 seconds
Error code 1 for command: ant with args: debug,-f,/Users/zhanghong/dev/androidapp/pushtest/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: /Users/zhanghong/dev/androidapp/pushtest/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/src/superspawn.js:112:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:735:16)
at Process.ChildProcess._handle.onexit (child_process.js:802:5)
monsterstep:pushtest zhanghong$

不能初始

在app.js 初始化时,window.plugins.jPushPlugin.init();模拟器下出错 Unable to get property 'jPushPlugin' of undefined or null reference。

怎么修改JPUSH_APPKEY?

在config.xml中增加<gap:config-file ...> ...,最终生成的AndroidManifest.xml中会有2个meta-data android:name="JPUSH_APPKEY", 直接修改plugins.xml中的APPKEY也是一样

receiveMessageInAndroidCallback v.s. openNotificationInAndroidCallback

Description

I am using jPush Cordova Plugin now, after reading the doc, I am not sure what the difference between receiveMessageInAndroidCallback and openNotificationInAndroidCallback ?

JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
    try{
        console.log("JPushPlugin:receiveMessageInAndroidCallback");
        //console.log(data);
        //ecvar bToObj=JSON.parse(data);
        //var message  = bToObj.message;
        //var extras  = bToObj.extras;

        //console.log(message);
        //console.log(extras['cn.jpush.android.MSG_ID']);
        //console.log(extras['cn.jpush.android.CONTENT_TYPE']);
        //console.log(extras['cn.jpush.android.EXTRA']);
    }
    catch(exception){               
        console.log("JPushPlugin:pushCallback "+exception);
    }
}
//
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
    try{
        console.log("JPushPlugin:openNotificationInAndroidCallback");       
        console.log(data);
        //var bToObj  = JSON.parse(data);
        //var alert   = bToObj.alert;
        //var extras  = bToObj.extras;
        //console.log(alert);

        //console.log(extras['cn.jpush.android.MSG_ID']);
        //console.log(extras['app']);
        //console.log(extras['cn.jpush.android.NOTIFICATION_CONTENT_TITLE']);
        //console.log(extras['cn.jpush.android.EXTRA']);
        //console.log(extras['cn.jpush.android.PUSH_ID']);
        //console.log(extras['cn.jpush.android.NOTIFICATION_ID']);
        //console.log("JPushPlugin:openNotificationCallback is ready");
    }
    catch(exception){               
        console.log(exception);
    }
}

Can anyone help ? Thanks.

关于如何[添加统计代码]的疑问

Hi:
很高兴极光能在国内 PhoneGap 基本无人问及的情况下依然推出了此插件!
按照 Readme 的步骤,我已成功接收到了测试推送。但是遇到了[需要添加统计代码]的提醒
请问,我能为我的应用添加代码统计功能吗?
如果可以,我需要进行怎么样的操作?
谢谢!

jpushplugin.m 中的部分方法 失效

  • (CDVPlugin_)initWithWebView:(UIWebView_)theWebView{
    if (self=[super initWithWebView:theWebView]) {

    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    [defaultCenter addObserver:self
                      selector:@selector(networkDidReceiveMessage:)
                          name:kJPFNetworkDidReceiveMessageNotification
                        object:nil];
    
    [defaultCenter addObserver:self
                      selector:@selector(networkDidReceiveNotification:)
                          name:kJPushPluginReceiveNotification
                        object:nil];
    

    }
    return self;
    }

以上两个监听的 函数 前端无法收到回调

-(void)networkDidReceiveNotification:(id)notification{

NSError  *error;
NSDictionary *userInfo = [notification object];

NSData   *jsonData   = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];


dispatch_async(dispatch_get_main_queue(), ^{
    [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]];
});

}

前端

var onOpenNotification = function(event){
try{
var alert = event.alert;
var extras = event.extras;
alert(alert);
//console.log(extras);
}
catch(exeption){
console.log(exception)
}
}

document.addEventListener("jpush.receiveNotificatio", onOpenNotification, false);

获取不到信息 = - = 怎么办

meteor 集成问题

不能初始化,我是用安卓手机usb调试
Uncaught TypeError: Cannot call method 'init' of undefined
window.plugins.jPushPlugin 找不到
请问是什么问题引起

文档错误!!!

ios文档中清除ios角标的实例是错误的!window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0)

请教问题,ionic+ngcordova添加jpush后运行 ionic build android编译错误

系统环境:windows7 64位 ionic+ngcordova

BUILD FAILED
E:\Android\android-sdk\tools\ant\build.xml:720: The following error occurred whi
le executing this line:
E:\Android\android-sdk\tools\ant\build.xml:734: Compile failed; see the compiler
error output for details.

Total time: 1 second

D:\2015\app\code\myApp\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s /c "ant debug -f D:\2015\app\code\my
App\platforms\android\build.xml -Dout.dir=ant-build -Dgen.absolute.dir=ant-gen"

我跟随guide安装出现了 “ 错误: 程序包R不存在 ” 的问题,请高手帮我解答一下,谢谢

[javac] Compiling 8 source files to /Users/ethanwang/mobile/my2/platforms/android/ant-build/classes
[javac] /Users/ethanwang/mobile/my2/platforms/android/src/cn/jpush/phonegap/JPushPlugin.java:341: 错误: 程序包R不存在
[javac] this.cordova.getActivity(), R.layout.test_notification_layout,
[javac] ^
[javac] /Users/ethanwang/mobile/my2/platforms/android/src/cn/jpush/phonegap/JPushPlugin.java:342: 错误: 程序包R不存在
[javac] R.id.icon, R.id.title, R.id.text);
[javac] ^
[javac] /Users/ethanwang/mobile/my2/platforms/android/src/cn/jpush/phonegap/JPushPlugin.java:342: 错误: 程序包R不存在
[javac] R.id.icon, R.id.title, R.id.text);
[javac] ^
[javac] /Users/ethanwang/mobile/my2/platforms/android/src/cn/jpush/phonegap/JPushPlugin.java:342: 错误: 程序包R不存在
[javac] R.id.icon, R.id.title, R.id.text);
[javac] ^
[javac] /Users/ethanwang/mobile/my2/platforms/android/src/cn/jpush/phonegap/JPushPlugin.java:344: 错误: 程序包R不存在
[javac] builder.layoutIconDrawable = R.drawable.jpush_notification_icon;
[javac] ^
[javac] 注: 某些输入文件使用或覆盖了已过时的 API。
[javac] 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
[javac] 5 个错误

BUILD FAILED
/Users/ethanwang/Library/Android/sdk/tools/ant/build.xml:720: The following error occurred while executing this line:
/Users/ethanwang/Library/Android/sdk/tools/ant/build.xml:734: Compile failed; see the compiler error output for details.

Total time: 3 seconds

/Users/ethanwang/mobile/my2/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: ant with args: debug,-f,/Users/ethanwang/mobile/my2/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
ERROR building one of the platforms: Error: /Users/ethanwang/mobile/my2/platforms/android/cordova/build: Command failed with exit code 8
You may not have the required environment or OS to build this project

Android JPushPlugin:transmitPush - instance == null 导致webview没有接到message

Description

使用jpush nodejs SDK 发下面的消息

var JPush = require("jpush-sdk");
var client = JPush.buildClient('', '');

// https://github.com/jpush/jpush-api-nodejs-client
client.push().setPlatform('android')
    .setAudience(JPush.ALL)
    .setNotification('Hi, JPush', JPush.ios('ios alert', 'happy', 5))
    .setMessage('hi, JPush', 'title', 'content-type', {
        foo: 'bar'
    })
    .send(function(err, res) {
        if (err) {
            console.log(err.message);
        } else {
            console.log('Sendno: ' + res.sendno);
            console.log('Msg_id: ' + res.msg_id);
        }
    });

如果应用正在运行,不论是在background 还是 foreground. webview都正确的执行了js.

可如果应用没有运行,收到消息后,打开应用,发现webview没有执行js. 读了代码,发现了问题。

JPushPlugin.java

    static void transmitPush(String message, Map<String, Object> extras) {
        if (instance == null) { // 在应用没有运行,来消息时,这里运行,直接返回了。
            return;
        }
        JSONObject data = notificationObject(message, extras);
        String js = String
                .format("window.plugins.jPushPlugin.receiveMessageInAndroidCallback('%s');",
                        data.toString());
        try {
            instance.webView.sendJavascript(js); // 因为前面返回,这里就没有执行。
        } catch (NullPointerException e) {

        } catch (Exception e) {

        }
    }

Solution

问题的原因是应用没有运行,webview实例不存在,这样js执行不了。
我想到一个方案,使用 数据库 sqlite 做 从 native 到 webview 的数据交互。

检测到 JPushPlugin.instance == null 以后,不立即返回,而是将这条message插入到一个 sqlite 的表中,
webview启动后读取表里的内容,取完了再删除。

sqlite api

有没有更好的办法?

android版本的自定义消息接收不到extras

在文档 “通用API说明” 的 “获取自定义消息推送内容”中介绍,android端返回的数据如下:

{"message":"今天去哪儿",
"extras"{
"cn.jpush.android.MSG_ID":"154378013",
"cn.jpush.android.CONTENT_TYPE":"",
"cn.jpush.android.EXTRA":{"key":"不添没有"}
}
}
“点击通知后传递的json object 保存在window.plugins.jPushPlugin.receiveNotification,直接访问即可”

但是在测试的过程中发现,接收到的消息是保存在window.plugins.jPushPlugin.openNotification中,
而且,在没有添加附加key/value 的时候,接收到的消息只有{"message":"今天去哪儿"}

IOS平台下面集成后的结果是可以收到系统栏通知,但进入应用后获取不到推送内容,求解

HI:
最近在集成jpush在phonegap下面的项目时遇到,如题困扰。如何解决呢,
另外在www/index.html中如何调用消息内容?
JPushPlugin.prototype.receiveMessageIniOSCallback 方法在何处调用?

我的做法:
var notice_data = {};
document.addEventListener('resume', function(){
console.log('--start resume--');
window.plugins.jPushPlugin.getNotification(JPushPlugin.prototype.openNotificationInAndroidCallback,notice_data);
console.log(notice_data);
console.log("--end resume--");
},false);

但这种写法无效

为什么android版本没有receiveNotification这事件呢?

在iOS版本里面有jpush.receiveNotification事件,在接收到推送消息的时候做一些处理,但是android版本的没有jpush.receiveNotification,无法在接收消息的时候做处理,只有jpush.openNotification时间。能否为android版本的也添加jpush.receiveNotification事件呢??

“我想要获取在推送信息里的内容”

我用jpush-phongap-plugin来做了一个IOS软件。
现在从服务器发送来的推送信息准确的到我这个app,但无法获取在其内的推送内容。
现在我想要获得其内的推送内容。请告诉我调用什么接口能得到其推送内容。
太着急了,能快点就好。谢谢

onResume 和 onPause 问题

document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady(){
        document.addEventListener('pause', JPushOnPause, false);
        document.addEventListener('resume', JPushOnResume, false);
}

function JPushOnResume(){
    window.plugins.jPushPlugin.onResume();
    console.log("APP已开启");
}

function JPushOnPause( ) {
    window.plugins.jPushPlugin.onPause();
    console.log("APP进入后台");
}

这两个事件是这样调用吗?调用之后在未签名的情况下还是会提示缺少代码统计

add error

org.apache.cordova.file-system-roots installed on ios.
Fetching plugin "/Users/timger/GitHub/PhoneGapPlugins/cordova-plugins/jpush-phonegap-plugin" via plugin registry
Error: Fetching plugin failed: Error: Failed to fetch package information for /Users/timger/GitHub/PhoneGapPlugins/cordova-plugins/jpush-phonegap-plugin
    at /usr/local/lib/node_modules/cordova/src/plugin.js:105:41
    at _rejected (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:808:24)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:834:30
    at Promise.when (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:1079:31)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:752:41)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:574:44
    at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:415:13)

执行cordova build --release 时报错

1.执行cordova build 不会报错。
2.按照这个文章添加了签名https://github.com/vilic/cordova-plugin-wechat/wiki/Android-%E5%BE%AE%E4%BF%A1-SDK-%E7%AD%BE%E5%90%8D%E9%97%AE%E9%A2%98

望解答。谢谢。

报错信息如下:


W:\work\caigoubang>cordova build  --release
Running command: C:\AppCan\AppCanStudioPersonalV3.2\HDK\emulator\mas\node.exe W:\work\caigoubang\hooks\after_prepare\010_add_platform_class.js W:\work\caigouba
ng
add to body class: platform-android
Running command: W:\work\caigoubang\platforms\android\cordova\build.bat --release
ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_25
Running: W:\work\caigoubang\platforms\android\gradlew cdvBuildRelease -b W:\work\caigoubang\platforms\android\build.gradle -Dorg.gradle.daemon=true
:preBuild
:preReleaseBuild
:checkReleaseManifest
:CordovaLib:compileLint
:CordovaLib:copyReleaseLint UP-TO-DATE
:CordovaLib:mergeReleaseProguardFiles UP-TO-DATE
:CordovaLib:preBuild
:CordovaLib:preReleaseBuild
:CordovaLib:checkReleaseManifest
:CordovaLib:prepareReleaseDependencies
:CordovaLib:compileReleaseAidl UP-TO-DATE
:CordovaLib:compileReleaseRenderscript UP-TO-DATE
:CordovaLib:generateReleaseBuildConfig UP-TO-DATE
:CordovaLib:generateReleaseAssets UP-TO-DATE
:CordovaLib:mergeReleaseAssets UP-TO-DATE
:CordovaLib:generateReleaseResValues UP-TO-DATE
:CordovaLib:generateReleaseResources UP-TO-DATE
:CordovaLib:packageReleaseResources UP-TO-DATE
:CordovaLib:processReleaseManifest UP-TO-DATE
:CordovaLib:processReleaseResources UP-TO-DATE
:CordovaLib:generateReleaseSources UP-TO-DATE
:CordovaLib:compileReleaseJava UP-TO-DATE
:CordovaLib:processReleaseJavaRes UP-TO-DATE
:CordovaLib:packageReleaseJar UP-TO-DATE
:CordovaLib:compileReleaseNdk UP-TO-DATE
:CordovaLib:packageReleaseJniLibs UP-TO-DATE
:CordovaLib:packageReleaseLocalJar UP-TO-DATE
:CordovaLib:packageReleaseRenderscript UP-TO-DATE
:CordovaLib:bundleRelease UP-TO-DATE
:prepareAndroidCordovaLibUnspecifiedReleaseLibrary UP-TO-DATE
:prepareReleaseDependencies
:compileReleaseAidl UP-TO-DATE
:compileReleaseRenderscript UP-TO-DATE
:generateReleaseBuildConfig UP-TO-DATE
:generateReleaseAssets UP-TO-DATE
:mergeReleaseAssets UP-TO-DATE
:generateReleaseResValues UP-TO-DATE
:generateReleaseResources UP-TO-DATE
:mergeReleaseResources UP-TO-DATE
:processReleaseManifest UP-TO-DATE
:processReleaseResources UP-TO-DATE
:generateReleaseSources UP-TO-DATE
:compileReleaseJava UP-TO-DATE
:lintVitalRelease
W:\work\caigoubang\platforms\android\res\values\multiimagechooser_strings_en.xml:7: Error: "discard" is not translated in "de" (German), "es" (Spanish), "fr" (
French), "hu" (Hungarian), "ja" (Japanese), "ko" (Korean) [MissingTranslation]
    <string name="discard">Cancel</string>
            ~~~~~~~~~~~~~~
W:\work\caigoubang\platforms\android\res\values\multiimagechooser_strings_en.xml:8: Error: "done" is not translated in "de" (German), "es" (Spanish), "fr" (Fre
nch), "hu" (Hungarian), "ja" (Japanese), "ko" (Korean) [MissingTranslation]
    <string name="done">OK</string>
            ~~~~~~~~~~~
W:\work\caigoubang\platforms\android\res\values\strings.xml:3: Error: "app_name" is not translated in "de" (German), "es" (Spanish), "fr" (French), "hu" (Hunga
rian), "ja" (Japanese), "ko" (Korean) [MissingTranslation]
    <string name="app_name">采购邦</string>
            ~~~~~~~~~~~~~~~
W:\work\caigoubang\platforms\android\res\values\strings.xml:4: Error: "launcher_name" is not translated in "de" (German), "es" (Spanish), "fr" (French), "hu" (
Hungarian), "ja" (Japanese), "ko" (Korean) [MissingTranslation]
    <string name="launcher_name">@string/app_name</string>
            ~~~~~~~~~~~~~~~~~~~~
W:\work\caigoubang\platforms\android\res\values\strings.xml:5: Error: "activity_name" is not translated in "de" (German), "es" (Spanish), "fr" (French), "hu" (
Hungarian), "ja" (Japanese), "ko" (Korean) [MissingTranslation]
    <string name="activity_name">@string/launcher_name</string>
            ~~~~~~~~~~~~~~~~~~~~

   Explanation for issues of type "MissingTranslation":
   If an application has more than one locale, then all the strings declared
   in one language should also be translated in all other languages.

   If the string should not be translated, you can add the attribute
   translatable="false" on the <string> element, or you can define all your
   non-translatable strings in a resource file called donottranslate.xml. Or,
   you can ignore the issue with a tools:ignore="MissingTranslation"
   attribute.

   By default this detector allows regions of a language to just provide a
   subset of the strings and fall back to the standard language strings. You
   can require all regions to provide a full translation by setting the
   environment variable ANDROID_LINT_COMPLETE_REGIONS.

   You can tell lint (and other tools) which language is the default language
   in your res/values/ folder by specifying tools:locale="languageCode" for
   the root <resources> element in your resource file. (The tools prefix
   refers to the namespace declaration http://schemas.android.com/tools.)

5 errors, 0 warnings
                                                                                                                                                              :
lintVitalRelease                                                                                                                                              F
AILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':lintVitalRelease'.
> Lint found fatal errors while assembling a release target.

To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}
...

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.542 secs

W:\work\caigoubang\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                          ^
Error code 1 for command: cmd with args: /s /c "W:\work\caigoubang\platforms\android\gradlew cdvBuildRelease -b W:\work\caigoubang\platforms\android\build.grad
le -Dorg.gradle.daemon=true"
ERROR building one of the platforms: Error: W:\work\caigoubang\platforms\android\cordova\build.bat: Command failed with exit code 8
You may not have the required environment or OS to build this project
Error: W:\work\caigoubang\platforms\android\cordova\build.bat: Command failed with exit code 8
    at ChildProcess.whenDone (C:\Users\admin\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:735:16)
    at Process.ChildProcess._handle.onexit (child_process.js:802:5)```

设置tags只能设置成功一个。

测试平台IOS 8.3

window.plugins.jPushPlugin.setTagsWithAlias(['A23','A24']);

设置回调只设置成功一个tag

tagAliasResult result code:0 tags:A23 alias:null

插架安装太复杂,不能做到开箱即用

我是第一次碰到安装插件还需要改插件代码的情况。能不能做到开箱即用,这样可以省去很多麻烦。 😸

能像 ionic push 这是使用就挺好的,可以借鉴下 ionic push.

可以收到推送通知,但通知/消息的事件无响应,求助

Hi:
您好,我有个问题想请教下,我用这个插件集成在IOS平台上(cordova+sencha touch),但和其他有些人遇到的问题可能类似,我能收到推送通知,但是无法获取数据,receiveNotification和receiveMessage事件不响应。我不知道是否是自己理解有问题,我的代码如下(index.html中):

window.plugins.jPushPlugin.init(); //起作用,能收到推送通知
window.plugins.jPushPlugin.setTagsWithAlias(['AA'],'BB'); //起作用,能按照别名,标签收到推送通知
var onOpenNotification = function(event){ //不起作用,ipad收到通知后,方法内代码不执行
//window.alert("AA"); //没有弹出AA
var indexPanel = Ext.ComponentQuery.query('#IndexAbstractPanel')[0];
indexPanel.setActiveItem(5);
};
var onReceiveMessage = function(event){ //不起作用,在极光官网发送消息后,提示发送成功,但 这个方法内部无响应
//window.alert("BB"); //没有弹出框
var indexPanel = Ext.ComponentQuery.query('#IndexAbstractPanel')[0];
indexPanel.setActiveItem(5);
};
document.addEventListener("jpush.openNotification", onOpenNotification, false);
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);

(我看到之前也有人提问过类似问题,但我的项目没有用到angular,我对object-c语言也不熟悉,看不大懂之前有人说过的那个方法,不明白为什么要就是将原来的window.plugins.jPushPlugin.receiveMessageIniOSCallback 改成 window.jPushPluginreceiveMessageIniOSCallback,我尝试着改过,没有作用)。

集成的时候我是按照文档步骤操作的,我理解的是不是当收到通知/消息的时候,系统会响应jpush.openNotification/jpush.receiveMessag事件?从而执行onOpenNotification/onReceiveMessage方法?但我不大清楚为什么方法没有响应。。是否还需要加object-c的一些代码?

希望大神有时间能解答下,万分感谢。
(Cordova 4.3.0 ,IOS7环境)

使用RegistrationID问题

我是菜鸟,我想在我的应用里使用RegistrationID,应该如何做,我用的是Oracle Mobile Application Framework,我已经在我的应用中配置了 jpush-phonegap-plugin

如何打开指定页面

你好。我想开发一个打开指定页面的功能。我现在用 openNotificationInAndroidCallback 这个方法。但是我发现这个方法只有在app打开的时候才能获取到 json字串,在app关闭的状态下无法正确获取,然后我看了下你的源码还有一个getNotification 方法应该是用来获取这个字串的吧。但是被注释掉了。请问有对应的方法能在app打开之后再拿到 推送的字串吗?

get a string but cause JSON.parse failure with cn.jpush.android.EXTRA

Description

If pushing a notification from web console for android platform like this, the further handler in javascript throw an error.

Push from web console

image
And the mobile client can get the data like this -

'{"alert":"fooo","extras":{"cn.jpush.android.MSG_ID":"790697075","app":"com.arrking.tory","cn.jpush.android.ALERT":"fooo","cn.jpush.android.EXTRA":"{\'a\':\'c\'}","cn.jpush.android.PUSH_ID":"790697075","cn.jpush.android.NOTIFICATION_ID":790697075,"cn.jpush.android.NOTIFICATION_TYPE":"0"}}'

Process Data in Client

Assume the data is passed into JPushPlugin.openNotificationInAndroidCallback, the JSON.parse(data) method throws an error.

I/Web Console( 1124): processMessage failed: Error: SyntaxError: Unexpected token a at file:///android_asset/www/cordova.js:1044
I/Web Console( 1124): processMessage failed: Stack: SyntaxError: Unexpected token a
I/Web Console( 1124):     at Object.parse (native)
I/Web Console( 1124):     at file:///android_asset/www/scripts/services.js:53:23

Solution

The root cause is cn.jpush.android.EXTRA is used as a String, when the data.toString() is called later, the return string is sent to webView, but if the webView's javascript parses this string as a JSON, it get an error.

fix it in JPushPlugin.java

private static JSONObject openNotificationObject(String alert,
            Map<String, Object> extras){
        JSONObject data = new JSONObject();
        try{
            data.put("alert", alert);
            JSONObject jExtras = new JSONObject();
            for(Entry<String,Object> entry:extras.entrySet()){
                if(entry.getKey().equals("cn.jpush.android.EXTRA")){
          JSONObject jo = new JSONObject((String)entry.getValue());
                    jExtras.put("cn.jpush.android.EXTRA", jo);
                }else{
                    jExtras.put(entry.getKey(),entry.getValue());
                }
            }
            if(jExtras.length()>0)
            {
                data.put("extras", jExtras);
            }
        } catch (Exception e) {
        }
        return data;
    }

Android 5.0 64位机器上找不到jpush的so库

我在一台华为的Android手机上测试的时候,发现只要调用setAlias,App就崩溃了。
从错误日志中看到下面的错误消息:
lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libjpush175.so"
在生成的android项目的lib下面,发现有下面几个目录
armeabi armeabi-v7a armeabi-v8a arm64-v8a
除了最后一个目录,其他几个都有libjpush175.so文件。 我看plugin.xml是把 arm64-v8a/libjpush175.so 拷贝到了libs/armeabi-v8a目录,对android喝cordova plugin不熟,但是我手动把插件里arm64-v8a/libjpush175.so 拷贝到android工程里的arm64-v8a文件夹下就没有问题了。

不知道是不是个问题?

谢谢

error: use of undeclared identifier 'APService'

Description

hi, I am building an iOS app, maybe later for android, so I have to choose a push sdk that can supports usage in China.

I follow the guide here, and get an error.
Can anyone help ?

1-6A1052d/Xcode/SharedPrecompiledHeaders/myApp-Prefix-amnewwtlvohosodyylvcuisxpfag/myApp-Prefix.pch -MMD -MT dependencies -MF /Users/faramir/tmp/myApp/platfor
ms/ios/build/myApp.build/Debug-iphonesimulator/myApp.build/Objects-normal/i386/AppDelegate.d --serialize-diagnostics /Users/faramir/tmp/myApp/platforms/ios/bu
ild/myApp.build/Debug-iphonesimulator/myApp.build/Objects-normal/i386/AppDelegate.dia -c /Users/faramir/tmp/myApp/platforms/ios/myApp/Classes/AppDelegate.m -o /Users/faramir/tmp/myApp/platforms/ios/build/myApp.build/Debug-iphonesimulator/myApp.build/Objects-normal/i386/AppDelegate.o
/Users/faramir/tmp/myApp/platforms/ios/myApp/Classes/AppDelegate.m:79:6: error: use of undeclared identifier 'APService'
    [APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
     ^
/Users/faramir/tmp/myApp/platforms/ios/myApp/Classes/AppDelegate.m:85:6: error: use of undeclared identifier 'APService'
    [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
     ^
/Users/faramir/tmp/myApp/platforms/ios/myApp/Classes/AppDelegate.m:97:6: error: use of undeclared identifier 'APService'
    [APService setupWithOption:launchOptions];

请问README中那段iOS 版需要手动插入的监听系统事件的代码是放到哪里?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    // Required
    [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                    UIRemoteNotificationTypeSound |
                                                    UIRemoteNotificationTypeAlert)];
    // Required
    [APService setupWithOption:launchOptions];

    return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    // Required
    [APService registerDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    // Required
    [APService handleRemoteNotification:userInfo];
}

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.