Flutter 弹通知栏插件
flutter_local_notifications
阿里推送,辅助推送挺有意思 github.com/bravekingzh…
也让我懂了为啥我杀死了应用tm的还能推送,比如那拼多多
最后选择 极光推送吧,这个无需App后台推送,由服务器推送,而且好像不少人用
pub.flutter-io.cn/packages/jp… 搞进来
jpush_flutter: ^0.1.0
android:
注册极光社区
创建应用 -- 推送设置 - -安卓添加包名 - -
打开android/app/src/build.gradle文件,加入如下代码:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.paoding.jieda"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//加下面这段
manifestPlaceholders = [
JPUSH_PKGNAME: applicationId,
JPUSH_APPKEY : "这里写入你自己申请的Key哦", /*NOTE: JPush 上注册的包名对应的 Appkey.*/
JPUSH_CHANNEL: "developer-default", /*暂时填写默认值即可.*/
]
}
然后在main.dart
void main() => realRunApp();
void realRunApp() async {
final JPush jPush = JPush();
Future<void> initPlatformState() async {
jPush.getRegistrationID().then((rid) {
print('---->rid:${rid}');
});
jPush.setup(
appKey: "-这里写入你自己申请的Key哦",
channel: "developer-default",
production: false,
debug: true,
);
jPush.applyPushAuthority(
NotificationSettingsIOS(sound: true, alert: true, badge: true)
);
try {
jPush.addEventHandler(
onReceiveNotification: (Map<String,dynamic>message) async {
print('---->接收到推送:${message}');
}
);
} on Exception {
print("---->获取平台版本失败");
}
}
initPlatformState();
runApp(MyApp());
}
此时可以在极光开发者服务,左边列表tab第一项,极光推送模拟服务器推送消息
登陆的时候要注册别名
jPush
.setAlias(LocalStorage.get(BaseCommon.USER_ID).toString())
.then((map) {
print("设置用户推送别名---------------");
print(map);
});
final JPush jPush = JPush();
如果要实现像QQ微信那样的效果
还有顶部弹框,需要去开启权限,下面是小米举例,
权限允许我还不知道咋整,到时候学学,学了就来更新哈。
参考:www.cnblogs.com/niceyoo/p/1…
www.imooc.com/article/det… 这个0.0.4版本的main不能参考,代码换了
www.jianshu.com/p/7f3ffc71a… 可以参考这个的main