【Flutter】极光推送配置流程(小米厂商通道) 章二

devtools/2024/10/18 22:30:32/

前言

继【Flutter】极光推送配置流程(极光通道/华为厂商/IOS) 章一
并且,我大概率不会去修改第一篇文章的内容。
随着我自己在配置公司的项目的同时,我希望一直更新这个推送系列文章。
在章一配置完后,也是出现了一些问题,所以本章主要围绕

  • 华为厂商通道配置出现的问题
  • 如何配置小米厂商通道

极光插件

首先是极光插件,可以去更新,但要看更新了什么内容
在这里插入图片描述
看这个更新内容,JPush 5.2.4
记得在之前那篇blog,我写了5.2.3
所以在.gradle文件中,把版本提到5.2.4(这里我直接截)
在这里插入图片描述

配置小米厂商通道

小米是需要上架应用的,需要企业开发者。
以下截图和代码是公司的项目,部分地方就马赛克了

上架

需要公司提供资料(软著/APP备案等),上架可能会快一些(1天以上)
在这里插入图片描述

推送申请估计要点时间(3天以上)

在这里插入图片描述
在这里插入图片描述
通道要申请下来,这里的类别,记得按自己需要。
在这里插入图片描述
类别选择参考这篇
在这里插入图片描述
填完类别等信息后
这里的channel_ID记一下
在这里插入图片描述
这里的appKey AppSecret AppID对应极光那三个要填写的
在这里插入图片描述
名字都一样的,把内容填写进去,再开启
在这里插入图片描述

build.gradle

回到项目
看这篇文章
在这里插入图片描述

配置依赖

在这里插入图片描述

    // 小米implementation 'cn.jiguang.sdk.plugin:xiaomi:5.2.4.a'

小米参数
在这里插入图片描述

填写小米参数

在这里插入图片描述

用一台小米手机来运行项目

在这里插入图片描述
若出现

xiao mi push register success

就代表配置好了
在这里插入图片描述

调用API发送推送

在这里插入图片描述
这里的channel id是之前创建的通道的id
代码之前篇章一有贴过
在这里插入图片描述

import 'dart:convert';
import 'dart:io';import 'package:dio/dio.dart';
import 'package:flutter/material.dart';void main() {runApp(const MyApp());
}class MyApp extends StatelessWidget {const MyApp({super.key});Widget build(BuildContext context) {return MaterialApp(title: '推送',theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),useMaterial3: true,),home: const MyHomePage(title: '信息推送'),);}
}class MyHomePage extends StatefulWidget {const MyHomePage({super.key, required this.title});final String title;State<MyHomePage> createState() => _MyHomePageState();
}class _MyHomePageState extends State<MyHomePage> {final String appKey = "XXXX";final String masterSecret = "XXXXXXX";late String base64AuthString;final Dio dio = Dio();late String notificationAlert;late String notificationTitle;late String notificationAudienceAlias;void initState() {final content = utf8.encode("$appKey:$masterSecret");base64AuthString = "Basic ${base64Encode(content)}";super.initState();}Widget build(BuildContext context) {return Scaffold(appBar: AppBar(backgroundColor: Theme.of(context).colorScheme.inversePrimary,title: Text(widget.title),),body: Center(child: Padding(padding: const EdgeInsets.all(8.0),child: ListView(children: [TextField(decoration: const InputDecoration(labelText: "主标题",hintText: "请输入...",),onChanged: (s) {notificationAlert = s;},),TextField(decoration: const InputDecoration(labelText: "副标题",hintText: "请输入...",),onChanged: (s) {notificationTitle = s;},),TextField(decoration: const InputDecoration(labelText: "别名",hintText: "请输入...",),onChanged: (s) {notificationAudienceAlias = s;},),Padding(padding: const EdgeInsets.all(8.0),child: ElevatedButton(onPressed: () {showDialog(context: context,builder: (context) {return SimpleDialog(title: const Text("确定发送?"),children: [SimpleDialogOption(child: const Text("确定"),onPressed: () {pushMessage(notificationAlert: notificationAlert,notificationTitle: notificationTitle,notificationAudienceAlias: [notificationAudienceAlias],);Navigator.of(context).pop();},),SimpleDialogOption(child: const Text("取消"),onPressed: () {Navigator.of(context).pop();},)],);});},child: const Text("推送消息"),),),],),),),);}/// 推送pushMessage({required String notificationAlert,required String notificationTitle,required List<String> notificationAudienceAlias,}) async {const String url = "https://api.jpush.cn/v3/push";var data = json.encode({"platform": ["android", "ios"],"inapp_message": {"inapp_message": false},"options": {"classification": 0,"time_to_live": 86400,"apns_production": false,"third_party_channel": {"huawei": {"skip_quota": false,"distribution": "secondary_push","channel_id": "","category": "DEVICE_REMINDER","receipt_id": ""},"xiaomi": {"channel_id": "XXXXXX","distribution": "secondary_push","skip_quota": false}}},"notification": {"alert": notificationAlert,"android": {"alert": notificationAlert,"title": notificationTitle,"intent": {"url": "intent:#Intent;action=android.intent.action.MAIN;end"},"sound": "","priority": 0,"category": "","alert_type": 7,"style": 0,"builder_id": 0,"large_icon": "","badge_add_num": 1,"extras": {"param": "123"}},"ios": {"alert": {"title": notificationAlert,"body": notificationTitle,},"content-available": 0,"mutable-content": 1,"sound": "default","badge": "+1","thread-id": "","interruption-level": "active","filter-criteria": "","extras": {"参数": "A"}}},"audience": {"alias": notificationAudienceAlias,}});final response = await dio.request(url,data: data,options: Options(headers: {HttpHeaders.authorizationHeader: base64AuthString,},method: "POST",),);print(response.data.toString());}
}

后台关闭APP,杀掉APP,再发送一下
在这里插入图片描述
手机收到就代表配置完成
在这里插入图片描述

遇到的问题

设置别名

这个是在公司项目里面遇到的
需求是这样的:注册好极光的插件之后,若用户登录之后,我需要给当前设备设置别名为手机号。
当调用

final value = await jPush.setAlias("17777777777");

在这里插入图片描述
在这里插入图片描述
这个问题目前解决的办法是在手机号前加了一些数字比如000001777777777,就可以了。不清楚原因,所以就先记录一下。


http://www.ppmy.cn/devtools/27807.html

相关文章

基于ssm+vue+Mysql的房屋租赁系统求租合同

开发语言&#xff1a;Java框架&#xff1a;ssmJDK版本&#xff1a;JDK1.8服务器&#xff1a;tomcat7数据库&#xff1a;mysql 5.7&#xff08;一定要5.7版本&#xff09;数据库工具&#xff1a;Navicat11开发软件&#xff1a;eclipse/myeclipse/ideaMaven包&#xff1a;Maven3.…

[ log日志画图]分割模型训练结束生成相关日志运用代码画图

文章目录 [ log日志画图]分割模型训练结束生成相关日志运用代码画图我的log文件&#xff1a;画图&#xff1a;1.loss1.1 loss是干嘛的1.2 代码1.3 生成图 2.DICE.IOU2.1 DICE,IOU是干嘛的(常规介绍)2.2 代码2.3 生成图小白tip [ log日志画图]分割模型训练结束生成相关日志运用代…

鹏哥C语言复习——字符函数与字符串函数

目录 一.字符函数 1.字符分类函数 2.字符转换函数 二.基础字符串函数 1.strlen函数 2.strcpy函数 3.strcat函数 4.strcmp函数 三.基础字符串函数优化 1.strncpy函数 2.strncat函数 3.strncmp函数 四.进阶字符串函数 1.strstr函数 2.strtok函数 3.strerror函数 一…

安卓手机APP开发__媒体开发部分__立体环绕声

安卓手机APP开发__媒体开发部分__立体环绕声 目录 概述 对于能力的查询 耳机的跟踪 可兼容的内容 声音的属性 禁用立体环绕声的声音 声音的格式 对立体环绕声的修改的监听

解锁大模型高效推理:将 LlamaIndex 与抽象链集成

在语言理解领域&#xff0c;对忠实推理的追求促使研究人员探索各种途径。 大型语言模型&#xff08;LLMs&#xff09;在解释和执行指令方面取得了显著进展&#xff0c;但在准确回忆和组合现实世界知识方面仍然面临挑战。 为了解决这个问题&#xff0c;将外部工具集成到LLMs的…

Hive 与 MySQL 的数据库限制对比

数据库的大小 Hive: 由于Hive是建立在Hadoop生态系统之上&#xff0c;理论上其数据库大小仅受Hadoop分布式文件系统&#xff08;HDFS&#xff09;的限制&#xff0c;可以达到PB级别或更高。MySQL: MySQL数据库的大小受到磁盘空间和文件系统的限制。在实践中&#xff0c;单个实例…

Docker在linux安装步骤超详细

官网 Install Docker Engine on CentOS | Docker Docs yum -y install gcc yum -y install gcc-c 安装工具 sudo yum install -y yum-utils 设置国内的镜像 yum-config-manager \ --add-repo \ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yu…

CSS常用属性之(列表、表格、鼠标)属性,(如果想知道CSS的列表、表格、鼠标相关的属性知识点,那么只看这一篇就足够了!)

前言&#xff1a;在学习CSS的时候&#xff0c;必不可少的就要学习选择器和常见的属性&#xff0c;而本篇文章讲解的是CSS中的列表、表格、背景、鼠标属性。 ✨✨✨这里是秋刀鱼不做梦的BLOG ✨✨✨想要了解更多内容可以访问我的主页秋刀鱼不做梦-CSDN博客 大致了解一下本篇文章…