Search code examples
iosswiftxcodeswiftuiunnotificationtrigger

how to create a custom IOS unnotificationTrigger with Swift?


I like to create a height notification trigger for my Swiftui app by subclassing UNNotificationTrigger. When I climb a mountain and reach the height of 2000 meters, I will get à notification on my apple device. Please advise me how.

i read the apple document and find no clue.


Solution

  • You cannot create your own UNNotificationTrigger subclasses. You can only use the concrete subclasses provided by iOS:

    • UNTimeIntervalNotificationTrigger
    • UNCalendarNotificationTrigger
    • UNLocationNotificationTrigger

    If you have always location permission and background location updates enabled you could, potentially, trigger a local notification when you determine that the current location is at or above your target altitude.