Skip to content

Commit

Permalink
Local Notification: schedule notification with Location
Browse files Browse the repository at this point in the history
  • Loading branch information
SajidHShanta committed Mar 4, 2023
1 parent 0542ec2 commit 60566ce
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import UserNotifications
import CoreLocation

class NotificationManager {
static let instance = NotificationManager() //singleton
Expand All @@ -30,21 +31,31 @@ class NotificationManager {
content.sound = .default
content.badge = 1

// trigger can be 3 types:
// trigger can be 3 types: time, calendar, location

// - time
// let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5.0, repeats: false)

// - calendar
var dateComponents = DateComponents()
dateComponents.hour = 0
dateComponents.minute = 18
dateComponents.weekday = 2 // every sunday 12 : 18 AM
// dateComponents.weekOfMonth
// dateComponents.weekOfYear

let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
// var dateComponents = DateComponents()
// dateComponents.hour = 0
// dateComponents.minute = 18
// dateComponents.weekday = 2 // every sunday 12 : 18 AM
//// dateComponents.weekOfMonth
//// dateComponents.weekOfYear
// let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)

// - location
let coordinate = CLLocationCoordinate2D(
latitude: 20.0,
longitude: 30.0)
let region = CLCircularRegion(
center: coordinate,
radius: 50,
identifier: UUID().uuidString)
region.notifyOnEntry = true
region.notifyOnExit = false
let trigger = UNLocationNotificationTrigger(region: region, repeats: true)

let request = UNNotificationRequest(
identifier: UUID().uuidString, // random id. because in this scenario we don't need to track
Expand Down

0 comments on commit 60566ce

Please sign in to comment.