当前位置: 首页>数据库>正文

极光flutter监听解析数据

注册极光账号
登记极光官网https://www.jiguang.cn/push?source=bdpc&plan=4&unit=80&keyword=5286

点击应用管理

点击创建应用,填写应用信息后点击确定

保存AppKey(项目需要配置)

填写项目包名(注意填写后不能修改)有华为oppo等厂商key可以配置提供推送效果

在flutter项目的 pubspec.yaml 中加入 依赖包

dependencies:

极光推送

jpush_flutter: 2.2.2
在main初始化极光推送

///初始化极光推送
void startJPush() {
JPush jpush = JPush();
//配置jpush(不要省略)
//debug就填debug:true,生产环境production:true
jpush.setup(
appKey: '替换极光注册的appKey',
channel: 'developer-default',
production: true,
debug: true);
//监听jpush(ios必须配置)
jpush.applyPushAuthority(
const NotificationSettingsIOS(sound: true, alert: true, badge: true));
jpush.addEventHandler(
onReceiveNotification: (Map<String, dynamic> message) async {
print('message11:极光flutter监听解析数据,message,第1张message');
},
);
}
安卓配置:
在 /android/app/build.gradle 中添加下列代码

android: {
....
defaultConfig {
applicationId "替换成自己应用 ID"
...
ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a',
}

    //极光推送配置key
    manifestPlaceholders = [
            JPUSH_PKGNAME : applicationId,
            JPUSH_APPKEY : "b75e994247ba8107f3f1c23f", // NOTE: JPush 上注册的包名对应的 Appkey.
            JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.

// MEIZU_APPKEY : "MZ-魅族的APPKEY",
// MEIZU_APPID : "MZ-魅族的APPID",
// XIAOMI_APPID : "MI-小米的APPID",
// XIAOMI_APPKEY : "MI-小米的APPKEY",
// OPPO_APPKEY : "OP-oppo的APPKEY",
// OPPO_APPID : "OP-oppo的APPID",
// OPPO_APPSECRET : "OP-oppo的APPSECRET",
// VIVO_APPKEY : "vivo的APPKEY",
// VIVO_APPID : "vivo的APPID"
]
}
}

如果需要配置指定厂商key还需要下面配置

model的build.gradle配置

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

// 接入华为厂商

// implementation 'com.huawei.hms:push:4.0.2.300'
// implementation 'cn.jiguang.sdk.plugin:huawei:4.0.0'// 极光厂商插件版本与接入 JPush 版本保持一致,下同
// // 接入 FCM 厂商
// implementation 'com.google.firebase:firebase-messaging:21.0.1'
// implementation 'cn.jiguang.sdk.plugin:fcm:4.0.0'
// // 接入魅族厂商
// implementation 'cn.jiguang.sdk.plugin:meizu:4.0.0'
// // 接入 VIVO 厂商
// implementation 'cn.jiguang.sdk.plugin:vivo:4.0.0'
// // 接入 OPPO 厂商
// implementation 'cn.jiguang.sdk.plugin:oppo:4.0.0'
// // 接入小米厂商
// implementation 'cn.jiguang.sdk.plugin:xiaomi:4.0.0'
}

项目的build.gradle配置

repositories {
google()
mavenCentral()
maven { url 'https://maven.aliyun.com/repository/public/'}
maven { url 'https://maven.aliyun.com/repository/spring/'}
maven { url "https://www.jitpack.io" }
maven { url "http://download.flutter.io"}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://maven.aliyun.com/repository/public/'}
maven { url 'https://maven.aliyun.com/repository/spring/'}
maven { url "https://www.jitpack.io" }
maven { url "http://download.flutter.io"}
}
}

IOS配置:
配置极光的tag和别名还有ios端的证书配置稍后更新
ios苹果端并不需要改动代码,只需要配置证书开启服务就行

跳转指定页面可以在推送消息配置附加字段

在下面监听方法可以获取配置

jpush.addEventHandler(
onReceiveNotification: (Map<String, dynamic> message) async {
//推送通知栏新消息
print('message11:极光flutter监听解析数据,message,第1张message');
var text=message["extras"];
print('text:极光flutter监听解析数据,text,第3张text2');
var text3=text["key"];//key是推送附件字段配置的key
},
);


https://www.xamrdz.com/database/6zq1994321.html

相关文章: