Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Time-Sensitive notifications on iOS 15 #659

Open
anagstef opened this issue Oct 15, 2021 · 5 comments · May be fixed by #1293
Open

Support for Time-Sensitive notifications on iOS 15 #659

anagstef opened this issue Oct 15, 2021 · 5 comments · May be fixed by #1293

Comments

@anagstef
Copy link

Feature Request

Plugin

Local Notifications

Description

Support for Time-Sensitive notifications on iOS 15+. Time-Sensitive notifications allow the developer to schedule notifications that are important to bypass the Focus active mode or the system Do not disturb settings.

Platform(s)

iOS (15.0+)

Preferred Solution

We should add the new variable interruptionLevel inside the UNMutableNotificationContent. The interruptionLevel variable is an enum with the following values:

case passive = 0
The system adds the notification to the notification list without lighting up the screen or playing a sound.

case active = 1
The system presents the notification immediately, lights up the screen, and can play a sound.

case timeSensitive = 2
The system presents the notification immediately, lights up the screen, and can play a sound, but won’t break through system notification controls.

case critical = 3
The system presents the notification immediately, lights up the screen, and bypasses the mute switch to play a sound.

Maybe add an interface to be exported through capacitor so that developer can get these allowed values.

Also, developer must enable the correct value in App.entitlements for this to work:

<key>com.apple.developer.usernotifications.time-sensitive</key>
<true/>

The above should be added to the documentation too.

Additional Context

Overview:
https://developer.apple.com/videos/play/wwdc2021/10091/

Relevant apple docs:
https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent
https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent/3747253-interruptionlevel
https://developer.apple.com/documentation/usernotifications/unnotificationinterruptionlevel

@mickjol
Copy link

mickjol commented Aug 28, 2023

When implementing ".criticalAlert" the ".provisional" authorization should be implemented at the same time.

@davidemerritt
Copy link

+1 - really need this 👍

@davidemerritt
Copy link

Any update on when this might be implemented?

@DercilioFontes
Copy link

I was looking for that!

@DercilioFontes
Copy link

I got a solution to use iOS Critical Alerts. This is more related to issue #1759, which was closed and referenced to this issue.

Note: Your app needs Apple Critical Alerts entitlement to have the critical alerts working.
https://medium.com/@shashidharyamsani/implementing-ios-critical-alerts-7d82b4bb5026

iOS Critical Alerts

  1. Install lastest @capacitor/push-notifications and @capacitor/local-notifications
  2. Copy them from node_modules/@capacitor to custom-plugins/@capacitor
  3. Update files:
    • custom-plugins/@capacitor/push-notifications/ios/Plugin/PushNotificationsHandler.swift
    • custom-plugins/@capacitor/local-notifications/ios/Plugin/LocalNotificationsHandler.swift
    • Add .criticalAlert to requestAuthorization options
   ...

    public func requestPermissions(with completion: ((Bool, Error?) -> Void)? = nil) {                  ⬇️
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge, .criticalAlert]) { granted, error in
            completion?(granted, error)
        }
    }
    ...
  1. "Pack" the plugins to a .tgz file in the custom-plugins folder

    1. local-notifications
      • cd custom-plugins/@capacitor/local-notifications
      • npm pack --pack-destination ../../
    2. push-notifications
    • cd custom-plugins/@capacitor/push-notifications
    • npm pack --pack-destination ../../
  2. Install the new packages. Update to the lastes version.

  • npm install ./custom-plugins/capacitor-push-notifications-5.1.0.tgz
  • npm install ./custom-plugins/capacitor-local-notifications-5.0.6.tgz

And you can git ignore the custom-plugins code, but the the new custom packages.

# iOS Critical Alerts
custom-plugins/*
!custom-plugins/capacitor-local-notifications-5.0.6.tgz
!custom-plugins/capacitor-push-notifications-5.1.0.tgz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants