鎮(zhèn)樓圖附上
image.png
本文是根據(jù)極光官網(wǎng)的文檔操作后總結(jié)出:(寫的不盡詳細支出可以先看一下官方文檔,以便理解)
首先簡單的集成極光推送
碘裕、極光平臺創(chuàng)建項目携取,Android/IOS,具體配置 p12這里就不贅述了帮孔,網(wǎng)上一堆
雷滋、pubspec.yaml -> 引入極光插件 jpush_flutter: ^0.6.3
、公共處main中 初始化 創(chuàng)建回調(diào) 具體 如下:
void initState() {
super.initState();
///極光推送
this.initJpush();
}
initJpush() async {
JPush jpush = new JPush();
jpush.applyPushAuthority(
new NotificationSettingsIOS(sound: true, alert: true, badge: true));
//獲取注冊的id
jpush.getRegistrationID().then((rid) {
//這里說一下 若別處需要使用rid 如此調(diào)用 await jpush.getRegistrationID()
print("獲取注冊的id:$rid");
});
//初始化
jpush.setup(
appKey: "這里是極光平臺的appKey",
channel: "thisChannel",
production: false,
debug: true, // 設(shè)置是否打印 debug 日志
);
//設(shè)置別名 實現(xiàn)指定用戶推送
jpush.setAlias("supperman").then((map) {
print("設(shè)置別名成功");
});
try {
//監(jiān)聽消息通知
jpush.addEventHandler(
// 接收通知回調(diào)方法文兢。
onReceiveNotification: (Map<String, dynamic> message) async {
print("flutter onReceiveNotification: $message");
},
// 點擊通知回調(diào)方法晤斩。
onOpenNotification: (Map<String, dynamic> message) async {
print("flutter onOpenNotification: $message");
},
// 接收自定義消息回調(diào)方法。
onReceiveMessage: (Map<String, dynamic> message) async {
print("flutter onReceiveMessage: $message");
},
);
} catch (e) {
print('極光sdk配置異常');
}
}
姆坚、Android 需要在app->build.gradle->android{...->defaultConfig {.. 此處添加配置如下
manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "xxxxxx", // NOTE: JPush 上注冊的包名對應(yīng)的 Appkey.
JPUSH_CHANNEL : "thisPush", //暫時填寫默認(rèn)值即可
]
至此app在線調(diào)試OK
因為需求不會只要app在線狀態(tài)下收到推送澳泵,蘋果本就可以所以需要處理安卓如何接收離線推送接下來我們開始著手處理接收離線推送
首先去小米、vivo兼呵、魅族兔辅、oppo、華為击喂、等手機廠商的開發(fā)者中心去注冊創(chuàng)建項目维苔,注意創(chuàng)建項目時包名要與本地項目的包名相同
然后再極光平臺集成設(shè)置中填寫
然后去看看廠商集成文檔,沒做過安卓是不是一頭霧水懂昂,沒事兒耐心看完接下來我們把那些簡化一下總結(jié)后就是分為兩種
一介时、小米/vivo/魅族/oppo
manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "xxxxxx", // NOTE: JPush 上注冊的包名對應(yīng)的 Appkey.
JPUSH_CHANNEL : "thisPush", //暫時填寫默認(rèn)值即可.
XIAOMI_APPID : "MI-xxxxxxx",
XIAOMI_APPKEY : "MI-xxxxxx",
OPPO_APPKEY : "OP-xxxxxxxx", // OPPO平臺注冊的appkey
OPPO_APPID : "OP-xxxxxx", // OPPO平臺注冊的appid
OPPO_APPSECRET: "OP-xxxxxx",//OPPO平臺注冊的appsecret
VIVO_APPKEY : "xxxxxxx", // VIVO平臺注冊的appkey
VIVO_APPID : "xxxxxx", // VIVO平臺注冊的appid
MEIZU_APPKEY : "MZ-xxxxx", // 魅族平臺注冊的appkey
MEIZU_APPID : "MZ-xxxxxx", // 魅族平臺注冊的appid
]
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compile 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+'
compile 'cn.jiguang.sdk.plugin:xiaomi:3.9.0'//版本號和對應(yīng)的JPush版本號相同
compile 'cn.jiguang.sdk.plugin:oppo:3.9.0'//版本號和對應(yīng)的JPush版本號相同
compile 'cn.jiguang.sdk.plugin:vivo:3.9.0'//版本號和對應(yīng)的JPush版本號相同
compile 'cn.jiguang.sdk.plugin:meizu:3.9.0'//版本號和對應(yīng)的JPush版本號相同
}
二、華為(總是ge路子)
、創(chuàng)建完項目后將agconnect-services.json文件拖入android->app下沸柔,然后將本地簽名文件中的SHA256代碼填入華為后臺(填寫完一定要點擊右側(cè)的?)
image.png
循衰、不需要在代碼中填寫appkey,具體操作如下
//app->build.gradle
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.huawei.hms:push:5.1.1.301'
implementation 'cn.jiguang.sdk.plugin:huawei:3.9.0'
compile 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+'
compile 'cn.jiguang.sdk.plugin:xiaomi:3.9.0'//版本號和對應(yīng)的JPush版本號相同
compile 'cn.jiguang.sdk.plugin:oppo:3.9.0'
compile 'cn.jiguang.sdk.plugin:vivo:3.9.0'
compile 'cn.jiguang.sdk.plugin:meizu:3.9.0'
}
apply plugin: 'com.huawei.agconnect' //此處用以調(diào)用agconnect動態(tài)狀態(tài)管理器
//android->build.gradle
buildscript {
ext.kotlin_version = '1.4.10'//'1.3.50'
repositories {
google()
jcenter()
maven {url 'http://developer.huawei.com/repo/'}
}
dependencies {
classpath 'com.android.tools.build:gradle'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'http://developer.huawei.com/repo/'}
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"http:////添加此處代碼
package="xxxxxx">
<application
tools:replace="android:label" ////添加此處代碼
android:usesCleartextTraffic="true"
......
萬事都有意外狀況,如果你的項目中有集成環(huán)信通訊勉失,仔細的你會發(fā)現(xiàn)推送不好用了,調(diào)試時會發(fā)現(xiàn)獲取不到Devicetoken原探,不要慌乱凿,這是因為環(huán)信對iOS原生代理重寫了導(dǎo)致Devicetoken獲取被環(huán)信攔截了,解決辦法就是咽弦,先注冊環(huán)信登錄徒蟆,就好了,原理就是先讓環(huán)信去獲取Devicetoken目前作者也沒什么更好的辦法型型,有更的解決方式歡迎留言段审,謝謝點贊支持!D炙狻K峦鳌!