-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.ios.js
More file actions
85 lines (70 loc) · 3.01 KB
/
index.ios.js
File metadata and controls
85 lines (70 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var frameModule = require("ui/frame");
var CustomMessageCompositeViewControllerDelegate = NSObject.extend({
// Author: Иван Бухов
// Author URL: https://github.com/ivanbuhov
// pass resolve and reject functions to the delegate instance and save them as instance properties
initWithResolveReject: function(resolve, reject) {
var self = this.super.init();
if(self) {
this.resolve = resolve;
this.reject = reject;
}
return self;
},
messageComposeViewControllerDidFinishWithResult: function(controller, result) {
controller.dismissModalViewControllerAnimated(true);
if(result == MessageComposeResultCancelled) {
console.log("Message Cancelled.");
this.resolve({
response: "canceled",
message: "User cancelled the message."
});
}
else if(result == MessageComposeResultSent) {
console.log("Message Sent.");
this.resolve({
response: "sent",
message: "Message sent."
});
}
else {
console.log("Something Failed.");
this.reject(Error("Message send failed."));
}
// release the delegate instance
CFRelease(controller.messageComposeDelegate);
}
}, {
protocols: [MFMessageComposeViewControllerDelegate]
});
function send(numbers, message, subject) {
return new Promise(function (resolve, reject) {
if(MFMessageComposeViewController.canSendText()){
var controller = MFMessageComposeViewController.alloc().init();
if(controller != null){
if(numbers && numbers.constructor === Array){
controller.recipients = numbers;
} else {
reject(Error("You must provide an array with number(s) as strings."));
}
if(message){
controller.body = message;
}
if(subject){
controller.subject = subject;
}
var delegate = CustomMessageCompositeViewControllerDelegate.alloc().initWithResolveReject(resolve, reject);
// retain the delegate because messageComposeDelegate property won't do it for us
CFRetain(delegate);
controller.messageComposeDelegate = delegate;
var page = frameModule.topmost().ios.controller;
page.presentModalViewControllerAnimated(controller, true);
}else{
reject(Error("You're not able to send SMS messages. Please check device settings."));
}
} else {
reject(Error("You're not able to send SMS messages. Please check device settings."));
}
});
}
exports.send = send;