ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Push notification ရဲ့ high-level workflow — (1) App က permission တောင်း, (2) device unique 'push token' ရယူ, (3) push token ကို backend server ဆီ ပို့သိမ်း, (4) backend က event တစ်ခုခု ဖြစ်ချိန် (message ရောက်, order confirm) push token ကို သုံးပြီး Expo/FCM/APNs push service ကနေတဆင့် notification ပို့။ Local notification (device ကိုယ်တိုင် schedule) နဲ့ Remote/Push notification (server ကနေ trigger) ကို ခွဲခြားနားလည်ဖို့ အရေးကြီးပါတယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
expo-notifications ကို install ပြီး Notifications.requestPermissionsAsync() ခေါ်ရင် permission dialog ပေါ်ပြီး, granted ရင် Notifications.getExpoPushTokenAsync() ကနေ unique token တစ်ခု ရပါတယ် — ဒီ token ကို backend database ထဲ user record နဲ့ တွဲသိမ်းထားရမှာပါ။ Local notification (ဥပမာ reminder) ကတော့ backend မလိုဘဲ Notifications.scheduleNotificationAsync() နဲ့ device ကိုယ်တိုင် schedule လုပ်လို့ရပါတယ်။
Code နမူနာ
import * as Notifications from 'expo-notifications';
async function registerForPushNotifications() {
const { status } = await Notifications.requestPermissionsAsync();
if (status !== 'granted') return null;
const tokenData = await Notifications.getExpoPushTokenAsync();
return tokenData.data; // send this to your backend to store
}
// Local notification example (no backend needed)
await Notifications.scheduleNotificationAsync({
content: { title: 'Reminder', body: 'Practice React Native today!' },
trigger: { seconds: 60 },
});Permission ရပြီးရင် push token string တစ်ခု ရမည်, local notification ကို ၆၀ စက္ကန့်အကြာ trigger ဖြစ်လာမည်။၅ မိနစ် စမ်းကြည့်
expo-notifications install ပြီး local notification (scheduleNotificationAsync) ကို ကိုယ်တိုင် schedule ကြည့်ပါ (Expo Go ပေါ်မှာ)။
သတိလေးတစ်ချက်
Push notification permission ကို app ဖွင့်ချက်ချင်း တောင်းရင် user တွေက deny ဖန်များပါတယ် — feature ကို တကယ်သုံးမယ့်အချိန် (ဥပမာ chat feature ပထမဆုံးသုံးချိန်) မှသာ contextually တောင်းတာက accept rate ပိုကောင်းပါတယ်။