နားလည်ထားရမယ့် အချက်
push notification ဆိုတာ device အပြင်ဘက်က စတင်တာပါ - backend ဒါမှမဟုတ် third-party service တစ်ခုက chat message အသစ်၊ comment၊ payment ပြီးစီးမှု စတဲ့ အဖြစ်အပျက်ကို သိလိုက်ပြီး app ပိတ်ထားနေချိန် ဒါမှမဟုတ် phone အိပ်နေချိန်မှာတောင် device ဆီ ပို့ပေးလိုက်တာပါ။
local notification ကတော့ ဆန့်ကျင်ဘက်ပါ - app ကိုယ်တိုင်က device ပေါ်မှာ server လုံးဝမပါဘဲ schedule လုပ်ထားတာပါ - ညနေ ၈ နာရီ study reminder၊ workout timer ပြီးဆုံးချက်၊ နာရီအနည်းငယ်အလို ချိန်ထားတဲ့ habit-tracking notification များပါ။
Register လုပ်ခြင်း
user က ခွင့်ပြုလိုက်တာနဲ့ app က platform ရဲ့ notification system မှာ register လုပ်ပါတယ်။
Device Token ရယူခြင်း
platform က device token တစ်ခု ပြန်ပေးပါတယ် - ဒီ device ပေါ်က ဒီ app installation အတွက်ပဲ သီးသန့်ရှိတဲ့ address ပါ။
Backend ဆီ Token ပို့ခြင်း
app က ဒီ token ကို backend ဆီ ချက်ချင်းပို့ပြီး ပြောင်းလဲတိုင်းလည်း ထပ်ပို့ပါတယ်။
Backend က Token သိမ်းဆည်းခြင်း
backend က ဒီ token ကို user account နဲ့ ချိတ်ဆက်ပြီး နောက်ပိုင်း push များအတွက် သိမ်းထားပါတယ်။
နောက်ပိုင်း ဒီ user ကို notify လုပ်ချင်တဲ့အခါ backend က device ကို တိုက်ရိုက်ဆက်သွယ်တာ မဟုတ်ပါဘူး - token နဲ့ payload ကို platform ကိုယ်တိုင် run နေတဲ့ push service ဆီ လွှဲပေးလိုက်ပြီး မှန်ကန်တဲ့ device ဆီ message ကို ပို့ပေးကာ system notification အနေနဲ့ ပြပေးတာ ဒါမှမဟုတ် run နေဆဲ app ဆီ တိုက်ရိုက်ပေးပို့ပါတယ်။
payload တစ်ခုမှာ ပုံမှန်အားဖြင့် title၊ body၊ deep link အတွက် id လိုမျိုး optional custom data၊ ပြီးတော့ delivery metadata ပါဝင်ပါတယ်။
Lock Screen ဆိုတာ Public ပါပဲ
title နဲ့ body တွေဟာ lock screen ပေါ်မှာ ဘယ်သူမဆို ဖတ်နိုင်အောင် ပြသလေ့ရှိပါတယ် - account balance၊ ရောဂါအမည်၊ ဒါမှမဟုတ် one-time code ကို notification ပေါ်မှာ တိုက်ရိုက် ဘယ်တော့မှ မထားပါနဲ့။
React Native ရဲ့ push-notification သင်ခန်းစာက framework-specific registration code ကို ဖော်ပြထားပြီး ဒီသင်ခန်းစာကတော့ framework မည်သည့် implementation အောက်ခံ architecture ကို ဖော်ပြပါတယ်။
- Push Notification
- server ဒါမှမဟုတ် service တစ်ခုက စတင်ပြီး app ပိတ်ထားနေချိန်မှာတောင် platform ရဲ့ push infrastructure မှတဆင့် device ဆီ ပေးပို့လိုက်တဲ့ message တစ်ခုပါ။
- Device Token
- platform တစ်ခုက device တစ်ခုပေါ်က app installation တစ်ခုအတွက် ထုတ်ပေးတဲ့ တစ်ခုတည်းသော identifier ဖြစ်ပြီး backend က push service မှတဆင့် ဒီ install ကို ပစ်မှတ်ထားဖို့ သုံးပါတယ်။
PUSH NOTIFICATION FLOW
----------------------
PUSH NOTIFICATION FLOW
-----------------------
DEVICE TOKEN REGISTRATION
Mobile App --> Register for Notifications
Mobile App --> Receive Device Token
Mobile App --> Send Token to Backend
Backend --> Stores Token (per user, per device)
SENDING A PUSH
Backend --> Push Service --> Device --> Mobile App / Notif.
(event happens) (platform delivery) (shown to the user)
LOCAL NOTIFICATION (no backend involved)
Mobile App --> Schedules Locally --> OS Delivers at Set Timeလက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
code မရေးခင် flow တစ်ခုလုံးကို စဉ်းစားထားပါ။ app က notification permission ကို context နဲ့တကွ တောင်းသင့်ပါတယ် - ဘာကြောင့်လိုအပ်လဲ ရှင်းပြပြီးမှ၊ အရေးပါတဲ့ အချိန်နီးကပ်မှသာ တောင်းသင့်ပြီး app စဖွင့်တာနဲ့ ချက်ချင်း မမေးသင့်ပါဘူး။
ခွင့်ပြုလိုက်တာနဲ့ platform က app ကို device token တစ်ခု ပေးပါတယ်၊ app ရဲ့ အလုပ်ကတော့ ဒီ token ကို backend ဆီ ချက်ချင်းပို့ပြီး ပြောင်းလဲတိုင်းလည်း ထပ်ပို့ဖို့ပါပဲ - reinstall လုပ်ပြီးနောက် ဒါမှမဟုတ် OS update လုပ်ပြီးနောက် token တွေ ပြောင်းသွားနိုင်ပါတယ်။
- backend မှာ user account တွေကို device token တွေနဲ့ ချိတ်ဆက်ထားတဲ့ table တစ်ခု ရှိပါတယ် - user တစ်ယောက်ကို token အများကြီး ရှိနိုင်ပါတယ်။
- notify လုပ်ထိုက်တဲ့ event တစ်ခု ဖြစ်လာတဲ့အခါ backend က payload တစ်ခု ဖန်တီးပြီး token တစ်ခုချင်းစီအတွက် push service ဆီ ပို့ပေးပါတယ်။
- payload ရဲ့ data field ကို သေးငယ်အောင်ထားပါ - ပုံမှန်အားဖြင့် tap လုပ်လိုက်ရင် မှန်ကန်တဲ့ screen ဆီ route လုပ်ဖို့ type နဲ့ id ပဲ လိုအပ်ပါတယ်။
- sensitive ဖြစ်နိုင်တာတွေအတွက် visible title/body ကို ယေဘူယျအနေနဲ့ ထားပြီး user app ဖွင့် login ဝင်ပြီးမှ အသေးစိတ်ကို ရယူပါ။
Lock Screen အစစ်ပေါ်မှာ စမ်းကြည့်ပါ
code က ဘာပို့လဲဆိုတာထက် lock screen အစစ်ပေါ်မှာ ဘာတွေအမှန်တကယ် ပေါ်လာလဲကို အမြဲစစ်ဆေးပါ - preview နဲ့ ပြသပုံ စည်းမျဉ်းတွေဟာ platform နဲ့ OS version အလိုက် ကွဲပြားနိုင်ပါတယ်။
အတူတူ စမ်းရေးကြည့်မယ်
function evaluateNotificationPayload(payload, context) {
if (!payload.containsSensitiveInfo) {
return { verdict: "safe", action: "show-as-is", reason: "No sensitive info in the payload." };
}
if (context.isLockScreen) {
return {
verdict: "unsafe",
action: "redact",
reason: "Sensitive info would render on the lock screen for anyone to see."
};
}
return {
verdict: "risky",
action: "redact-recommended",
reason: "Content also persists in the notification center after unlock, so redact by default."
};
}
const orderUpdate = {
title: "Order shipped",
body: "Your order is on its way!",
containsSensitiveInfo: false
};
const labResult = {
title: "New result from Dr. Lin",
body: "Your test came back positive for...",
containsSensitiveInfo: true
};
console.log("Order update:", evaluateNotificationPayload(orderUpdate, { isLockScreen: true }));
console.log("Lab result:", evaluateNotificationPayload(labResult, { isLockScreen: true }));Order ပို့ပြီးကြောင်း safe notification က sensitive info မပါလို့ { verdict: 'safe', action: 'show-as-is' } ကို ပြန်ပေးပါတယ်။ lab-result notification ကတော့ sensitive info ပါဝင်ပြီး lock screen context ဖြစ်နေတဲ့အတွက် { verdict: 'unsafe', action: 'redact' } ကို ပြန်ပေးပါတယ် - lock screen ပေါ်မှာ ဘယ်သူမဆို မြင်နိုင်မှာမို့ပါ။၅ မိနစ် စမ်းကြည့်
app က ပို့နိုင်မယ့် notification တစ်ခု (ဥပမာ 'သင့် post ပေါ် comment အသစ်') အတွက် spec အတိုချုပ် ရေးပါ။ visible title/body ထဲ ဘာထည့်မလဲ၊ app ဖွင့်ပြီးမှ fetch လုပ်ရမယ့် data field ထဲ ဘာထားမလဲ တိတိကျကျ ဆုံးဖြတ်ပါ။ ပြီးရင် isLockScreen true နဲ့ evaluateNotificationPayload-စတိုင် function ကို run ပြီး verdict က သင့် design နဲ့ ကိုက်ညီမလား စစ်ဆေးပါ။
သတိလေးတစ်ချက်
user က ဘာကြောင့်လိုအပ်လဲ နားမလည်ခင် app ဖွင့်ချက်ချင်း notification permission တောင်းလိုက်တာက ထာဝရ ငြင်းဆန်မှုတွေကို ဖြစ်စေတတ်ပါတယ်။
message အစစ်၊ account အသေးစိတ်၊ ဒါမှမဟုတ် code များကို ယေဘူယျ placeholder အစား payload ရဲ့ title/body ထဲ တိုက်ရိုက်ထည့်လိုက်တာ။
Push technology - Wikipedia — How Mobile Apps Work