How to Add Local Push Notification With timeInterval & Test On Simulator

Last update: Nov 6, 2021

Technicalisto

How to Add Local Push Notification With timeInterval & Test On Simulator

  1. In Project Target ( Signing & Capapilities ) Add Capapility :

    1. Background Modes : Check -> [ Bachground fetch , Remote notifications , Background processing ]
    
    2. Push Notification
    

//---------------------------------------------------------------------------------------------

  1. In App Delegate Import :

    import UserNotifications
    
    import BackgroundTasks
    

//---------------------------------------------------------------------------------------------

  1. Add Settings of Push Notification ->

|. Define gcmMessageIDKey :

    let gcmMessageIDKey = "gcm.message_id"

||. Add Delegate of UNUserNotificationCenterDelegate for handle message :

Void) { let userInfo = response.notification.request.content.userInfo print(userInfo) completionHandler() } } ">
    // [START ios_10_message_handling]
    @available(iOS 10, *)
    extension AppDelegate : UNUserNotificationCenterDelegate {

        func userNotificationCenter(_ center: UNUserNotificationCenter,
                            willPresent notification: UNNotification,
                            withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

            let userInfo = notification.request.content.userInfo

            if let messageID = userInfo[gcmMessageIDKey] {
                print("Message ID: \(messageID)")
            }

            completionHandler([.alert,.badge, .sound])

            print(userInfo)

        }

        func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {
            let userInfo = response.notification.request.content.userInfo

            print(userInfo)

            completionHandler()
        }
      }

//---------------------------------------------------------------------------------------------

  1. In App Delegate add method :

    func applicationDidEnterBackground(_ application: UIApplication) {
        application.beginBackgroundTask {} // Allows to run background tasks
    }
    

//---------------------------------------------------------------------------------------------

  1. In App Delegate Inside method didFinishLaunchingWithOptions add :

    application.beginBackgroundTask(withName: "showNotification", expirationHandler: nil)
    
    let center = UNUserNotificationCenter.current()
    
    center.delegate = self as! UNUserNotificationCenterDelegate
    

//---------------------------------------------------------------------------------------------

  1. Call this method to take a permission for use push notification :

    func TakeLocalNotificationPermisiion(){
       UNUserNotificationCenter.current().requestAuthorization(options: [.alert , .badge , .sound]) { (granted, error) in
          if granted {
              print("User gave permissions for local Notifications")
          }else{ 
    
          }
      }
      }
    

//---------------------------------------------------------------------------------------------

  1. You Can Test By The following lines :

     let content = UNMutableNotificationContent()
     
     content.title = "Technicalisto"
     
     content.subtitle = "Test Local Push Notification On Simulator"
     
     content.sound = UNNotificationSound.default
    
     let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
    
     let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
    
     UNUserNotificationCenter.current().add(request)
    

Thanks

GitHub

https://github.com/AyaBaghdadi/Local_Push_Notification
You might also like...

Easily create Local Notifications in swift - Wrapper of UserNotifications Framework

Easily create Local Notifications in swift - Wrapper of UserNotifications Framework

In IOS 10, apple updated their library for Notifications and separated Local and push notifications to a new framework: User Notifications This librar

Jun 21, 2022

See all your scheduled local notifications in one place

See all your scheduled local notifications in one place

ScheduledNotificationsViewController Nice Photon is available for hire! Talk to

Jun 19, 2022

SystemNotification is lets you mimic the native iOS system notification in your SwiftUI apps.

SystemNotification is lets you mimic the native iOS system notification in your SwiftUI apps.

SystemNotification is a SwiftUI library that lets you mimic the native iOS system notification in your iOS apps.

Jun 27, 2022

Custom notification view

Custom notification view

Custom notification view

Nov 11, 2021

Roar - Let's reskin Notification Center

Roar Let's reskin Notification Center. See this blog post. Thanks Big thanks to

Mar 15, 2022

FNotify - Notification Library For iOS

FNotify Notification Library For IOS FNotify.mov Requirements: xcode 12+ swift 5

Jan 9, 2022

Chanify is a safe and simple notification tools. This repository is iOS clinet for Chanify.

Chanify is a safe and simple notification tools. This repository is iOS clinet for Chanify.

Chanify English | ็ฎ€ไฝ“ไธญๆ–‡ Chanify is a safe and simple notification tools. For developers, system administrators, and everyone can push notifications wit

Jun 19, 2022

SNPnotificationBar - Notification Bar for ios

SNPnotificationBar - Notification Bar for ios

SNPnotificationBar Screenshot Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements S

Nov 20, 2019

OS X app for sending push with Apple Push Notification service (APNs)

OS X app for sending push with Apple Push Notification service (APNs)

pushHandle OS X app for sending push with Apple Push Notification service (APNs) About This app was created just to allow painless testing of push not

Nov 7, 2021

A way to quickly add a notification badge icon to any view. Make any view of a full-fledged animated notification center.

A way to quickly add a notification badge icon to any view. Make any view of a full-fledged animated notification center.

BadgeHub A way to quickly add a notification badge icon to any view. Demo/Example For demo: $ pod try BadgeHub To run the example project, clone the r

Jun 16, 2022

A way to quickly add a notification badge icon to any view. Make any view of a full-fledged animated notification center.

A way to quickly add a notification badge icon to any view. Make any view of a full-fledged animated notification center.

BadgeHub A way to quickly add a notification badge icon to any view. Demo/Example For demo: $ pod try BadgeHub To run the example project, clone the r

Jun 16, 2022

๐Ÿ“† Breeze through Date, DateComponents, and TimeInterval with Swift!

๐Ÿ“† Breeze through Date, DateComponents, and TimeInterval with Swift!

Datez ๐Ÿ“† Breeze through Date, DateComponents, and TimeInterval Highlights Two Custom Structs Only (value types FTW!): DateView: An Date associated wit

Feb 6, 2022

๐Ÿ“† Breeze through Date, DateComponents, and TimeInterval with Swift!

๐Ÿ“† Breeze through Date, DateComponents, and TimeInterval with Swift!

Datez ๐Ÿ“† Breeze through Date, DateComponents, and TimeInterval Highlights Two Custom Structs Only (value types FTW!): DateView: An Date associated wit

Feb 6, 2022

'Minimalistic Push' is a minimalistic push-up application now built with Flutter.

'Minimalistic Push' is a minimalistic push-up application now built with Flutter.

Minimalistic Push Minimalistic Push is one of the simplest push-up trackers out there. You can track your push-ups in the training mode and see an ove

May 12, 2022

๐Ÿคจ Apple Push Notification service tutorial

๐Ÿคจ Apple Push Notification service tutorial

APNsTutorial-iOS ๐Ÿคจ Apple Push Notification service tutorial ๋‹จ์ˆœํžˆ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฐ€๋ฉด ๋  ์ค„ ์•Œ์•˜๋Š”๋ฐ ์•Œ์•„์•ผํ•  ๊ฒƒ๋„ ์žˆ์—ˆ๊ณ  ๊ฒฝ์šฐ์— ๋”ฐ๋ผ์„œ ์š”๊ตฌํ•˜๋Š” ํŒŒ์ผ๋„ ๋‹ฌ๋ž๋‹ค. ๊ทธ๋Ÿฌ๋‹ˆ ์ฒœ์ฒœํžˆ ์ฝ์–ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. ๋จผ์ € ์–ด๋–ค ์„œ๋ฒ„ ํ™˜๊ฒฝ

Dec 9, 2021

A simple and attractive AlertView to ask permission to your users for Push Notification.

A simple and attractive AlertView to ask permission to your users for Push Notification.

A simple and attractive AlertView **to ask permission to your users for Push Notification.** PRESENTATION Ask permission to user for push notification

Mar 23, 2022

Push Notification Registration for iOS

Orbiter Note: This project is no longer being maintained. For most iOS client / server applications, push notifications are negotiated through an inte

Mar 3, 2022

The debug application for Apple Push Notification Service (APNs).

The debug application for Apple Push Notification Service (APNs).

Knuff The debug application for Apple Push Notification Service (APNs). Download the latest version Features Send push notifications to APNS (Apple Pu

Jun 23, 2022

OS X and iOS application and framework to play with the Apple Push Notification service (APNs)

OS X and iOS application and framework to play with the Apple Push Notification service (APNs)

Pusher OS X and iOS application and framework to play with the Apple Push Notification service (APNs) Installation Install the Mac app using Homebrew

Jun 13, 2022
๐Ÿคจ Apple Push Notification service tutorial
๐Ÿคจ Apple Push Notification service tutorial

APNsTutorial-iOS ?? Apple Push Notification service tutorial ๋‹จ์ˆœํžˆ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฐ€๋ฉด ๋  ์ค„ ์•Œ์•˜๋Š”๋ฐ ์•Œ์•„์•ผํ•  ๊ฒƒ๋„ ์žˆ์—ˆ๊ณ  ๊ฒฝ์šฐ์— ๋”ฐ๋ผ์„œ ์š”๊ตฌํ•˜๋Š” ํŒŒ์ผ๋„ ๋‹ฌ๋ž๋‹ค. ๊ทธ๋Ÿฌ๋‹ˆ ์ฒœ์ฒœํžˆ ์ฝ์–ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. ๋จผ์ € ์–ด๋–ค ์„œ๋ฒ„ ํ™˜๊ฒฝ

Dec 9, 2021
Push Notification Registration for iOS

Orbiter Note: This project is no longer being maintained. For most iOS client / server applications, push notifications are negotiated through an inte

Mar 3, 2022
The debug application for Apple Push Notification Service (APNs).
The debug application for Apple Push Notification Service (APNs).

Knuff The debug application for Apple Push Notification Service (APNs). Download the latest version Features Send push notifications to APNS (Apple Pu

Jun 23, 2022
OS X and iOS application and framework to play with the Apple Push Notification service (APNs)
OS X and iOS application and framework to play with the Apple Push Notification service (APNs)

Pusher OS X and iOS application and framework to play with the Apple Push Notification service (APNs) Installation Install the Mac app using Homebrew

Jun 13, 2022
APNSUtil is makes code simple using apple push notification service

APNSUtil APNSUtil makes code simple settings and landing for apple push notification service. Features Using apple push notification service simply No

Mar 24, 2022
ToDoAppCoreData - MVVM + Core Data + Local Notification
ToDoAppCoreData - MVVM + Core Data + Local Notification

ToDo App Features MVVM + Core Data + Local Notification Screen recordings Creadi

Apr 22, 2022
Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS
Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS

FocusPlsNoBadges Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS, in a really gross and hacky way. Getting started Build the X

May 15, 2022
Library to send mock remote notifications to the iOS simulator
Library to send mock remote notifications to the iOS simulator

SimulatorRemoteNotifications SimulatorRemoteNotifications is a library to send mock remote notifications to the iOS simulator. The library extends UIA

May 27, 2022
Push notifications allow developers to reach users, even when users aren't actively using an app!
Push notifications allow developers to reach users, even when users aren't actively using an app!

Push notifications allow developers to reach users, even when users aren't actively using an app! With the latest update of iOS Apple provide very useful extensions which are user-friendly. In this tutorial, I am going to share the configuration, set up of Notification with the media attachments like.

Mar 3, 2022
Pushkin is a free open source tool for sending push notifications
Pushkin is a free open source tool for sending push notifications

Unmaintained This repository is no longer maintained. Pushkin Introduction Pushkin is a free open source tool for sending push notifications. It was d

Mar 13, 2022