capacitor-notificationhandler 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorNotificationhandler.podspec +17 -0
- package/README.md +64 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/push/handler/NotificationHandler.java +11 -0
- package/android/src/main/java/com/push/handler/NotificationHandlerPlugin.java +92 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +66 -0
- package/dist/esm/definitions.d.ts +9 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +9 -0
- package/dist/esm/web.js +8 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +24 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +27 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/NotificationHandler.swift +82 -0
- package/ios/Plugin/NotificationHandlerPlugin.h +10 -0
- package/ios/Plugin/NotificationHandlerPlugin.m +8 -0
- package/ios/Plugin/NotificationHandlerPlugin.swift +27 -0
- package/package.json +78 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
4
|
+
|
5
|
+
Pod::Spec.new do |s|
|
6
|
+
s.name = 'CapacitorNotificationhandler'
|
7
|
+
s.version = package['version']
|
8
|
+
s.summary = package['description']
|
9
|
+
s.license = package['license']
|
10
|
+
s.homepage = package['repository']['url']
|
11
|
+
s.author = package['author']
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
14
|
+
s.ios.deployment_target = '13.0'
|
15
|
+
s.dependency 'Capacitor'
|
16
|
+
s.swift_version = '5.1'
|
17
|
+
end
|
package/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# capacitor-notificationhandler
|
2
|
+
|
3
|
+
Push notification Handler
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
```bash
|
8
|
+
npm install capacitor-notificationhandler
|
9
|
+
npx cap sync
|
10
|
+
```
|
11
|
+
|
12
|
+
## API
|
13
|
+
|
14
|
+
<docgen-index>
|
15
|
+
|
16
|
+
* [`echo(...)`](#echo)
|
17
|
+
* [`addListener([eventName: 'pushNotificationActionPerformed', listenerFunc: (info: any) => void], ...)`](#addlistenereventname-pushnotificationactionperformed-listenerfunc-info-any--void)
|
18
|
+
* [Interfaces](#interfaces)
|
19
|
+
|
20
|
+
</docgen-index>
|
21
|
+
|
22
|
+
<docgen-api>
|
23
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
24
|
+
|
25
|
+
### echo(...)
|
26
|
+
|
27
|
+
```typescript
|
28
|
+
echo(options: { value: string; }) => Promise<{ value: string; }>
|
29
|
+
```
|
30
|
+
|
31
|
+
| Param | Type |
|
32
|
+
| ------------- | ------------------------------- |
|
33
|
+
| **`options`** | <code>{ value: string; }</code> |
|
34
|
+
|
35
|
+
**Returns:** <code>Promise<{ value: string; }></code>
|
36
|
+
|
37
|
+
--------------------
|
38
|
+
|
39
|
+
|
40
|
+
### addListener([eventName: 'pushNotificationActionPerformed', listenerFunc: (info: any) => void], ...)
|
41
|
+
|
42
|
+
```typescript
|
43
|
+
addListener(eventName: "pushNotificationActionPerformed", listenerFunc: (info: any) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
|
44
|
+
```
|
45
|
+
|
46
|
+
| Param | Type |
|
47
|
+
| ---------- | ------------------------------------------------------------------------------------------------- |
|
48
|
+
| **`args`** | <code>[eventName: 'pushNotificationActionPerformed', listenerFunc: (info: any) => void]</code> |
|
49
|
+
|
50
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>> & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
|
51
|
+
|
52
|
+
--------------------
|
53
|
+
|
54
|
+
|
55
|
+
### Interfaces
|
56
|
+
|
57
|
+
|
58
|
+
#### PluginListenerHandle
|
59
|
+
|
60
|
+
| Prop | Type |
|
61
|
+
| ------------ | ----------------------------------------- |
|
62
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
63
|
+
|
64
|
+
</docgen-api>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
ext {
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
6
|
+
}
|
7
|
+
|
8
|
+
buildscript {
|
9
|
+
repositories {
|
10
|
+
google()
|
11
|
+
mavenCentral()
|
12
|
+
}
|
13
|
+
dependencies {
|
14
|
+
classpath 'com.android.tools.build:gradle:8.0.0'
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
apply plugin: 'com.android.library'
|
19
|
+
|
20
|
+
android {
|
21
|
+
namespace "com.push.handler"
|
22
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
|
23
|
+
defaultConfig {
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
|
26
|
+
versionCode 1
|
27
|
+
versionName "1.0"
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
29
|
+
}
|
30
|
+
buildTypes {
|
31
|
+
release {
|
32
|
+
minifyEnabled false
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
34
|
+
}
|
35
|
+
}
|
36
|
+
lintOptions {
|
37
|
+
abortOnError false
|
38
|
+
}
|
39
|
+
compileOptions {
|
40
|
+
sourceCompatibility JavaVersion.VERSION_17
|
41
|
+
targetCompatibility JavaVersion.VERSION_17
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
repositories {
|
46
|
+
google()
|
47
|
+
mavenCentral()
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
dependencies {
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
53
|
+
implementation project(':capacitor-android')
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
58
|
+
}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
package com.push.handler;
|
2
|
+
|
3
|
+
import com.getcapacitor.JSObject;
|
4
|
+
import com.getcapacitor.Plugin;
|
5
|
+
import com.getcapacitor.PluginCall;
|
6
|
+
import com.getcapacitor.PluginMethod;
|
7
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
8
|
+
import android.app.NotificationManager;
|
9
|
+
|
10
|
+
import android.content.Context;
|
11
|
+
import android.content.Intent;
|
12
|
+
import android.content.pm.ApplicationInfo;
|
13
|
+
import android.content.pm.PackageManager;
|
14
|
+
import android.os.Build;
|
15
|
+
import android.os.Bundle;
|
16
|
+
import com.getcapacitor.*;
|
17
|
+
import com.getcapacitor.annotation.PermissionCallback;
|
18
|
+
@CapacitorPlugin(name = "NotificationHandler")
|
19
|
+
public class NotificationHandlerPlugin extends Plugin {
|
20
|
+
static final String PUSH_NOTIFICATIONS = "receive";
|
21
|
+
|
22
|
+
private NotificationHandler implementation = new NotificationHandler();
|
23
|
+
public NotificationManager notificationManager;
|
24
|
+
|
25
|
+
@PluginMethod
|
26
|
+
public void echo(PluginCall call) {
|
27
|
+
String value = call.getString("value");
|
28
|
+
|
29
|
+
JSObject ret = new JSObject();
|
30
|
+
ret.put("value", implementation.echo(value));
|
31
|
+
call.resolve(ret);
|
32
|
+
}
|
33
|
+
public void load() {
|
34
|
+
notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
|
35
|
+
|
36
|
+
}
|
37
|
+
@Override
|
38
|
+
protected void handleOnNewIntent(Intent data) {
|
39
|
+
super.handleOnNewIntent(data);
|
40
|
+
Bundle bundle = data.getExtras();
|
41
|
+
if (bundle != null && bundle.containsKey("PUSH_RECEIVE_EVENT")) {
|
42
|
+
JSObject notificationJson = new JSObject();
|
43
|
+
notificationJson.put("PushObject", bundle.getString("PUSH_RECEIVE_EVENT"));
|
44
|
+
notifyListeners("pushNotificationActionPerformed", notificationJson, true);
|
45
|
+
|
46
|
+
|
47
|
+
//notificationJson.put("data", dataObject);
|
48
|
+
// JSObject actionJson = new JSObject();
|
49
|
+
// actionJson.put("actionId", "tap");
|
50
|
+
// actionJson.put("notification", notificationJson);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
@PluginMethod
|
55
|
+
public void checkPermissions(PluginCall call) {
|
56
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
57
|
+
JSObject permissionsResultJSON = new JSObject();
|
58
|
+
permissionsResultJSON.put("receive", "granted");
|
59
|
+
call.resolve(permissionsResultJSON);
|
60
|
+
} else {
|
61
|
+
super.checkPermissions(call);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
@PluginMethod
|
66
|
+
public void requestPermissions(PluginCall call) {
|
67
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || getPermissionState(PUSH_NOTIFICATIONS) == PermissionState.GRANTED) {
|
68
|
+
JSObject permissionsResultJSON = new JSObject();
|
69
|
+
permissionsResultJSON.put("receive", "granted");
|
70
|
+
call.resolve(permissionsResultJSON);
|
71
|
+
} else {
|
72
|
+
requestPermissionForAlias(PUSH_NOTIFICATIONS, call, "permissionsCallback");
|
73
|
+
}
|
74
|
+
}
|
75
|
+
@PermissionCallback
|
76
|
+
private void permissionsCallback(PluginCall call) {
|
77
|
+
this.checkPermissions(call);
|
78
|
+
}
|
79
|
+
|
80
|
+
@SuppressWarnings("deprecation")
|
81
|
+
private Bundle getBundleLegacy() {
|
82
|
+
try {
|
83
|
+
ApplicationInfo applicationInfo = getContext()
|
84
|
+
.getPackageManager()
|
85
|
+
.getApplicationInfo(getContext().getPackageName(), PackageManager.GET_META_DATA);
|
86
|
+
return applicationInfo.metaData;
|
87
|
+
} catch (PackageManager.NameNotFoundException e) {
|
88
|
+
e.printStackTrace();
|
89
|
+
return null;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
File without changes
|
package/dist/docs.json
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
{
|
2
|
+
"api": {
|
3
|
+
"name": "NotificationHandlerPlugin",
|
4
|
+
"slug": "notificationhandlerplugin",
|
5
|
+
"docs": "",
|
6
|
+
"tags": [],
|
7
|
+
"methods": [
|
8
|
+
{
|
9
|
+
"name": "echo",
|
10
|
+
"signature": "(options: { value: string; }) => Promise<{ value: string; }>",
|
11
|
+
"parameters": [
|
12
|
+
{
|
13
|
+
"name": "options",
|
14
|
+
"docs": "",
|
15
|
+
"type": "{ value: string; }"
|
16
|
+
}
|
17
|
+
],
|
18
|
+
"returns": "Promise<{ value: string; }>",
|
19
|
+
"tags": [],
|
20
|
+
"docs": "",
|
21
|
+
"complexTypes": [],
|
22
|
+
"slug": "echo"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"name": "addListener",
|
26
|
+
"signature": "(eventName: \"pushNotificationActionPerformed\", listenerFunc: (info: any) => void) => Promise<PluginListenerHandle> & PluginListenerHandle",
|
27
|
+
"parameters": [
|
28
|
+
{
|
29
|
+
"name": "args",
|
30
|
+
"docs": "",
|
31
|
+
"type": "[eventName: 'pushNotificationActionPerformed', listenerFunc: (info: any) => void]"
|
32
|
+
}
|
33
|
+
],
|
34
|
+
"returns": "Promise<PluginListenerHandle> & PluginListenerHandle",
|
35
|
+
"tags": [],
|
36
|
+
"docs": "",
|
37
|
+
"complexTypes": [
|
38
|
+
"PluginListenerHandle"
|
39
|
+
],
|
40
|
+
"slug": "addlistenereventname-pushnotificationactionperformed-listenerfunc-info-any--void"
|
41
|
+
}
|
42
|
+
],
|
43
|
+
"properties": []
|
44
|
+
},
|
45
|
+
"interfaces": [
|
46
|
+
{
|
47
|
+
"name": "PluginListenerHandle",
|
48
|
+
"slug": "pluginlistenerhandle",
|
49
|
+
"docs": "",
|
50
|
+
"tags": [],
|
51
|
+
"methods": [],
|
52
|
+
"properties": [
|
53
|
+
{
|
54
|
+
"name": "remove",
|
55
|
+
"tags": [],
|
56
|
+
"docs": "",
|
57
|
+
"complexTypes": [],
|
58
|
+
"type": "() => Promise<void>"
|
59
|
+
}
|
60
|
+
]
|
61
|
+
}
|
62
|
+
],
|
63
|
+
"enums": [],
|
64
|
+
"typeAliases": [],
|
65
|
+
"pluginConfigs": []
|
66
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { PluginListenerHandle } from "@capacitor/core";
|
2
|
+
export interface NotificationHandlerPlugin {
|
3
|
+
echo(options: {
|
4
|
+
value: string;
|
5
|
+
}): Promise<{
|
6
|
+
value: string;
|
7
|
+
}>;
|
8
|
+
addListener(...args: [eventName: 'pushNotificationActionPerformed', listenerFunc: (info: any) => void]): Promise<PluginListenerHandle> & PluginListenerHandle;
|
9
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import { PluginListenerHandle } from \"@capacitor/core\";\n\nexport interface NotificationHandlerPlugin {\n echo(options: { value: string }): Promise<{ value: string }>;\n addListener(...args: [eventName: 'pushNotificationActionPerformed', listenerFunc: (info: any) => void]): Promise<PluginListenerHandle> & PluginListenerHandle;\n\n}\n"]}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
2
|
+
const NotificationHandler = registerPlugin('NotificationHandler', {
|
3
|
+
web: () => import('./web').then(m => new m.NotificationHandlerWeb()),
|
4
|
+
});
|
5
|
+
export * from './definitions';
|
6
|
+
export { NotificationHandler };
|
7
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,mBAAmB,GAAG,cAAc,CACxC,qBAAqB,EACrB;IACE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,sBAAsB,EAAE,CAAC;CACrE,CACF,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { NotificationHandlerPlugin } from './definitions';\n\nconst NotificationHandler = registerPlugin<NotificationHandlerPlugin>(\n 'NotificationHandler',\n {\n web: () => import('./web').then(m => new m.NotificationHandlerWeb()),\n },\n);\n\nexport * from './definitions';\nexport { NotificationHandler };\n"]}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
2
|
+
import type { NotificationHandlerPlugin } from './definitions';
|
3
|
+
export declare class NotificationHandlerWeb extends WebPlugin implements NotificationHandlerPlugin {
|
4
|
+
echo(options: {
|
5
|
+
value: string;
|
6
|
+
}): Promise<{
|
7
|
+
value: string;
|
8
|
+
}>;
|
9
|
+
}
|
package/dist/esm/web.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,sBACX,SAAQ,SAAS;IAGjB,KAAK,CAAC,IAAI,CAAC,OAA0B;QACnC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { NotificationHandlerPlugin } from './definitions';\n\nexport class NotificationHandlerWeb\n extends WebPlugin\n implements NotificationHandlerPlugin\n{\n async echo(options: { value: string }): Promise<{ value: string }> {\n console.log('ECHO', options);\n return options;\n }\n}\n"]}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
var core = require('@capacitor/core');
|
6
|
+
|
7
|
+
const NotificationHandler = core.registerPlugin('NotificationHandler', {
|
8
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.NotificationHandlerWeb()),
|
9
|
+
});
|
10
|
+
|
11
|
+
class NotificationHandlerWeb extends core.WebPlugin {
|
12
|
+
async echo(options) {
|
13
|
+
console.log('ECHO', options);
|
14
|
+
return options;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
var web = /*#__PURE__*/Object.freeze({
|
19
|
+
__proto__: null,
|
20
|
+
NotificationHandlerWeb: NotificationHandlerWeb
|
21
|
+
});
|
22
|
+
|
23
|
+
exports.NotificationHandler = NotificationHandler;
|
24
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst NotificationHandler = registerPlugin('NotificationHandler', {\n web: () => import('./web').then(m => new m.NotificationHandlerWeb()),\n});\nexport * from './definitions';\nexport { NotificationHandler };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class NotificationHandlerWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,mBAAmB,GAAGA,mBAAc,CAAC,qBAAqB,EAAE;AAClE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,sBAAsB,EAAE,CAAC;AACxE,CAAC;;ACFM,MAAM,sBAAsB,SAASC,cAAS,CAAC;AACtD,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACrC,QAAQ,OAAO,OAAO,CAAC;AACvB,KAAK;AACL;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
var capacitorNotificationHandler = (function (exports, core) {
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
const NotificationHandler = core.registerPlugin('NotificationHandler', {
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.NotificationHandlerWeb()),
|
6
|
+
});
|
7
|
+
|
8
|
+
class NotificationHandlerWeb extends core.WebPlugin {
|
9
|
+
async echo(options) {
|
10
|
+
console.log('ECHO', options);
|
11
|
+
return options;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
var web = /*#__PURE__*/Object.freeze({
|
16
|
+
__proto__: null,
|
17
|
+
NotificationHandlerWeb: NotificationHandlerWeb
|
18
|
+
});
|
19
|
+
|
20
|
+
exports.NotificationHandler = NotificationHandler;
|
21
|
+
|
22
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
23
|
+
|
24
|
+
return exports;
|
25
|
+
|
26
|
+
})({}, capacitorExports);
|
27
|
+
//# sourceMappingURL=plugin.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst NotificationHandler = registerPlugin('NotificationHandler', {\n web: () => import('./web').then(m => new m.NotificationHandlerWeb()),\n});\nexport * from './definitions';\nexport { NotificationHandler };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class NotificationHandlerWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,mBAAmB,GAAGA,mBAAc,CAAC,qBAAqB,EAAE;IAClE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,sBAAsB,EAAE,CAAC;IACxE,CAAC;;ICFM,MAAM,sBAAsB,SAASC,cAAS,CAAC;IACtD,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,QAAQ,OAAO,OAAO,CAAC;IACvB,KAAK;IACL;;;;;;;;;;;;;;;;;"}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
7
|
+
<key>CFBundleExecutable</key>
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
9
|
+
<key>CFBundleIdentifier</key>
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
12
|
+
<string>6.0</string>
|
13
|
+
<key>CFBundleName</key>
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
15
|
+
<key>CFBundlePackageType</key>
|
16
|
+
<string>FMWK</string>
|
17
|
+
<key>CFBundleShortVersionString</key>
|
18
|
+
<string>1.0</string>
|
19
|
+
<key>CFBundleVersion</key>
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
21
|
+
<key>NSPrincipalClass</key>
|
22
|
+
<string></string>
|
23
|
+
</dict>
|
24
|
+
</plist>
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import Capacitor
|
2
|
+
import UserNotifications
|
3
|
+
|
4
|
+
@objc public class NotificationHandler: NSObject,NotificationHandlerProtocol {
|
5
|
+
public weak var plugin: CAPPlugin?
|
6
|
+
var notificationRequestLookup = [String: JSObject]()
|
7
|
+
|
8
|
+
public func willPresent(notification: UNNotification) -> UNNotificationPresentationOptions {
|
9
|
+
let notificationData = makeNotificationRequestJSObject(notification.request)
|
10
|
+
self.plugin?.notifyListeners("pushNotificationReceived", data: notificationData)
|
11
|
+
|
12
|
+
if let options = notificationRequestLookup[notification.request.identifier] {
|
13
|
+
let silent = options["silent"] as? Bool ?? false
|
14
|
+
|
15
|
+
if silent {
|
16
|
+
return UNNotificationPresentationOptions.init(rawValue: 0)
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
if let optionsArray = self.plugin?.getConfig().getArray("presentationOptions") as? [String] {
|
21
|
+
var presentationOptions = UNNotificationPresentationOptions.init()
|
22
|
+
|
23
|
+
optionsArray.forEach { option in
|
24
|
+
switch option {
|
25
|
+
case "alert":
|
26
|
+
presentationOptions.insert(.alert)
|
27
|
+
case "badge":
|
28
|
+
presentationOptions.insert(.badge)
|
29
|
+
|
30
|
+
case "sound":
|
31
|
+
presentationOptions.insert(.sound)
|
32
|
+
default:
|
33
|
+
print("Unrecogizned presentation option: \(option)")
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
return presentationOptions
|
38
|
+
}
|
39
|
+
|
40
|
+
return []
|
41
|
+
}
|
42
|
+
|
43
|
+
public func didReceive(response: UNNotificationResponse) {
|
44
|
+
var data = JSObject()
|
45
|
+
|
46
|
+
let originalNotificationRequest = response.notification.request
|
47
|
+
let actionId = response.actionIdentifier
|
48
|
+
|
49
|
+
if actionId == UNNotificationDefaultActionIdentifier {
|
50
|
+
data["actionId"] = "tap"
|
51
|
+
} else if actionId == UNNotificationDismissActionIdentifier {
|
52
|
+
data["actionId"] = "dismiss"
|
53
|
+
} else {
|
54
|
+
data["actionId"] = actionId
|
55
|
+
}
|
56
|
+
|
57
|
+
if let inputType = response as? UNTextInputNotificationResponse {
|
58
|
+
data["inputValue"] = inputType.userText
|
59
|
+
}
|
60
|
+
|
61
|
+
data["notification"] = makeNotificationRequestJSObject(originalNotificationRequest)
|
62
|
+
|
63
|
+
self.plugin?.notifyListeners("pushNotificationActionPerformed", data: data, retainUntilConsumed: true)
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
func makeNotificationRequestJSObject(_ request: UNNotificationRequest) -> JSObject {
|
68
|
+
return [
|
69
|
+
"id": request.identifier,
|
70
|
+
"title": request.content.title,
|
71
|
+
"subtitle": request.content.subtitle,
|
72
|
+
"badge": request.content.badge ?? 1,
|
73
|
+
"body": request.content.body,
|
74
|
+
"data": JSTypes.coerceDictionaryToJSObject(request.content.userInfo) ?? [:]
|
75
|
+
]
|
76
|
+
}
|
77
|
+
|
78
|
+
@objc public func echo(_ value: String) -> String {
|
79
|
+
print(value)
|
80
|
+
return value
|
81
|
+
}
|
82
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#import <UIKit/UIKit.h>
|
2
|
+
|
3
|
+
//! Project version number for Plugin.
|
4
|
+
FOUNDATION_EXPORT double PluginVersionNumber;
|
5
|
+
|
6
|
+
//! Project version string for Plugin.
|
7
|
+
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
8
|
+
|
9
|
+
// In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
|
10
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
#import <Foundation/Foundation.h>
|
2
|
+
#import <Capacitor/Capacitor.h>
|
3
|
+
|
4
|
+
// Define the plugin using the CAP_PLUGIN Macro, and
|
5
|
+
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
6
|
+
CAP_PLUGIN(NotificationHandlerPlugin, "NotificationHandler",
|
7
|
+
CAP_PLUGIN_METHOD(echo, CAPPluginReturnPromise);
|
8
|
+
)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import Foundation
|
2
|
+
import Capacitor
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
6
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
7
|
+
*/
|
8
|
+
@objc(NotificationHandlerPlugin)
|
9
|
+
public class NotificationHandlerPlugin: CAPPlugin {
|
10
|
+
private let notificationDelegateHandler = NotificationHandler()
|
11
|
+
private var appDelegateRegistrationCalled: Bool = false
|
12
|
+
|
13
|
+
override public func load() {
|
14
|
+
self.bridge?.notificationRouter.pushNotificationHandler = self.notificationDelegateHandler
|
15
|
+
self.notificationDelegateHandler.plugin = self
|
16
|
+
}
|
17
|
+
|
18
|
+
deinit {
|
19
|
+
NotificationCenter.default.removeObserver(self)
|
20
|
+
}
|
21
|
+
@objc func echo(_ call: CAPPluginCall) {
|
22
|
+
let value = call.getString("value") ?? ""
|
23
|
+
call.resolve([
|
24
|
+
"value": notificationDelegateHandler.echo(value)
|
25
|
+
])
|
26
|
+
}
|
27
|
+
}
|
package/package.json
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
{
|
2
|
+
"name": "capacitor-notificationhandler",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "Push notification Handler",
|
5
|
+
"main": "dist/plugin.cjs.js",
|
6
|
+
"module": "dist/esm/index.js",
|
7
|
+
"types": "dist/esm/index.d.ts",
|
8
|
+
"unpkg": "dist/plugin.js",
|
9
|
+
"files": [
|
10
|
+
"android/src/main/",
|
11
|
+
"android/build.gradle",
|
12
|
+
"dist/",
|
13
|
+
"ios/Plugin/",
|
14
|
+
"CapacitorNotificationhandler.podspec"
|
15
|
+
],
|
16
|
+
"author": "",
|
17
|
+
"license": "MIT",
|
18
|
+
"repository": {
|
19
|
+
"type": "git",
|
20
|
+
"url": "git+https://github.com/vamsi3293/capacitor-NotificationHandler.git.git"
|
21
|
+
},
|
22
|
+
"bugs": {
|
23
|
+
"url": "https://github.com/vamsi3293/capacitor-NotificationHandler.git/issues"
|
24
|
+
},
|
25
|
+
"keywords": [
|
26
|
+
"capacitor",
|
27
|
+
"plugin",
|
28
|
+
"native"
|
29
|
+
],
|
30
|
+
"scripts": {
|
31
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
32
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
33
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
34
|
+
"verify:web": "npm run build",
|
35
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
36
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
37
|
+
"eslint": "eslint . --ext ts",
|
38
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
39
|
+
"swiftlint": "node-swiftlint",
|
40
|
+
"docgen": "docgen --api NotificationHandlerPlugin --output-readme README.md --output-json dist/docs.json",
|
41
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
|
42
|
+
"clean": "rimraf ./dist",
|
43
|
+
"watch": "tsc --watch",
|
44
|
+
"prepublishOnly": "npm run build"
|
45
|
+
},
|
46
|
+
"devDependencies": {
|
47
|
+
"@capacitor/android": "^5.0.0",
|
48
|
+
"@capacitor/core": "^5.0.0",
|
49
|
+
"@capacitor/docgen": "^0.0.18",
|
50
|
+
"@capacitor/ios": "^5.0.0",
|
51
|
+
"@ionic/eslint-config": "^0.3.0",
|
52
|
+
"@ionic/prettier-config": "^1.0.1",
|
53
|
+
"@ionic/swiftlint-config": "^1.1.2",
|
54
|
+
"eslint": "^7.11.0",
|
55
|
+
"prettier": "~2.3.0",
|
56
|
+
"prettier-plugin-java": "~1.0.2",
|
57
|
+
"rimraf": "^3.0.2",
|
58
|
+
"rollup": "^2.32.0",
|
59
|
+
"swiftlint": "^1.0.1",
|
60
|
+
"typescript": "~4.1.5"
|
61
|
+
},
|
62
|
+
"peerDependencies": {
|
63
|
+
"@capacitor/core": "^5.0.0"
|
64
|
+
},
|
65
|
+
"prettier": "@ionic/prettier-config",
|
66
|
+
"swiftlint": "@ionic/swiftlint-config",
|
67
|
+
"eslintConfig": {
|
68
|
+
"extends": "@ionic/eslint-config/recommended"
|
69
|
+
},
|
70
|
+
"capacitor": {
|
71
|
+
"ios": {
|
72
|
+
"src": "ios"
|
73
|
+
},
|
74
|
+
"android": {
|
75
|
+
"src": "android"
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|