में पुश नोटिफिकेशन प्राप्त करने में समस्या आईओएस 10 के लिए पुश अधिसूचना सेट अप करने का प्रयास कर रहा है।आईओएस 10 और आईओएस 9
// Register for the defined notifications
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = UIApplication.shared.delegate as! AppDelegate
center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if error == nil {
UIApplication.shared.registerForRemoteNotifications()
}
}
} else {
// Fallback on earlier versions
let notificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: [autoCancelCategory])
UIApplication.shared.registerUserNotificationSettings(notificationSettings)
UIApplication.shared.registerForRemoteNotifications()
}
यह मेरे विचार नियंत्रकों में से एक में लॉगिन^पर कहा जाता है: यह कुछ गाइड मेरी सेटअप इसलिए की तरह है के माध्यम से नीचे से 10
पढ़ें संस्करणों के लिए पहले से काम कर रहा था।
और अब AppDelegate
में, यह UNUserNotificationCenterDelegate
के अनुरूप है, मैं इन तरीकों है:
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("Got a push!")
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) {
print("Got a push!")
}
और मैं भी है:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let settings = UserDefaults.standard
settings.setValue(deviceToken, forKey: "deviceToken")
}
डिवाइस टोकन Data
के रूप में सर्वर पर अपलोड है, और इसने पिछले संस्करणों के लिए ठीक काम किया है।
मैंने जांच की है कि सर्वर पर टोकन फोन पर एक से मेल खाता है।
मैंने Capabilities
में सभी लक्ष्यों के लिए पुश सूचनाएं सक्षम की हैं, मैंने Add the push Notifications entitlement to your entitlements file
भी चुना है।
धक्का पर हालांकि कुछ भी प्राप्त नहीं कर रहा है।
कोई विचार क्या मैं यहां गलत कर सकता हूं? किसी भी संकेतक वास्तव में सराहना की जाएगी!
धन्यवाद!
संपादित करें: मैंने यह भी देखा है कि पुश सूचनाएं आईओएस 9 में काम नहीं कर रही हैं।
यह ओएस समस्या हो सकती है। कृपया डिवाइस को पुनरारंभ करके आज़माएं। https://twitter.com/yogye7/status/781340933228945408 –