1# 电话子系统ChangeLog 2 3 4 5## cl.telephony.1 sms模块接口变更 6 7sendMessage接口作废弃处理,变更为sendShortMessage接口。 8 9**变更影响** 10 11从API version 10开始,sendMessage接口废弃。应用需要自行适配为sendShortMessage。接口功能不变。 12 13**关键的接口/组件变更** 14 15修改前的接口原型: 16 17```js 18function sendMessage(options: SendMessageOptions): void; 19``` 20 21修改后的接口原型: 22 23```js 24function sendShortMessage(options: SendMessageOptions, callback: AsyncCallback<void>): void; 25function sendShortMessage(options: SendMessageOptions): Promise<void>; 26``` 27 28 29 30**适配指导** 31 32使用变更后的接口,示例代码如下: 33 34```js 35let sendCallback = function (err, data) { 36 console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 37} 38let deliveryCallback = function (err, data) { 39 console.log(`deliveryCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 40} 41let slotId = 0; 42let content = '短信内容'; 43let destinationHost = '+861xxxxxxxxxx'; 44let serviceCenter = '+861xxxxxxxxxx'; 45let destinationPort = 1000; 46let options = {slotId, content, destinationHost, serviceCenter, destinationPort, sendCallback, deliveryCallback}; 47sms.sendShortMessage(options, (err) => { 48 console.log(`callback: err->${JSON.stringify(err)}`); 49}); 50``` 51 52```js 53let sendCallback = function (err, data) { 54 console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 55} 56let deliveryCallback = function (err, data) { 57 console.log(`deliveryCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 58} 59let slotId = 0; 60let content = '短信内容'; 61let destinationHost = '+861xxxxxxxxxx'; 62let serviceCenter = '+861xxxxxxxxxx'; 63let destinationPort = 1000; 64let options = {slotId, content, destinationHost, serviceCenter, destinationPort, sendCallback, deliveryCallback}; 65let promise = sms.sendShortMessage(options); 66promise.then(() => { 67 console.log(`sendShortMessage success`); 68}).catch(err => { 69 console.error(`sendShortMessage failed, promise: err->${JSON.stringify(err)}`); 70}); 71 72``` 73 74## cl.telephony.2 sim模块接口变更 75 76getSimTelephoneNumber接口权限变更,由ohos.permission.GET_TELEPHONY_STATE变更为ohos.permission.GET_PHONE_NUMBERS。 77 78**变更影响** 79 80从API version 10开始,getSimTelephoneNumber接口权限变更为ohos.permission.GET_PHONE_NUMBERS。 81 82应用需要修改为申请权限ohos.permission.GET_PHONE_NUMBERS。接口功能不变。 83 84**关键的接口/组件变更** 85 86修改前的接口原型: 87 88```js 89 @permission ohos.permission.GET_TELEPHONY_STATE 90 function getSimTelephoneNumber(slotId: number, callback: AsyncCallback<string>): void; 91 92 @permission ohos.permission.GET_TELEPHONY_STATE 93 function getSimTelephoneNumber(slotId: number): Promise<string>; 94``` 95 96修改后的接口原型: 97 98```js 99 @permission ohos.permission.GET_PHONE_NUMBERS 100 function getSimTelephoneNumber(slotId: number, callback: AsyncCallback<string>): void; 101 102 @permission ohos.permission.GET_PHONE_NUMBERS 103 function getSimTelephoneNumber(slotId: number): Promise<string>; 104``` 105 106 107 108**适配指导** 109 110使用变更后的接口,示例代码如下: 111 112module.json中申请权限需要更换或者添加ohos.permission.GET_PHONE_NUMBERS。 113 114```js 115"requestPermissions" : [ 116 { 117 "name": "ohos.permission.GET_PHONE_NUMBERS", 118 "reason": "$string:GET_PHONE_NUMBERS" 119 } 120] 121```