का उपयोग करके स्थानीय और पुश अधिसूचनाएं iOS 10
में विकसित हुईं। यह पूरी तरह से काम कर रहा है। लेकिन अब मुझे local notifications
और push notification
कोड कैसे करना चाहिए यदि उपयोगकर्ता iOS 9
और ऊपर के संस्करणों का उपयोग कर रहा है। क्या कोई मदद कर सकता है?आईओएस 9 और 10 में स्विफ्ट 3
नीचे iOS 10
import UIKit
import UserNotifications
@available(iOS 10.0, *)
class ViewController: UIViewController,UNUserNotificationCenterDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 10.0, *) {
//Seeking permission of the user to display app notifications
UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge], completionHandler: {didAllow,Error in })
UNUserNotificationCenter.current().delegate = self
}
}
//To display notifications when app is running inforeground
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound, .badge])
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func buttonPressed(_ sender: UIButton) {
if #available(iOS 10.0, *) {
//Setting content of the notification
let content = UNMutableNotificationContent()
content.title = "hello"
content.body = "notification pooped out"
content.badge = 1
//Setting time for notification trigger
let date = Date(timeIntervalSinceNow: 10)
var dateCompenents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: dateCompenents, repeats: false)
//Adding Request
let request = UNNotificationRequest(identifier: "timerdone", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
}
}
आपकी समस्या क्या है? आपने क्या प्रयास किया है – shallowThought
मुझे अपने कोड को संशोधित करने की आवश्यकता है जैसे कि यह आईओएस 9 में भी काम करता है। उपयोगकर्ता नोटिफिकेशन फ्रेमवर्क जो मैंने यहां उपयोग किया है केवल आईओएस 10 –
में अलग-अलग दिनांक घटकों को सेट करने या स्थानीय नोटिस को कई बार कॉल करने के तरीके में कैसे मौजूद है? – ArgaPK