@capawesome/capacitor-sms-composer 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/CapawesomeCapacitorSmsComposer.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +200 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/SmsComposer.java +52 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/SmsComposerPlugin.java +96 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/classes/CustomExceptions.java +9 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/classes/options/ComposeSmsOptions.java +45 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/classes/results/CanComposeSmsResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/classes/results/ComposeSmsResult.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +177 -0
- package/dist/esm/definitions.d.ts +92 -0
- package/dist/esm/definitions.js +13 -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 +6 -0
- package/dist/esm/web.js +10 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +37 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +40 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Options/ComposeSmsOptions.swift +12 -0
- package/ios/Plugin/Classes/Results/CanComposeSmsResult.swift +16 -0
- package/ios/Plugin/Classes/Results/ComposeSmsResult.swift +16 -0
- package/ios/Plugin/Enums/CustomError.swift +26 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/ios/Plugin/SmsComposer.swift +52 -0
- package/ios/Plugin/SmsComposerPlugin.swift +62 -0
- package/package.json +91 -0
package/dist/docs.json
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "SmsComposerPlugin",
|
|
4
|
+
"slug": "smscomposerplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "canComposeSms",
|
|
10
|
+
"signature": "() => Promise<CanComposeSmsResult>",
|
|
11
|
+
"parameters": [],
|
|
12
|
+
"returns": "Promise<CanComposeSmsResult>",
|
|
13
|
+
"tags": [
|
|
14
|
+
{
|
|
15
|
+
"name": "since",
|
|
16
|
+
"text": "0.1.0"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"docs": "Check whether the device is able to compose and send SMS messages.\n\nOn devices without SMS capability (e.g. Wi-Fi-only tablets or iPads),\nthis resolves with `canCompose` set to `false`.\n\nOnly available on Android and iOS.",
|
|
20
|
+
"complexTypes": [
|
|
21
|
+
"CanComposeSmsResult"
|
|
22
|
+
],
|
|
23
|
+
"slug": "cancomposesms"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "composeSms",
|
|
27
|
+
"signature": "(options: ComposeSmsOptions) => Promise<ComposeSmsResult>",
|
|
28
|
+
"parameters": [
|
|
29
|
+
{
|
|
30
|
+
"name": "options",
|
|
31
|
+
"docs": "",
|
|
32
|
+
"type": "ComposeSmsOptions"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"returns": "Promise<ComposeSmsResult>",
|
|
36
|
+
"tags": [
|
|
37
|
+
{
|
|
38
|
+
"name": "since",
|
|
39
|
+
"text": "0.1.0"
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"docs": "Open the native SMS composer prefilled with the given recipients and body.\n\nThe user reviews the message and decides whether to send it. The plugin\nnever sends the message itself.\n\nThe call resolves once the composer is dismissed. If the device is not\nable to compose SMS messages, the call rejects as unavailable.\n\nOnly available on Android and iOS.",
|
|
43
|
+
"complexTypes": [
|
|
44
|
+
"ComposeSmsResult",
|
|
45
|
+
"ComposeSmsOptions"
|
|
46
|
+
],
|
|
47
|
+
"slug": "composesms"
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"properties": []
|
|
51
|
+
},
|
|
52
|
+
"interfaces": [
|
|
53
|
+
{
|
|
54
|
+
"name": "CanComposeSmsResult",
|
|
55
|
+
"slug": "cancomposesmsresult",
|
|
56
|
+
"docs": "",
|
|
57
|
+
"tags": [
|
|
58
|
+
{
|
|
59
|
+
"text": "0.1.0",
|
|
60
|
+
"name": "since"
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"methods": [],
|
|
64
|
+
"properties": [
|
|
65
|
+
{
|
|
66
|
+
"name": "canCompose",
|
|
67
|
+
"tags": [
|
|
68
|
+
{
|
|
69
|
+
"text": "0.1.0",
|
|
70
|
+
"name": "since"
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"docs": "Whether the device is able to compose and send SMS messages.",
|
|
74
|
+
"complexTypes": [],
|
|
75
|
+
"type": "boolean"
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"name": "ComposeSmsResult",
|
|
81
|
+
"slug": "composesmsresult",
|
|
82
|
+
"docs": "",
|
|
83
|
+
"tags": [
|
|
84
|
+
{
|
|
85
|
+
"text": "0.1.0",
|
|
86
|
+
"name": "since"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"methods": [],
|
|
90
|
+
"properties": [
|
|
91
|
+
{
|
|
92
|
+
"name": "status",
|
|
93
|
+
"tags": [
|
|
94
|
+
{
|
|
95
|
+
"text": "0.1.0",
|
|
96
|
+
"name": "since"
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
"docs": "The status of the SMS composer after it was dismissed.\n\nOn Android, the status is always `unknown` because the system does not\nreport whether the message was sent.",
|
|
100
|
+
"complexTypes": [
|
|
101
|
+
"SmsComposeStatus"
|
|
102
|
+
],
|
|
103
|
+
"type": "SmsComposeStatus"
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"name": "ComposeSmsOptions",
|
|
109
|
+
"slug": "composesmsoptions",
|
|
110
|
+
"docs": "",
|
|
111
|
+
"tags": [
|
|
112
|
+
{
|
|
113
|
+
"text": "0.1.0",
|
|
114
|
+
"name": "since"
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"methods": [],
|
|
118
|
+
"properties": [
|
|
119
|
+
{
|
|
120
|
+
"name": "body",
|
|
121
|
+
"tags": [
|
|
122
|
+
{
|
|
123
|
+
"text": "'Hello from Capacitor!'",
|
|
124
|
+
"name": "example"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"text": "0.1.0",
|
|
128
|
+
"name": "since"
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
"docs": "The message body to prefill in the composer.",
|
|
132
|
+
"complexTypes": [],
|
|
133
|
+
"type": "string | undefined"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"name": "recipients",
|
|
137
|
+
"tags": [
|
|
138
|
+
{
|
|
139
|
+
"text": "['+41791234567', '+41797654321']",
|
|
140
|
+
"name": "example"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"text": "0.1.0",
|
|
144
|
+
"name": "since"
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
"docs": "The recipients (phone numbers) to prefill in the composer.",
|
|
148
|
+
"complexTypes": [],
|
|
149
|
+
"type": "string[] | undefined"
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
"enums": [],
|
|
155
|
+
"typeAliases": [
|
|
156
|
+
{
|
|
157
|
+
"name": "SmsComposeStatus",
|
|
158
|
+
"slug": "smscomposestatus",
|
|
159
|
+
"docs": "The status of the SMS composer after it was dismissed.\n\n- `sent`: The user sent the message.\n- `canceled`: The user canceled the composer without sending the message.\n- `unknown`: The result is unknown. This is always the case on Android.",
|
|
160
|
+
"types": [
|
|
161
|
+
{
|
|
162
|
+
"text": "'canceled'",
|
|
163
|
+
"complexTypes": []
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"text": "'sent'",
|
|
167
|
+
"complexTypes": []
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"text": "'unknown'",
|
|
171
|
+
"complexTypes": []
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
"pluginConfigs": []
|
|
177
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export interface SmsComposerPlugin {
|
|
2
|
+
/**
|
|
3
|
+
* Check whether the device is able to compose and send SMS messages.
|
|
4
|
+
*
|
|
5
|
+
* On devices without SMS capability (e.g. Wi-Fi-only tablets or iPads),
|
|
6
|
+
* this resolves with `canCompose` set to `false`.
|
|
7
|
+
*
|
|
8
|
+
* Only available on Android and iOS.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.1.0
|
|
11
|
+
*/
|
|
12
|
+
canComposeSms(): Promise<CanComposeSmsResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Open the native SMS composer prefilled with the given recipients and body.
|
|
15
|
+
*
|
|
16
|
+
* The user reviews the message and decides whether to send it. The plugin
|
|
17
|
+
* never sends the message itself.
|
|
18
|
+
*
|
|
19
|
+
* The call resolves once the composer is dismissed. If the device is not
|
|
20
|
+
* able to compose SMS messages, the call rejects as unavailable.
|
|
21
|
+
*
|
|
22
|
+
* Only available on Android and iOS.
|
|
23
|
+
*
|
|
24
|
+
* @since 0.1.0
|
|
25
|
+
*/
|
|
26
|
+
composeSms(options: ComposeSmsOptions): Promise<ComposeSmsResult>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @since 0.1.0
|
|
30
|
+
*/
|
|
31
|
+
export interface CanComposeSmsResult {
|
|
32
|
+
/**
|
|
33
|
+
* Whether the device is able to compose and send SMS messages.
|
|
34
|
+
*
|
|
35
|
+
* @since 0.1.0
|
|
36
|
+
*/
|
|
37
|
+
canCompose: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @since 0.1.0
|
|
41
|
+
*/
|
|
42
|
+
export interface ComposeSmsOptions {
|
|
43
|
+
/**
|
|
44
|
+
* The message body to prefill in the composer.
|
|
45
|
+
*
|
|
46
|
+
* @example 'Hello from Capacitor!'
|
|
47
|
+
* @since 0.1.0
|
|
48
|
+
*/
|
|
49
|
+
body?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The recipients (phone numbers) to prefill in the composer.
|
|
52
|
+
*
|
|
53
|
+
* @example ['+41791234567', '+41797654321']
|
|
54
|
+
* @since 0.1.0
|
|
55
|
+
*/
|
|
56
|
+
recipients?: string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @since 0.1.0
|
|
60
|
+
*/
|
|
61
|
+
export interface ComposeSmsResult {
|
|
62
|
+
/**
|
|
63
|
+
* The status of the SMS composer after it was dismissed.
|
|
64
|
+
*
|
|
65
|
+
* On Android, the status is always `unknown` because the system does not
|
|
66
|
+
* report whether the message was sent.
|
|
67
|
+
*
|
|
68
|
+
* @since 0.1.0
|
|
69
|
+
*/
|
|
70
|
+
status: SmsComposeStatus;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The status of the SMS composer after it was dismissed.
|
|
74
|
+
*
|
|
75
|
+
* - `sent`: The user sent the message.
|
|
76
|
+
* - `canceled`: The user canceled the composer without sending the message.
|
|
77
|
+
* - `unknown`: The result is unknown. This is always the case on Android.
|
|
78
|
+
*
|
|
79
|
+
* @since 0.1.0
|
|
80
|
+
*/
|
|
81
|
+
export type SmsComposeStatus = 'canceled' | 'sent' | 'unknown';
|
|
82
|
+
/**
|
|
83
|
+
* @since 0.1.0
|
|
84
|
+
*/
|
|
85
|
+
export declare enum ErrorCode {
|
|
86
|
+
/**
|
|
87
|
+
* The SMS composer failed to compose or present the message.
|
|
88
|
+
*
|
|
89
|
+
* @since 0.1.0
|
|
90
|
+
*/
|
|
91
|
+
ComposeFailed = "COMPOSE_FAILED"
|
|
92
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
export var ErrorCode;
|
|
5
|
+
(function (ErrorCode) {
|
|
6
|
+
/**
|
|
7
|
+
* The SMS composer failed to compose or present the message.
|
|
8
|
+
*
|
|
9
|
+
* @since 0.1.0
|
|
10
|
+
*/
|
|
11
|
+
ErrorCode["ComposeFailed"] = "COMPOSE_FAILED";
|
|
12
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
13
|
+
//# sourceMappingURL=definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAsFA;;GAEG;AACH,MAAM,CAAN,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB;;;;OAIG;IACH,6CAAgC,CAAA;AAClC,CAAC,EAPW,SAAS,KAAT,SAAS,QAOpB","sourcesContent":["export interface SmsComposerPlugin {\n /**\n * Check whether the device is able to compose and send SMS messages.\n *\n * On devices without SMS capability (e.g. Wi-Fi-only tablets or iPads),\n * this resolves with `canCompose` set to `false`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n canComposeSms(): Promise<CanComposeSmsResult>;\n /**\n * Open the native SMS composer prefilled with the given recipients and body.\n *\n * The user reviews the message and decides whether to send it. The plugin\n * never sends the message itself.\n *\n * The call resolves once the composer is dismissed. If the device is not\n * able to compose SMS messages, the call rejects as unavailable.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n composeSms(options: ComposeSmsOptions): Promise<ComposeSmsResult>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface CanComposeSmsResult {\n /**\n * Whether the device is able to compose and send SMS messages.\n *\n * @since 0.1.0\n */\n canCompose: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface ComposeSmsOptions {\n /**\n * The message body to prefill in the composer.\n *\n * @example 'Hello from Capacitor!'\n * @since 0.1.0\n */\n body?: string;\n /**\n * The recipients (phone numbers) to prefill in the composer.\n *\n * @example ['+41791234567', '+41797654321']\n * @since 0.1.0\n */\n recipients?: string[];\n}\n\n/**\n * @since 0.1.0\n */\nexport interface ComposeSmsResult {\n /**\n * The status of the SMS composer after it was dismissed.\n *\n * On Android, the status is always `unknown` because the system does not\n * report whether the message was sent.\n *\n * @since 0.1.0\n */\n status: SmsComposeStatus;\n}\n\n/**\n * The status of the SMS composer after it was dismissed.\n *\n * - `sent`: The user sent the message.\n * - `canceled`: The user canceled the composer without sending the message.\n * - `unknown`: The result is unknown. This is always the case on Android.\n *\n * @since 0.1.0\n */\nexport type SmsComposeStatus = 'canceled' | 'sent' | 'unknown';\n\n/**\n * @since 0.1.0\n */\nexport enum ErrorCode {\n /**\n * The SMS composer failed to compose or present the message.\n *\n * @since 0.1.0\n */\n ComposeFailed = 'COMPOSE_FAILED',\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const SmsComposer = registerPlugin('SmsComposer', {
|
|
3
|
+
web: () => import('./web').then(m => new m.SmsComposerWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { SmsComposer };
|
|
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,WAAW,GAAG,cAAc,CAAoB,aAAa,EAAE;IACnE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;CAC7D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { SmsComposerPlugin } from './definitions';\n\nconst SmsComposer = registerPlugin<SmsComposerPlugin>('SmsComposer', {\n web: () => import('./web').then(m => new m.SmsComposerWeb()),\n});\n\nexport * from './definitions';\nexport { SmsComposer };\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { CanComposeSmsResult, ComposeSmsResult, SmsComposerPlugin } from './definitions';
|
|
3
|
+
export declare class SmsComposerWeb extends WebPlugin implements SmsComposerPlugin {
|
|
4
|
+
canComposeSms(): Promise<CanComposeSmsResult>;
|
|
5
|
+
composeSms(): Promise<ComposeSmsResult>;
|
|
6
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class SmsComposerWeb extends WebPlugin {
|
|
3
|
+
async canComposeSms() {
|
|
4
|
+
throw this.unimplemented('Not implemented on web.');
|
|
5
|
+
}
|
|
6
|
+
async composeSms() {
|
|
7
|
+
throw this.unimplemented('Not implemented on web.');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAC3C,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CanComposeSmsResult,\n ComposeSmsResult,\n SmsComposerPlugin,\n} from './definitions';\n\nexport class SmsComposerWeb extends WebPlugin implements SmsComposerPlugin {\n async canComposeSms(): Promise<CanComposeSmsResult> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async composeSms(): Promise<ComposeSmsResult> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @since 0.1.0
|
|
7
|
+
*/
|
|
8
|
+
exports.ErrorCode = void 0;
|
|
9
|
+
(function (ErrorCode) {
|
|
10
|
+
/**
|
|
11
|
+
* The SMS composer failed to compose or present the message.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
*/
|
|
15
|
+
ErrorCode["ComposeFailed"] = "COMPOSE_FAILED";
|
|
16
|
+
})(exports.ErrorCode || (exports.ErrorCode = {}));
|
|
17
|
+
|
|
18
|
+
const SmsComposer = core.registerPlugin('SmsComposer', {
|
|
19
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.SmsComposerWeb()),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
class SmsComposerWeb extends core.WebPlugin {
|
|
23
|
+
async canComposeSms() {
|
|
24
|
+
throw this.unimplemented('Not implemented on web.');
|
|
25
|
+
}
|
|
26
|
+
async composeSms() {
|
|
27
|
+
throw this.unimplemented('Not implemented on web.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
32
|
+
__proto__: null,
|
|
33
|
+
SmsComposerWeb: SmsComposerWeb
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
exports.SmsComposer = SmsComposer;
|
|
37
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * The SMS composer failed to compose or present the message.\n *\n * @since 0.1.0\n */\n ErrorCode[\"ComposeFailed\"] = \"COMPOSE_FAILED\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst SmsComposer = registerPlugin('SmsComposer', {\n web: () => import('./web').then(m => new m.SmsComposerWeb()),\n});\nexport * from './definitions';\nexport { SmsComposer };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class SmsComposerWeb extends WebPlugin {\n async canComposeSms() {\n throw this.unimplemented('Not implemented on web.');\n }\n async composeSms() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACWA;AACX,CAAC,UAAU,SAAS,EAAE;AACtB;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,eAAe,CAAC,GAAG,gBAAgB;AACjD,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;ACV5B,MAAC,WAAW,GAAGC,mBAAc,CAAC,aAAa,EAAE;AAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;AAChE,CAAC;;ACFM,MAAM,cAAc,SAASC,cAAS,CAAC;AAC9C,IAAI,MAAM,aAAa,GAAG;AAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,UAAU,GAAG;AACvB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var capacitorSmsComposer = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @since 0.1.0
|
|
6
|
+
*/
|
|
7
|
+
exports.ErrorCode = void 0;
|
|
8
|
+
(function (ErrorCode) {
|
|
9
|
+
/**
|
|
10
|
+
* The SMS composer failed to compose or present the message.
|
|
11
|
+
*
|
|
12
|
+
* @since 0.1.0
|
|
13
|
+
*/
|
|
14
|
+
ErrorCode["ComposeFailed"] = "COMPOSE_FAILED";
|
|
15
|
+
})(exports.ErrorCode || (exports.ErrorCode = {}));
|
|
16
|
+
|
|
17
|
+
const SmsComposer = core.registerPlugin('SmsComposer', {
|
|
18
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.SmsComposerWeb()),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
class SmsComposerWeb extends core.WebPlugin {
|
|
22
|
+
async canComposeSms() {
|
|
23
|
+
throw this.unimplemented('Not implemented on web.');
|
|
24
|
+
}
|
|
25
|
+
async composeSms() {
|
|
26
|
+
throw this.unimplemented('Not implemented on web.');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
31
|
+
__proto__: null,
|
|
32
|
+
SmsComposerWeb: SmsComposerWeb
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
exports.SmsComposer = SmsComposer;
|
|
36
|
+
|
|
37
|
+
return exports;
|
|
38
|
+
|
|
39
|
+
})({}, capacitorExports);
|
|
40
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * The SMS composer failed to compose or present the message.\n *\n * @since 0.1.0\n */\n ErrorCode[\"ComposeFailed\"] = \"COMPOSE_FAILED\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst SmsComposer = registerPlugin('SmsComposer', {\n web: () => import('./web').then(m => new m.SmsComposerWeb()),\n});\nexport * from './definitions';\nexport { SmsComposer };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class SmsComposerWeb extends WebPlugin {\n async canComposeSms() {\n throw this.unimplemented('Not implemented on web.');\n }\n async composeSms() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;AACWA;IACX,CAAC,UAAU,SAAS,EAAE;IACtB;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,eAAe,CAAC,GAAG,gBAAgB;IACjD,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;ACV5B,UAAC,WAAW,GAAGC,mBAAc,CAAC,aAAa,EAAE;IAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;IAChE,CAAC;;ICFM,MAAM,cAAc,SAASC,cAAS,CAAC;IAC9C,IAAI,MAAM,aAAa,GAAG;IAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,UAAU,GAAG;IACvB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class ComposeSmsOptions: NSObject {
|
|
5
|
+
let body: String?
|
|
6
|
+
let recipients: [String]?
|
|
7
|
+
|
|
8
|
+
init(_ call: CAPPluginCall) throws {
|
|
9
|
+
self.recipients = call.getArray("recipients", String.self)
|
|
10
|
+
self.body = call.getString("body")
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class CanComposeSmsResult: NSObject, Result {
|
|
5
|
+
let canCompose: Bool
|
|
6
|
+
|
|
7
|
+
init(canCompose: Bool) {
|
|
8
|
+
self.canCompose = canCompose
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@objc public func toJSObject() -> AnyObject {
|
|
12
|
+
var result = JSObject()
|
|
13
|
+
result["canCompose"] = canCompose
|
|
14
|
+
return result as AnyObject
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class ComposeSmsResult: NSObject, Result {
|
|
5
|
+
let status: String
|
|
6
|
+
|
|
7
|
+
init(status: String) {
|
|
8
|
+
self.status = status
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@objc public func toJSObject() -> AnyObject {
|
|
12
|
+
var result = JSObject()
|
|
13
|
+
result["status"] = status
|
|
14
|
+
return result as AnyObject
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
public enum CustomError: Error {
|
|
4
|
+
case composeFailed
|
|
5
|
+
case viewControllerUnavailable
|
|
6
|
+
|
|
7
|
+
public var code: String? {
|
|
8
|
+
switch self {
|
|
9
|
+
case .composeFailed:
|
|
10
|
+
return "COMPOSE_FAILED"
|
|
11
|
+
case .viewControllerUnavailable:
|
|
12
|
+
return nil
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
extension CustomError: LocalizedError {
|
|
18
|
+
public var errorDescription: String? {
|
|
19
|
+
switch self {
|
|
20
|
+
case .composeFailed:
|
|
21
|
+
return NSLocalizedString("The SMS composer failed to compose or present the message.", comment: "composeFailed")
|
|
22
|
+
case .viewControllerUnavailable:
|
|
23
|
+
return NSLocalizedString("The view controller is not available.", comment: "viewControllerUnavailable")
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -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,52 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import MessageUI
|
|
4
|
+
|
|
5
|
+
@objc public class SmsComposer: NSObject, MFMessageComposeViewControllerDelegate {
|
|
6
|
+
private let plugin: SmsComposerPlugin
|
|
7
|
+
private var composeCompletion: ((ComposeSmsResult?, Error?) -> Void)?
|
|
8
|
+
|
|
9
|
+
init(plugin: SmsComposerPlugin) {
|
|
10
|
+
self.plugin = plugin
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@objc public func canComposeSms() -> Bool {
|
|
14
|
+
return MFMessageComposeViewController.canSendText()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@objc public func composeSms(_ options: ComposeSmsOptions, completion: @escaping (_ result: ComposeSmsResult?, _ error: Error?) -> Void) {
|
|
18
|
+
DispatchQueue.main.async {
|
|
19
|
+
guard let viewController = self.plugin.bridge?.viewController else {
|
|
20
|
+
completion(nil, CustomError.viewControllerUnavailable)
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
let composeViewController = MFMessageComposeViewController()
|
|
24
|
+
composeViewController.messageComposeDelegate = self
|
|
25
|
+
if let recipients = options.recipients {
|
|
26
|
+
composeViewController.recipients = recipients
|
|
27
|
+
}
|
|
28
|
+
if let body = options.body {
|
|
29
|
+
composeViewController.body = body
|
|
30
|
+
}
|
|
31
|
+
self.composeCompletion = completion
|
|
32
|
+
viewController.present(composeViewController, animated: true)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
|
|
37
|
+
controller.dismiss(animated: true) {
|
|
38
|
+
let completion = self.composeCompletion
|
|
39
|
+
self.composeCompletion = nil
|
|
40
|
+
switch result {
|
|
41
|
+
case .sent:
|
|
42
|
+
completion?(ComposeSmsResult(status: "sent"), nil)
|
|
43
|
+
case .cancelled:
|
|
44
|
+
completion?(ComposeSmsResult(status: "canceled"), nil)
|
|
45
|
+
case .failed:
|
|
46
|
+
completion?(nil, CustomError.composeFailed)
|
|
47
|
+
@unknown default:
|
|
48
|
+
completion?(nil, CustomError.composeFailed)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc(SmsComposerPlugin)
|
|
5
|
+
public class SmsComposerPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
+
public let identifier = "SmsComposerPlugin"
|
|
7
|
+
public let jsName = "SmsComposer"
|
|
8
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
9
|
+
CAPPluginMethod(name: "canComposeSms", returnType: CAPPluginReturnPromise),
|
|
10
|
+
CAPPluginMethod(name: "composeSms", returnType: CAPPluginReturnPromise)
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
public static let tag = "SmsComposerPlugin"
|
|
14
|
+
|
|
15
|
+
private var implementation: SmsComposer?
|
|
16
|
+
|
|
17
|
+
override public func load() {
|
|
18
|
+
self.implementation = SmsComposer(plugin: self)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@objc func canComposeSms(_ call: CAPPluginCall) {
|
|
22
|
+
let canCompose = implementation?.canComposeSms() ?? false
|
|
23
|
+
resolveCall(call, CanComposeSmsResult(canCompose: canCompose))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@objc func composeSms(_ call: CAPPluginCall) {
|
|
27
|
+
guard let implementation = implementation, implementation.canComposeSms() else {
|
|
28
|
+
rejectCallAsUnavailable(call)
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
do {
|
|
32
|
+
let options = try ComposeSmsOptions(call)
|
|
33
|
+
implementation.composeSms(options) { result, error in
|
|
34
|
+
if let error = error {
|
|
35
|
+
self.rejectCall(call, error)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
self.resolveCall(call, result)
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
self.rejectCall(call, error)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private func rejectCall(_ call: CAPPluginCall, _ error: Error) {
|
|
46
|
+
CAPLog.print("[", SmsComposerPlugin.tag, "] ", error)
|
|
47
|
+
let code = (error as? CustomError)?.code
|
|
48
|
+
call.reject(error.localizedDescription, code)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private func rejectCallAsUnavailable(_ call: CAPPluginCall) {
|
|
52
|
+
call.unavailable("This method is not available on this platform.")
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private func resolveCall(_ call: CAPPluginCall, _ result: Result?) {
|
|
56
|
+
if let result = result?.toJSObject() as? JSObject {
|
|
57
|
+
call.resolve(result)
|
|
58
|
+
} else {
|
|
59
|
+
call.resolve()
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|