@@ -78,15 +78,10 @@ <h2>Introduction</h2>
78
78
An example of use is provided below:
79
79
80
80
< pre class ="example highlight ">
81
- var req = navigator.messaging.sms.send (
82
- '+1234567890', 'How are you?');
83
-
84
- req.onsuccess = function() {
85
- window.console.log('Message Sent!');
86
- }
87
- req.onerror = function(e) {
88
- window.console.error(e.target.error.name);
89
- }
81
+ navigator.messaging.sms.send ( '+1234567890', 'How are you?').done(
82
+ function(message) { window.console.log('Message with identifier ' +
83
+ message.messageID + ' sent at ' + message.timestamp); },
84
+ function(error) { window.console.error('Error: ' + error); } )
90
85
</ pre >
91
86
</ section >
92
87
@@ -1150,18 +1145,18 @@ <h3>Steps</h3>
1150
1145
An example of manual fetch of an MMS is provided below:
1151
1146
1152
1147
< pre class ="example highlight ">
1153
- var message = receivedMessageEvent.message
1154
- if (message.state == 'not-downloaded' ) {
1155
- var req = navigator.messaging.mms.fetch (message.id)
1156
- req.onprogress = function() {
1157
- window.console.log(e.loaded + ' bytes out of ' + e.total + '
1158
- downloaded ... ');
1159
- }
1160
- req.onsuccess = function() {
1161
- window.console.log('Message Fetched!');
1162
- }
1163
- req.onerror = function(e) {
1164
- window.console.error(e.target.error.name);
1148
+ navigator.setMessageHandler ('received', onMessageReceived)
1149
+ function onMessageReceived (message) {
1150
+ if (message.type == 'sms') { window.console.log('SMS Message from ' +
1151
+ message.from + ' received'); }
1152
+ else if (message.type == 'mms') {
1153
+ window.console.log('MMS Message from ' + message.from + ' received ');
1154
+ if (message.state == 'not-downloaded') {
1155
+ window.console.log('MMS Message download started');
1156
+ navigator.messaging.mms.fetch (message.id).done(
1157
+ function(message) { window.console.log('MMS Message downloaded!');},
1158
+ function(error) { window.console.error('Error: ' + error);} );
1159
+ }
1165
1160
}
1166
1161
}
1167
1162
</ pre >
0 commit comments