我正在完成有关洪水推送通知的最后一年的项目。以前,只要数据库中的值从0变为1,用户都将检索通知。但是现在,在我的应用程序中,用户可以选择将车停在哪个地方,并且可以根据公园的位置来检索状态和通知。零或一。例如,用户A在中谷设置其微调器值,用户B在KPS中设置其微调器值。当FLOOD_STATUS_MID_VALLEY为1时,用户A将收到通知,而由于FLOOD_STATUS_KPS仍为0,用户B没有收到任何通知。任何人都可以帮助我如何基于应用程序中的微调器值发送通知?
我的应用的屏幕截图Screenshot
下面是在服务器上运行的python代码,用于基于Firebase数据库中名为“ FLOOD_STATUS”的值发送通知
from pusher_push_notifications import PushNotifications
config = {
'apiKey': "APIKEY",
'authDomain': "car-app-push-notification.firebaseapp.com",
'databaseURL': "https://car-app-push-notification.firebaseio.com",
'projectId': "car-app-push-notification",
'storageBucket': "car-app-push-notification.appspot.com",
'messagingSenderId': "596729642105",
'appId': "APPID",
'measurementId': "G-9LMJGS1BDW"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
beams_client = PushNotifications(
instance_id='49f62b05-bd81-4040-ab57-80afa56a8680',
secret_key='SECRET KEY',
)
def stream_handler(message):
print(message)
if(message['data'] is 1):
response = beams_client.publish_to_interests(
interests=['hello'],
publish_body={
'apns': {
'aps': {
'alert': 'Hello!',
},
},
'fcm': {
'notification': {
'title': 'Alert!',
'body': 'It is starting to flood, please remove your car immediately!',
},
},
},
)
print(response['publishId'])
my_stream = db.child("FLOOD_STATUS").stream(stream_handler,None)
由于这是您的五年计划,因此我不会提供任何代码。
[用户更改了他们停放的位置时,您将要更改他们的设备兴趣以匹配相关位置。
当给定位置的FLOOD_STATUS
被更新为1
时,您发送通知至匹配的兴趣点>>。
[我建议,当用户A在MID_VALLEY
中选择Spinner
时,会将所选值发送到服务器。我建议您看看this tutorial,看看如何从Spinner
中获取所选值在服务器端,当FLOOD_STATUS_MID_VALLEY
为1时,您仅将通知发送给用户A(因为您知道用户A的FCM token
)。