Thuta Learning
ရှာဖွေရန်
AdvancedMobile Developmentintermediate

Push Notifications Basics

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Push Notifications Basics ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • ကိုယ်တိုင် code ရေးပြီး Expo Go ပေါ်မှာ run ကြည့်တတ်မယ်
  • Real app project ထဲမှာ ဒီ concept ကို ချက်ချင်း အသုံးချတတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

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 နမူနာ

javascript
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 },
});
You should see
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 ပိုကောင်းပါတယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Push token ကို backend database ထဲ သိမ်းစရာ မလိုတယ်လို့ ထင်ခြင်း — remote push ပို့ဖို့ backend ကနေ token ကို သိထားရပါမည်
  • Local vs Push notification ကို ရောနားလည်ပြီး backend architecture design ကို ရှုပ်ထွေးအောင်လုပ်ခြင်း

အခု ကိုယ်တိုင် စမ်းကြည့်

expo-notifications install ပြီး local notification (scheduleNotificationAsync) ကို ကိုယ်တိုင် schedule ကြည့်ပါ (Expo Go ပေါ်မှာ)။

You'll know it worked when: Permission ရပြီးရင် push token string တစ်ခု ရမည်, local notification ကို ၆၀ စက္ကန့်အကြာ trigger ဖြစ်လာမည်။

Push Notifications Basics | Thuta Learning