खोज…


UserNotifications

  1. आपको UserNotifications आयात करना होगा

     @import UserNotifications;
    

2. स्थानीयकरण के लिए पर्याप्त प्राधिकरण

let center = UNUserNotificationCenter.current()
center.requestAuthorization([.alert, .sound]) { (granted, error) in
    // Enable or disable features based on authorization.
}
  1. अब हम एप्लिकेशन आइकन बैज नंबर अपडेट करेंगे

     @IBAction  func triggerNotification(){
     let content = UNMutableNotificationContent()
     content.title = NSString.localizedUserNotificationString(forKey: "Tom said:", arguments: nil)
     content.body = NSString.localizedUserNotificationString(forKey: "Hello Mike!Let's go.", arguments: nil)
     content.sound = UNNotificationSound.default()
     content.badge = UIApplication.shared().applicationIconBadgeNumber + 1;
     content.categoryIdentifier = "com.mike.localNotification"
     //Deliver the notification in two seconds.
     let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 1.0, repeats: true)
     let request = UNNotificationRequest.init(identifier: "TwoSecond", content: content, trigger: trigger)
    
     //Schedule the notification.
     let center = UNUserNotificationCenter.current()
     center.add(request)
     }
    
     @IBAction func stopNotification(_ sender: AnyObject) {
     let center = UNUserNotificationCenter.current()
     center.removeAllPendingNotificationRequests()
     }
    


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow