基本的なローカルプッシュを実現するためのジグアンプッシュを備えたフラッタードック
原文:@ As.Kai
ブログアドレス:https://blog.csdn.net/qq_42362997
以下の内容が参考になりましたら、よろしくお願いします〜
最初に依存関係パッケージをインポートします
需要导入极光推送依赖包:
#极光推送JPush
jpush_flutter: ^0.6.2
#接着pub get
最新のパブバージョンを表示する:
ポータル
構成の側面:
android / app /build.gradleにいくつかの構成を追加します
android: {
....
defaultConfig {
...
ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a',
}
manifestPlaceholders = [
JPUSH_PKGNAME : 你的key,
JPUSH_APPKEY : "appkey", // NOTE: JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
}
}
Aurora開発者IDがありませんか?
ゴーJiguangの公式ウェブサイトhttps://www.jiguang.cn/Registrationへと言うまでもなく、ログイン、言うために
、アプリケーションと作成> =アバター=>開発者プラットフォームの右上にあるサービスセンターをクリックして入力します
塗りつぶし確認する名前に=> Androidプラットフォームのメッセージプッシュを選択しますワンステップ=>アプリケーションパッケージ名を入力します
パッケージ名が見つかりませんか?
プロジェクトを開き、
android / app / src / main / AndroidManifest.xmlを見つけます。
上部にあるパッケージタグを開きます。パッケージ名をコピーしてJiguangに入力すると、完了
です。完了すると、 AppKey。このAppKeyを取得したら、それを入力します。build.gradleにアクセスします。
設定が完了したら、その使用方法を見てみましょう。
//极光推送
final JPush _jPush = new JPush();
//异步方法 推送消息监听
Future<void> initPlatformState() async {
//错误信息
String platformVersion;
try {
//响应时间
_jPush.addEventHandler(
//接收通知回调方法
onReceiveNotification: (Map<String, dynamic> message) async {
//接收到数据 //进程运行时候可以接受
// print('>>>>>>>>>flutter接收到推送:${message}');
setState(() {
debugLable = '接收到极光推送数据:$message';
// notifyRoute();
});
}, //点击通知毁掉方法
onOpenNotification: (Map<String, dynamic> message) async {
await print('触发onOpenNotification>>>>>>>${message.toString()}');
// notifyRoute();
},
//接收自定义消息回调方法
// onReceiveMessage: (Map<String,dynamic> message) async{
// print('触发onReceiveMessage');
// notifyRoute();
// }
);
} on PlatformException {
platformVersion = '平台版本获取失败,请检查配置';
}
if (!mounted) return;
setState(() {
debugLable = platformVersion;
print('deBug===${debugLable.toString()}');
});
}
次に、ボタンクリックイベントをビルドに追加して、ボタンクリックを実現してプッシュを送信します。
child: FlatButton(
onPressed: () {
//3秒后时间
var fireDate = DateTime.fromMillisecondsSinceEpoch(
DateTime.now().millisecondsSinceEpoch + 3000);
var localNotification = LocalNotification(
id: 001,
title: '作者:@As丶Kai',
content: '看到了说明已经成功了',
buildId: 1,
fireTime: fireDate,
subtitle: '子标题');
_jPush
.sendLocalNotification(localNotification)
.then((value) {
//传递
setState(() {
debugLable = value;
print('value===${value.toString()}');
});
});
},
child: new Text('发送推送信息',
style: TextStyle(color: Colors.white))),
3秒のタイムスタンプを作成し、3秒後にプッシュします
var fireDate = DateTime.fromMillisecondsSinceEpoch(
DateTime.now()。millisecondsSinceEpoch + 3000);
実行して効果を確認してください!上記はJiguangの基本的なローカルプッシュ統合です
完全なコードは次のとおりです。
//极光推送
final JPush _jPush = new JPush();
String debugLable = 'Unknown';
//推送跳转
void notifyRoute() async {
await Navigator.of(context)
.push(new MaterialPageRoute(builder: (ctx) => new IndexPage()));
}
Future<void> initPlatformState() async {
//错误信息
String platformVersion;
try {
//响应时间
_jPush.addEventHandler(
//接收通知回调方法
onReceiveNotification: (Map<String, dynamic> message) async {
//接收到数据 //进程运行时候可以接受
// print('>>>>>>>>>flutter接收到推送:${message}');
setState(() {
debugLable = '接收到极光推送数据:$message';
// notifyRoute();
});
}, //点击通知毁掉方法
onOpenNotification: (Map<String, dynamic> message) async {
await print('触发onOpenNotification>>>>>>>${message.toString()}');
// notifyRoute();
},
//接收自定义消息回调方法
// onReceiveMessage: (Map<String,dynamic> message) async{
// print('触发onReceiveMessage');
// notifyRoute();
// }
);
} on PlatformException {
platformVersion = '平台版本获取失败,请检查配置';
}
if (!mounted) return;
setState(() {
debugLable = platformVersion;
print('deBug===${debugLable.toString()}');
});
}
//*******************END****************
@override
void initState() {
// TODO: implement initState
initPlatformState();
}
@override
Widget build(BuildContext context) {
setState(() {
print('deBug===${debugLable.toString()}');
});
return Scaffold(
backgroundColor: Colors.black,
appBar: new AppBar(
brightness: Brightness.dark,
title: new Text(widget.title),
),
body: return new Column(
children: [
new Text(
'结果:${debugLable}',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(30.0)),
),
new Center(
child: FlatButton(
onPressed: () {
//3秒后时间
var fireDate = DateTime.fromMillisecondsSinceEpoch(
DateTime.now().millisecondsSinceEpoch + 3000);
var localNotification = LocalNotification(
id: 001,
title: '作者:@As丶Kai',
content: '看到了说明已经成功了',
buildId: 1,
fireTime: fireDate,
subtitle: '子标题');
_jPush
.sendLocalNotification(localNotification)
.then((value) {
//传递
setState(() {
debugLable = value;
print('value===${value.toString()}');
});
});
},
child: new Text('发送推送信息',
style: TextStyle(color: Colors.white))),
)
],
),
);
}
効果:
私に従って、一緒に成長してください!
@ As.Kai