flutter对接极光推送
- 注册极光账号,创建应用
安卓需要填写应用的包名
iOS需要填写Bundle ID
推荐使用Token Authentication配置
1.获取APNs Auth Key
苹果版IOS云消息推送配置教程,P8密钥制作APNs Auth Key获取Key ID - 一门APP (yimenapp.com)https://www.yimenapp.com/info/ping-guo-ban-IOS-yun-xiao-xi-tui-song-pei-zhi-jiao-cheng-P8-mi-yao-zhi-zuo-APNs-Auth-Key-huo-qu-Key-ID-589.html
请跳转上述教程
2.获取Team ID
苹果版IOS云消息推送配置教程,P8密钥制作APNs Auth Key获取Key ID - 一门APP (yimenapp.com)https://www.yimenapp.com/info/ping-guo-ban-IOS-yun-xiao-xi-tui-song-pei-zhi-jiao-cheng-P8-mi-yao-zhi-zuo-APNs-Auth-Key-huo-qu-Key-ID-589.html
请跳转上述教程
- 安卓配置
去android->app->build.gradle中进行下列配置
-
defaultConfig {
-
applicationId "包名"
-
minSdkVersion 21
-
targetSdkVersion 30
-
versionCode flutterVersionCode.toInteger()
-
versionName flutterVersionName
-
multiDexEnabled true
-
-
ndk {
-
//选择要添加的对应 cpu 类型的 .so 库。
-
abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a'
-
}
-
-
manifestPlaceholders = [
-
JPUSH_PKGNAME : "包名",
-
JPUSH_APPKEY : "Appkey", // NOTE: JPush 上注册的包名对应的 Appkey.
-
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
-
]
-
}
-
- iOS配置
看下图中,XCode中选中即可
出现下图即可
- 初始化推送插件
在pubspec.yaml中的dependencies中添加-
-
jpush_flutter: 2.1.4
-
class PushUtil {
-
static JPush? pushUtil;
-
-
static initPush() async {
-
if (pushUtil == null) {
-
pushUtil = JPush();
-
}
-
-
try {
-
pushUtil!.addEventHandler(
-
onReceiveNotification: (Map<String, dynamic> message) async {
-
debugPrint("flutter onReceiveNotification: $message");
-
},
-
-
///点击的回调事件
-
onOpenNotification: (Map<String, dynamic> message) async {
-
debugPrint("flutter onOpenNotification: $message");
-
}, onReceiveMessage: (Map<String, dynamic> message) async {
-
debugPrint("flutter onReceiveMessage: $message");
-
}, onReceiveNotificationAuthorization:
-
(Map<String, dynamic> message) async {
-
debugPrint("flutter onReceiveNotificationAuthorization: $message");
-
});
-
} on PlatformException {
-
// platformVersion = 'Failed to get platform version.';
-
}
-
-
pushUtil!.setup(
-
appKey: Platform.isIOS ? 'iOS AppKey' : "Android AppKey", //你自己应用的 AppKey
-
channel: "theChannel",
-
production: false,
-
debug: true,
-
);
-
-
///声音,震动等设置
-
pushUtil!.applyPushAuthority(
-
new NotificationSettingsIOS(sound: true, alert: true, badge: false));
-
-
///给后台的registration id
-
pushUtil!.getRegistrationID().then((rid) {
-
print("flutter get registration id : $rid");
-
});
-
}
-
}
然后在runApp(MyApp)的MyApp中初始化
-
///初始化极光推送
-
PushUtil.initPush();
获取registrationID
-
///获取极光推送注册id
-
String registrationID = await PushUtil.pushUtil!.getRegistrationID();
-
-
遇到的一些坑
iOS发布到App Store上以后,安卓也上正式
安卓的推送可以正常收到,iOS的正式环境收不到
后面经过和客服沟通,发现是后台发起推送时,
配置的问题
apns_production true正式 false测试
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhgakkgj
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01