7 C
Friday, December 15, 2023

swift – Native Push Notification not working in iOS

//  LocalNotifications.swift
//  PushNotifications_Tutorial
//  Created by Abhishek Gautam on 15/12/23.

import SwiftUI
import UserNotifications

class NotificationManager {
    static let occasion = NotificationManager() // Singleton
    func requestAuthorization() {
        let choices : UNAuthorizationOptions = [.alert, .sound, .badge]
        UNUserNotificationCenter.present().requestAuthorization(choices: choices) { (success, error) in
            if let error = error{
                print("ERROR : (error)")
            else {
    func scheduleNotification() {
        let content material = UNMutableNotificationContent()
        content material.title = "That is my first push notification"
        content material.subtitle = "This was sooooo a lot enjoyable!"
        content material.sound = .default
        content material.badge = 1
        let set off = UNTimeIntervalNotificationTrigger(timeInterval: 1.0, repeats: false)
        let request = UNNotificationRequest(identifier: UUID().uuidString, content material: content material, set off: set off)

struct LocalNotifications: View {
    var physique: some View {
        VStack(spacing :40){
            Button("Request Permission") {
                //print("Button Tapped!")
            Button("Schedule Notification") {

#Preview {

Every little thing appears to be working nice, however the issue is the notification shouldn’t be exhibiting up. I’m making an attempt to be taught push notification in iOS from a youtube video, issues appears to be working good for the youtuber, however I additionally did the identical factor and it is not woking for me.

I attempted to entry the permission of the consumer, which is a Success. However in the case of the pop-up a part of the notification , it is not exhibiting up. Please assist.

Latest news
Related news


Please enter your comment!
Please enter your name here