一、先在uniapp的插件市场下载
点击直达
二、本地插件配置(可在控制台看到打印信息,方便测试)
1.配置本地插件信息
1.1 厂商信息需要在各个厂商注册后,然后填写,用处为:可在离线时,发送通知。
1.2 在本地插件的page.json中,配置安卓和ios的appKey和厂商id(若不配置,仅支持在线通知):
2.配置manifest.json信息
在manifest.json的源码视图中配置如下信息:
1、2、3步代码保持一致,4、5步填写ios、安卓对应的appkey
"android" : {
"permissions" : [
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.CALL_PHONE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
],
"abiFilters" : [ "armeabi-v7a", "x86" ]
},
"ios" : {
"privacyDescription" : {
"NSLocationAlwaysAndWhenInUseUsageDescription" : "This app requires location services to work",
"NSLocationAlwaysUsageDescription" : "This app requires location services to work",
"NSLocationWhenInUseUsageDescription" : "This app requires location services to work"
},
"UIBackgroundModes" : "remote-notification,voip,fetch,location",
"idfa" : true
},
"sdkConfigs" : {
"ad" : {},
"push" : {},
"geolocation" : {},
"maps" : {}
},
7、8、11、12配置安卓和ios的appKey,9,10配置安卓的包名和ios的bundle_id
下面的JG-JPush 配置相同,就不一一列举。
再放一段参考代码:
"nativePlugins" : {
"JG-JCore" : {
"JPUSH_APPKEY_ANDROID" : "appkey注册时获取",
"JPUSH_APPKEY_IOS" : "appkey注册时获取",
"JPUSH_CHANNEL_IOS" : "developer-default",
"JPUSH_CHANNEL_ANDROID" : "developer-default",
"__plugin_info__" : {
"name" : "JG-JCore",
"description" : "极光推送JCore插件",
"platforms" : "Android,iOS",
"url" : "",
"android_package_name" : "com.xxx.com",
"ios_bundle_id" : "com.xxxaaa.com",
"isCloud" : false,
"bought" : -1,
"pid" : "",
"parameters" : {
"JPUSH_APPKEY_ANDROID" : {
"des" : "appkey注册时获取",
"key" : "JPUSH_APPKEY",
"value" : "appkey"
},
"JPUSH_APPKEY_IOS" : {
"des" : "appkey注册时获取",
"key" : "JCore:APP_KEY",
"value" : "appkey"
},
"JPUSH_CHANNEL_IOS" : {
"des" : "developer-default",
"key" : "JCore:CHANNEL",
"value" : "developer-default"
},
"JPUSH_CHANNEL_ANDROID" : {
"des" : "developer-default",
"key" : "JPUSH_CHANNEL",
"value" : "developer-default"
}
}
}
},
"JG-JPush" : {
"JPUSH_XIAOMI_APPKEY" : "",
"JPUSH_MEIZU_APPID" : "",
"JPUSH_OPPO_APPSECRET" : "",
"JPUSH_OPPO_APPKEY" : "",
"JPUSH_ADVERTISINGID_IOS" : "",
"JPUSH_MEIZU_APPKEY" : "",
"JPUSH_OPPO_APPID" : "",
"JPUSH_DEFAULTINITJPUSH_IOS" : "",
"JPUSH_VIVO_APPKEY" : "",
"JPUSH_VIVO_APPID" : "",
"JPUSH_ISPRODUCTION_IOS" : "false",
"JPUSH_XIAOMI_APPID" : "",
"JPUSH_HUAWEI_APPID" : "",
"__plugin_info__" : {
"name" : "JG-JPush",
"description" : "极光推送Hbuilder插件",
"platforms" : "Android,iOS",
"url" : "",
"android_package_name" : "com.xxx.com",
"ios_bundle_id" : "com.xxxaaa.com",
"isCloud" : false,
"bought" : -1,
"pid" : "",
"parameters" : {
"JPUSH_XIAOMI_APPKEY" : {
"des" : "",
"key" : "XIAOMI_APPKEY",
"value" : ""
},
"JPUSH_MEIZU_APPID" : {
"des" : "",
"key" : "MEIZU_APPID",
"value" : ""
},
"JPUSH_OPPO_APPSECRET" : {
"des" : "",
"key" : "OPPO_APPSECRET",
"value" : ""
},
"JPUSH_OPPO_APPKEY" : {
"des" : "",
"key" : "OPPO_APPKEY",
"value" : ""
},
"JPUSH_ADVERTISINGID_IOS" : {
"des" : "",
"key" : "JPush:ADVERTISINGID",
"value" : ""
},
"JPUSH_MEIZU_APPKEY" : {
"des" : "",
"key" : "MEIZU_APPKEY",
"value" : ""
},
"JPUSH_OPPO_APPID" : {
"des" : "",
"key" : "OPPO_APPID",
"value" : ""
},
"JPUSH_DEFAULTINITJPUSH_IOS" : {
"des" : "false",
"key" : "JPush:DEFAULTINITJPUSH",
"value" : ""
},
"JPUSH_VIVO_APPKEY" : {
"des" : "",
"key" : "com.vivo.push.api_key",
"value" : ""
},
"JPUSH_VIVO_APPID" : {
"des" : "",
"key" : "com.vivo.push.app_id",
"value" : ""
},
"JPUSH_ISPRODUCTION_IOS" : {
"des" : "false",
"key" : "JPush:ISPRODUCTION",
"value" : ""
},
"JPUSH_XIAOMI_APPID" : {
"des" : "",
"key" : "XIAOMI_APPID",
"value" : ""
},
"JPUSH_HUAWEI_APPID" : {
"des" : "",
"key" : "com.huawei.hms.client.appid",
"value" : ""
}
}
}
}
}
3.配置自定义基座包(Android、iOS)
iOS打包勾选上后修改bundle id并且上传证书即可
4.运行测试
选择自定义基座–>选择与电脑连接的手机设备(或者模拟器)–>点击运行
三、离线打包集成(安卓和ios,ios无需配置其他,官方参考文档)
1、生成离线打包资源 1.在菜单栏中选中 “发行” --> “原生App-本地打包” --> “生成本地打包App资源”
2.在项目目录下的"unpackage" --> "resources"目录下会生成资源文件
2、下载离线打包SDK 2.1 下载地址 https://nativesupport.dcloud.net.cn/AppDocs/download/android 注意:SDK版本需要与HbuilderX版本对应才能正常运行项目,否则可能造成兼容问题。 2.2 查看HbuilderX版本 在菜单栏中选点击 “帮助”–>“关于”,查看弹窗即可看到版本号
2.3 下载SDK 下载跟自己HBuilderX版本号相同的SDK
3、离线打包工程配置 3.1 打开 UniPlugin-Hello-AS 工程 使用Android Stuido打开UniPlugin-Hello-AS工程
3.2 导入离线打包资源 将项目中app/src/main/assets/apps/目录下的文件删除,并且替换为HBuilderX中生成的离线打包资源
3.3 修改dcloud_control.xml 将dcloud_control.xml中的appid修改成与离线打包资源文件夹同名
3.4 删除无用模块
4、集成推送插件 4.1 修改applicationId ?将app/build.gradle文件中的applicationId修改为认证时申请的包名
?将AndroidManifest.xml中的package修改为认证时申请的包名
4.2 配置打包签名文件 在app/build.gradle中的android{}里面添加签名信息(使用自己的签名文件或者云端证书都可)
signingConfigs {
release {
keyAlias 'push'
keyPassword '123456'
storeFile file('./push.jks')
storePassword '123456'
}
debug {
keyAlias 'push'
keyPassword '123456'
storeFile file('./push.jks')
storePassword '123456'
}
}
?在app/build.gradle中的buildTypes{}里面添加打包时指定的签名文件
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}
4.3 配置插件信息 打开dcloud_uniplugins.json文件填写插件信息 插件信息在HBuilderX项目nativeplugins/JG-JCore/package.json、nativeplugins/JG-JPush/package.json中查看
{
"nativePlugins": [
{
"plugins": [
{
"type": "module",
"name": "JG-JCore",
"class": "cn.jiguang.uniplugin_jcore.JCoreModule"
},
{
"type": "module",
"name": "JG-JPush",
"class": "cn.jiguang.uniplugin_jpush.JPushModule"
}
],
"integrateType": "aar",
"minSdkVersion": "16"
}
]
}
4.4 导入推送插件依赖库 将JPush_Hbuilder_Demo中的依赖包复制到UniPlugin-Hello-AS项目中的app/libs目录下
4.5 配置极光和厂商参数 注意:以下参数替换为自己的参数
manifestPlaceholders = [
JPUSH_PKGNAME : "pub.kilo.thirdpush",
JPUSH_APPKEY : "xx",
JPUSH_CHANNEL : "developer-default",
XIAOMI_APPKEY : "MI-xx",
XIAOMI_APPID : "MI-xx",
OPPO_APPKEY : "OP-xx",
OPPO_APPID : "OP-xx",
OPPO_APPSECRET: "OP-xx",
VIVO_APPKEY : "xx",
VIVO_APPID : "xx",
MEIZU_APPKEY : "MZ-xx",
MEIZU_APPID : "MZ-xx",
]
<meta-data
android:name="JPUSH_APPKEY"
android:value="${JPUSH_APPKEY}" />
<meta-data
android:name="JPUSH_CHANNEL"
android:value="${JPUSH_CHANNEL}" />
<meta-data
android:name="XIAOMI_APPKEY"
android:value="${XIAOMI_APPKEY}" />
<meta-data
android:name="XIAOMI_APPID"
android:value="${XIAOMI_APPID}" />
<meta-data
android:name="OPPO_APPKEY"
android:value="${OPPO_APPKEY}" />
<meta-data
android:name="OPPO_APPID"
android:value="${OPPO_APPID}" />
<meta-data
android:name="OPPO_APPSECRET"
android:value="${OPPO_APPSECRET}" />
<meta-data
android:name="com.vivo.push.api_key"
android:value="${VIVO_APPKEY}" />
<meta-data
android:name="com.vivo.push.app_id"
android:value="${VIVO_APPID}" />
<meta-data
android:name="MEIZU_APPKEY"
android:value="${MEIZU_APPKEY}" />
<meta-data
android:name="MEIZU_APPID"
android:value="${MEIZU_APPID}" />
4.6 登录开发者中心申请签名 1)开发者需登录 https://dev.dcloud.net.cn/ 申请签名,申请签名成功后会显示 AppKey
2)将步骤 1 获取到的 AppKey 配置到 manifest
4.7 集成华为和FCM 华为和FCM的集成参考以下文档即可 https://www.yuque.com/docs/share/0f6327ce-da8f-488e-824a-7ca53890252d?# 《极光厂商通道集成指南》 解决fcm集成报AndroidX错误的问题
android.useAndroidX=true
android.enableJetifier=true
5、厂商通道点击跳转获取参数问题 (华为/小米/VIVO通道)uri_activity:cn.jiguang.uniplugin_jpush.OpenClickActivity (OPPO / FCM通道)uri_action: cn.jiguang.uniplugin_jpush.OpenClickActivity
四、官方demo和API文档
官方demo : https://github.com/jpush/jpush-hbuilder-plugin API文档 :https://github.com/jpush/jpush-hbuilder-plugin/blob/master/doc/API.md
|