में काम नहीं कर UNLocationNotificationTrigger- उपयोगकर्ता सूचना ढांचा उपलब्ध आईओएस 10 में मैं जब भी उपयोगकर्ता UNLocationNotificationTrigger का उपयोग कर विशिष्ट भौगोलिक स्थान में प्रवेश करती है सूचना उत्प्रेरित करने की कोशिश की का उपयोग करना। जब मैंने भौगोलिक स्थान को अनुकरण करके सिम्युलेटर के माध्यम से परीक्षण करने का प्रयास किया, तो अधिसूचना ट्रिगर नहीं हो रही है, लेकिन स्थान प्रबंधक अद्यतन भौगोलिक स्थान लौटाता है। क्या इसे सिम्युलेटर में चलाने के बजाए वास्तविक डिवाइस में परीक्षण किया जाना चाहिए?सिम्युलेटर
7
A
उत्तर
2
Apple Documentation के अनुसार:
Apps का स्थान सेवाओं तक पहुंच का अनुरोध करना होगा और इस वर्ग का उपयोग करने के लिए जब-इन-उपयोग अनुमतियाँ होना आवश्यक है। स्थान सेवाओं का उपयोग करने के लिए अनुमति का अनुरोध करने के लिए, किसी भी स्थान-आधारित ट्रिगर्स को शेड्यूल करने से पहले CLLocationManager की requestWhenInUseAuthorization() विधि को कॉल करें।
हालांकि मेरे अनुकरणकर्ता/उपकरणों "जब उपयोग में" अनुमतियां पर्याप्त नहीं हैं, अनुमतियों को हमेशा "हमेशा" पर सेट किया जाना चाहिए।
इस प्रकार,
<key>NSLocationAlwaysUsageDescription</key>
<string>We use your location to warn you when there are adorable cats nearby</string>
तो स्थान को सक्रिय अपने pinfo.list के लिए इस कुंजी जोड़ें। आपके ट्रिगर केवल एक बार आप जानते हैं कि आप हमेशा के लिए अधिकृत हैं परिभाषित करें, उदाहरण के लिए मैं इसे यहाँ किया didChangeAuthorizationStatus में:
class myClass : CLLocationManagerDelegate {
var locationManager: CLLocationManager()
func init() {
// Note: defining the location manager locally in this function won't work
// var locationManager: CLLocationManager()
// as it gets gargabe collected too early.
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) {(accepted, error) in
if !accepted {
logger.info("Notification access denied.")
}
}
// MARK CLLocationManagerDelegate:
func locationManager(manager: CLLocationManager,
didChangeAuthorizationStatus status: CLAuthorizationStatus)
{
if status == .AuthorizedAlways {
let region = CLCircularRegion(center: CLLocationCoordinate2D(latitude: 61.446812, longitude: 23.859914),
radius: 1000, identifier: "test")
logger.info("Notification will trigger at \(region)")
region.notifyOnEntry = true
region.notifyOnExit = false
let trigger = UNLocationNotificationTrigger(region: region, repeats:true)
let content = UNMutableNotificationContent()
content.title = "Oh Dear !"
content.body = "It's working!"
content.sound = UNNotificationSound.default()
let request = UNNotificationRequest(identifier: "textNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("Uh oh! We had an error: \(error)")
}
}
}
}
}
संबंधित मुद्दे
- 1. सिम्युलेटर
- 2. सिम्युलेटर
- 3. सिम्युलेटर
- 4. सिम्युलेटर
- 5. सिम्युलेटर
- 6. सिम्युलेटर
- 7. सिम्युलेटर
- 8. सिम्युलेटर
- 9. सिम्युलेटर
- 10. सिम्युलेटर
- 11. एक्सकोड 8 आईओएस 10 सिम्युलेटर, सिम्युलेटर
- 12. आईफोन सिम्युलेटर
- 13. आईओएस सिम्युलेटर
- 14. आईफोन सिम्युलेटर
- 15. एंड्रॉइड सिम्युलेटर
- 16. सिम्युलेटर स्लाइस
- 17. आईपैड-सिम्युलेटर
- 18. आईफोन सिम्युलेटर
- 19. आईफोन सिम्युलेटर
- 20. आईफोन सिम्युलेटर
- 21. आईओएस सिम्युलेटर
- 22. आईफोन सिम्युलेटर
- 23. एसडीके सिम्युलेटर
- 24. सिम्युलेटर आयनिक
- 25. आईओएस सिम्युलेटर
- 26. अंतर्राष्ट्रीयकरण: सिम्युलेटर
- 27. आईफोन सिम्युलेटर
- 28. आईओएस सिम्युलेटर
- 29. आईओएस सिम्युलेटर
- 30. आईफोन - सिम्युलेटर
मैं मुसीबत के साथ-साथ वास्तविक डिवाइस में सूचना हो रही हो रही है। :/ – Rihards
मैं सिम्युलेटर और डिवाइस दोनों पर उपयोगकर्ता अधिसूचना फ्रेमवर्क का उपयोग करके दिनांक और समय के आधार पर अधिसूचना ट्रिगर करने में सक्षम हूं। मैं अभी तक डिवाइस में स्थान आधारित अधिसूचना की जांच नहीं कर रहा हूं। – Ashok
क्या आप इसे ठीक करने में कामयाब रहे हैं? यदि नहीं, तो मैं आपको एक हाथ दे सकता हूं। –