{"id":16011540,"url":"https://github.com/edusperoni/nativescript-shared-notification-delegate","last_synced_at":"2025-07-26T07:05:07.829Z","repository":{"id":48020254,"uuid":"178251637","full_name":"edusperoni/nativescript-shared-notification-delegate","owner":"edusperoni","description":null,"archived":false,"fork":false,"pushed_at":"2021-09-29T17:41:10.000Z","size":1998,"stargazers_count":2,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-18T08:19:21.882Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edusperoni.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-28T17:26:21.000Z","updated_at":"2020-02-24T14:35:38.000Z","dependencies_parsed_at":"2022-08-12T16:50:41.541Z","dependency_job_id":null,"html_url":"https://github.com/edusperoni/nativescript-shared-notification-delegate","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/edusperoni/nativescript-shared-notification-delegate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edusperoni%2Fnativescript-shared-notification-delegate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edusperoni%2Fnativescript-shared-notification-delegate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edusperoni%2Fnativescript-shared-notification-delegate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edusperoni%2Fnativescript-shared-notification-delegate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edusperoni","download_url":"https://codeload.github.com/edusperoni/nativescript-shared-notification-delegate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edusperoni%2Fnativescript-shared-notification-delegate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260985173,"owners_count":23092885,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-08T13:43:43.164Z","updated_at":"2025-06-26T02:36:09.860Z","avatar_url":"https://github.com/edusperoni.png","language":"TypeScript","readme":"# Nativescript Shared Notification Delegate\n\nThis project aims to prevent the shortcomings that come from the iOS implementation of only allowing a single delegate.\n\n## Installation\n\n```javascript\ntns plugin add nativescript-shared-notification-delegate\n```\n\n## Usage \n\nImport `SharedNotificationDelegate` and add Observers\n\t\n```typescript\nimport { SharedNotificationDelegate } from 'nativescript-shared-notification-delegate';\n\n...\n\n\nSharedNotificationDelegate.addObserver({\n    delegateUniqueKey: \"myUniqueKey\", // ensures uniqueness, if not set or is null/undefined, allows multiple of the same\n    userNotificationCenterWillPresentNotificationWithCompletionHandler: (notificationCenter, notification, handler, stop, next) =\u003e {\n        console.log(\"notification received by observer\");\n        // is this notification something I should handle?\n        if (shouldHandleThis) {\n            // do stuff\n            // intercept it and show alert\n            handler(UNNotificationPresentationOptions.Alert);\n            return;\n        }\n        // not mine, next should handle\n        next();\n    }\n});\n```\n\n## API\n\n#### SharedNotificationDelegate Methods\n| Method |  Description |\n| --- | --- |\n| addObserver(observer: `DelegateObserver`, priority?: `number`): `void` | Adds a delegate observer of a certain priority (lower means first). Default priority is 100. |\n| removeObserver(observer: `DelegateObserver`) | removes a DelegateObserver |\n| removeObserverByUniqueKey(key: `any`) | removes a DelegateObserver by its unique key |\n\n#### DelegateObserver Interface\n\nA DelegateObserver can implement 3 methods from `UNUserNotificationCenterDelegate` with the addition of some details:\n\n```typescript\ninterface DelegateObserver {\n    userNotificationCenterDidReceiveNotificationResponseWithCompletionHandler?(center: any /* UNUserNotificationCenter */, response: any /* UNNotificationResponse */, completionHandler: () =\u003e void, next: () =\u003e void): void;\n    userNotificationCenterOpenSettingsForNotification?(center: any /* UNUserNotificationCenter */, notification: any /* UNNotification */, stop: () =\u003e void, next: () =\u003e void): void;\n    userNotificationCenterWillPresentNotificationWithCompletionHandler?(center: any /* UNUserNotificationCenter */, notification: any /* UNNotification */, completionHandler: (p1: any /* UNNotificationPresentationOptions */) =\u003e void, next: () =\u003e void): void;\n    /**\n     * if set to not null/undefined, will ensure only one is registered\n     */\n    delegateUniqueKey?: any;\n}\n```\n\nAll the functions are called asynchronously in a chain.\n\nCalling a `completionHandler` immediately stops the observer chain. `next()` **must** be called if the method will not be handling the notification.\n\nCalling `stop()` on `userNotificationCenterOpenSettingsForNotification` prevents the event bubbling to the rest.\n\nOnly one method will be processed at a time, this means you can take as long as you want (including making http calls, for example), as long as you just call `completionHandler`, `stop` and `next` when you're finished.\n\nIf a DelegateObserver has a `delegateUniqueKey`, the `SharedNotificationDelegate` will ensure only the latest copy of the observer is present. This is especially useful if debugging with HMR, which may add multiple observers on application reload.\n\n    \n## License\n\nApache License Version 2.0, January 2004\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedusperoni%2Fnativescript-shared-notification-delegate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedusperoni%2Fnativescript-shared-notification-delegate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedusperoni%2Fnativescript-shared-notification-delegate/lists"}