ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Basic chapter မှာ `Info.plist` ထဲ usage description string ထည့်ရမယ်ဆိုတာ လေ့လာခဲ့ပြီးသားပါ — iOS API (Camera, Location) ကို ခေါ်တာနဲ့ system dialog ကို automatic ပြပေးပါတယ် (Android လိုမျိုး `rememberLauncherForActivityResult` manual trigger စရာ မလိုပါ) — user 'Allow' ဒါမှမဟုတ် 'Don't Allow' ရွေးနိုင်ပါတယ်။ Location permission ကို 'While Using App' / 'Always' ဆိုပြီး granularity ၂ မျိုးထိ ခွဲထားတတ်ပါတယ် — 'Always' (background location) ကို App Store review က အထူး strict စစ်ဆေးပါတယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Location feature ရှိတဲ့ app မှာ `CLLocationManager().requestWhenInUseAuthorization()` ကို ခေါ်ရင် — `Info.plist` ထဲက `NSLocationWhenInUseUsageDescription` string ပါတဲ့ system dialog ချက်ချင်း ပေါ်လာပါတယ်, user 'Allow' နှိပ်မှသာ location data ကို ရယူနိုင်ပါတယ်, 'Don't Allow' ရွေးရင် graceful ဖြစ်ဖြစ် handle လုပ်ပေးရပါတယ်.
အတူတူ ကြည့်မယ်
import CoreLocation
class LocationManager: NSObject, ObservableObject {
private let manager = CLLocationManager()
override init() {
super.init()
manager.delegate = self
}
func requestPermission() {
manager.requestWhenInUseAuthorization()
}
}
extension LocationManager: CLLocationManagerDelegate {
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
print("Authorization status: \(manager.authorizationStatus)")
}
}`requestPermission()` ခေါ်ရင် system location permission dialog ပေါ်လာပြီး, 'Allow' ရွေးရင် authorizationStatus ပြောင်းသွားတာ Console ထဲ တွေ့ရမည်။၅ မိနစ် စမ်းကြည့်
`LocationManager` ကို ကိုယ်တိုင်ရေးပြီး `Info.plist` ထဲ `NSLocationWhenInUseUsageDescription` ထည့်ကာ Simulator ပေါ်မှာ permission dialog ကို trigger ကြည့်ပါ — 'Allow' နဲ့ 'Don't Allow' ၂ မျိုးလုံး ရွေးကြည့်ပါ။
သတိလေးတစ်ချက်
User 'Don't Allow' ကို ရွေးလိုက်ရင် app ကနေ dialog ကို ထပ်ခါထပ်ခါ ပြခွင့် မရှိတော့ပါ — Settings ကို manual သွားရမှာမို့, app ထဲမှာ 'Settings ဖွင့်ပါ' ဆိုတဲ့ guidance ကို ပြသင့်ပါတယ်။