免费的静态网站托管,怎样做信息收费网站,传媒公司 网站开发,咸宁哪个企业没有做网站一、简述
极光推送#xff0c;英文简称 JPush#xff0c;免费的第三方消息推送服务#xff0c;官方也推出众多平台的SDK以及插件。
参考链接
名称地址客户端集成插件客户端集成插件 - 极光文档
二、操作步骤
2.1 添加插件
flutter项目中集成官方提供的 极光推送flutte… 一、简述
极光推送英文简称 JPush免费的第三方消息推送服务官方也推出众多平台的SDK以及插件。
参考链接
名称地址客户端集成插件客户端集成插件 - 极光文档
二、操作步骤
2.1 添加插件
flutter项目中集成官方提供的 极光推送flutter插件
在根目录执行以下命令 flutter pub add jpush_flutter 2.2 初始化极光推送
在项目启动入口增加以下代码块 import package:flutter/material.dart;
import package:jpush_flutter/jpush_flutter.dart;import index_page.dart;///程序入口
void main() runApp(RootApp());class RootApp extends StatefulWidget{overrideStateStatefulWidget createState() {return RottAppState();}}class RottAppState extends StateRootApp{///根布局的初始化overridevoid initState() {super.initState();///创建 JPushJPush jpush new JPush();///配置应用 Keyjpush.setup(appKey: 替换成你自己的 appKey,channel: theChannel,production: false,/// 设置是否打印 debug 日志debug: true, );}overrideWidget build(BuildContext context) {///来构建return MaterialApp(///应用程序默认显示的页面home: IndexPage(),);}
}
2.3 配置 flutter
2.3.1 Android项目
在 android 目录下配置 build.gradle android: {....defaultConfig {applicationId 替换成自己应用 ID...ndk {//选择要添加的对应 cpu 类型的 .so 库。abiFilters armeabi, armeabi-v7a, x86, x86_64, mips, mips64, arm64-v8a, }manifestPlaceholders [JPUSH_PKGNAME : applicationId,JPUSH_APPKEY : appkey, // NOTE: JPush 上注册的包名对应的 Appkey.JPUSH_CHANNEL : developer-default, //暂时填写默认值即可.]}
}
2.3.2 IOS项目 在 xcode8 之后需要点开推送选项 TARGETS - Capabilities - Push Notification 设为 on 状态
2.4 创建应用程序
在极光开发者平台中创建你的应用程序
极光开发者平台主页portal
推送证书生成证书设置指南 - 极光文档 2.5 常见错误
android ios 平台无法接收到推送消息
在注册推送的时候可以先添加上接收通知消息的权限申请申请成功权限后再进行注册。 三、JPush主要API
参考链接https://github.com/jpush/jpush-flutter-plugin/blob/master/documents/APIs.md
3.1 初始化
添加初始化方法调用 setup 方法会执行两个操作
初始化 JPush SDK将缓存的事件下发到 dart 环境中。
注意 插件版本 0.0.8 android 端支持在 setup 方法中动态设置 channel动态设置的 channel 优先级比 manifestPlaceholders 中的 JPUSH_CHANNEL 优先级要高。 JPush jpush new JPush();
jpush.setup(appKey: 替换成你自己的 appKey,channel: theChannel,production: false,debug: false, // 设置是否打印 debug 日志);
3.2 事件监听
添加事件监听方法。
注意addEventHandler 方法建议放到 setup 之前其他方法需要在 setup 方法之后调用。 JPush jpush new JPush();
jpush.addEventHandler(// 接收通知回调方法。onReceiveNotification: (MapString, dynamic message) async {print(flutter onReceiveNotification: $message);},// 点击通知回调方法。onOpenNotification: (MapString, dynamic message) async {print(flutter onOpenNotification: $message);},// 接收自定义消息回调方法。onReceiveMessage: (MapString, dynamic message) async {print(flutter onReceiveMessage: $message);},);
3.3 推送通知 JPush jpush new JPush();
//获取 registrationId这个 JPush 运行通过 registrationId 来进行推送.
jpush.getRegistrationID().then((rid) { });
//停止推送功能调用该方法将不会接收到通知。
jpush.stopPush();
//调用 stopPush 后可以通过 resumePush 方法恢复推送。
jpush.resumePush();//指定触发时间添加本地推送通知。
// 延时 3 秒后触发本地通知。
var fireDate DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch 3000);
var localNotification LocalNotification(id: 234,title: notification title,buildId: 1,content: notification content,fireTime: fireDate,subtitle: notification subtitle, // 该参数只有在 iOS 有效badge: 5, // 该参数只有在 iOS 有效extras: {fa: 0} // 设置 extras extras 需要是 MapString, String);
jpush.sendLocalNotification(localNotification).then((res) {});//清楚通知栏上所有通知。
jpush.clearAllNotifications();
3.4 IOS独有 JPush jpush new JPush();
//申请推送权限注意这个方法只会向用户弹出一次推送权限请求如果用户不同意之后只能用户到设置页面里面勾选相应权限需要开发者选择合适的时机调用。
jpush.applyPushAuthority(new NotificationSettingsIOS(sound: true,alert: true,badge: true));//设置应用 badge 值该方法还会同步 JPush 服务器的的 badge 值JPush 服务器的 badge 值用于推送 badge 自动 1 时会用到。
jpush.setBadge(66).then((map) {});//获取 iOS 点击推送启动应用的那条通知。
jpush.getLaunchAppNotification().then((map) {});