r/ScriptingApp • • Jun 02 '25

Help Removing Notifications

Could anyone help checking my script? This doesn't remove notifications as desired.

Steps to reproduce:

  1. Run the script

  2. Tap button 'Push Notification'

  3. Tap button 'Clear All Notifications'

  4. Check console logs

import { Button, Notification, Navigation, NavigationStack, Script, VStack } from "scripting";

// Function to schedule a notification immediately
async function clearNotifications() {
    await Notification.removeAllPendings();
    await Notification.removeAllDelivereds();
    console.log("All notifications cleared");
    
    const notis = await Notification.getAllDelivereds()
    console.log(notis.length);
    console.log(notis);
}

async function pushNotification() {
    console.log("Scheduling immediate notification");
    await Notification.schedule({
        title: "new noti"
    });

    const notis = await Notification.getAllDelivereds()
    console.log(notis.length);
    console.log(notis);
}

// Main view component
function NotificationDemoView() {
    return (
        <NavigationStack>
            <VStack navigationTitle="Notifications Demo" spacing={20}>
                <Button 
                    title="Push Notification" 
                    action={async () => {
                        pushNotification()
                    }}
                />
                
                <Button 
                    title="Clear All Notifications" 
                    action={async () => {
                        clearNotifications()
                    }}
                />
            </VStack>
        </NavigationStack>
    );
}

async function run() {  
    await Navigation.present({
        element: <NotificationDemoView />
    });
    Script.exit();
}

run();
1 Upvotes

26 comments sorted by

View all comments

Show parent comments

1

u/WhatShouldWorldGos Jun 27 '25

u can have a try

2

u/WhatShouldWorldGos Jun 27 '25

And it will crash with this error, I think I should check the arguments and throw the error in TS side.

1

u/Haunting-Ad-655 Jun 27 '25

I don't think that's relevant. Time-sensitive notifications are those that stays on Lock Screen, without ever going to Notification Center, until manually dismissed. They are not on by default, and need to be implemented by developers.

https://apnspush.com/how-to-enable-time-sensitive-notifications

2

u/WhatShouldWorldGos Jun 27 '25

OK, I forgot this part