السلام عليكم,
يمكنك استخدام onesignal لأرسال تنبيهات Push Notifications بدون الحاجة الى استخدام سيرفر خارجي او سيرفر خاص بك.
الكود في المثال كود فلاتر.
sendAdNotification() async {
OneSignal.shared.getPermissionSubscriptionState();
OneSignal.shared.getDeviceState().then((deviceState) {
print("OneSignal: device state: ${deviceState?.userId}");
});
var sendData = await post(
Uri.parse('https://onesignal.com/api/v1/notifications'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Basic RESTAPIKEY',
},
body: jsonEncode(<String, dynamic>
{
"app_id": "APPID",//kAppId is the App Id that one get from the OneSignal When the application is registered.
"filters": [
{"field": "tag", "key": "KeyNAme", "relation": "=", "value": Id},
],
"android_accent_color":"FF9976D2",
"small_icon":"ic_stat_onesignal_default",
"large_icon":"biglogo.png",
"headings": {"en": "اعلان جديد"},
"contents": {"en": titleTextEditingController.text},
}),
);
debugPrint(sendData.body.toString());
}
اترك تعليقاً