WeChat Mini Program - Add Mobile Contacts

for reference only

1,wxml:

<view bindlongtap="phoneNumTap">{{phoneNum}}</view>

2,js:

        data = {
            phoneNum: '123456789014'
        }

        methods = {
             // Long press the number response function   
            phoneNumTap: function () {
                 var that = this ;
                 // Prompt to call the number or add the number to the phone address book   
                wx.showActionSheet({
                    itemList: [ 'Call', 'Add Contact' ],
                    success: function (res) {
                         if (res.tapIndex === 0 ) {
                             // call number   
                            wx.makePhoneCall({
                                phoneNumber: that.data.phoneNum,
                            })
                        } else  if (res.tapIndex == 1 ) {
                             // Add to phone address book   
                            wx.addPhoneContact({
                                firstName: 'Zhang San', // contact name   
                                mobilePhoneNumber: that.data.phoneNum, // contact phone number   
                            })
                        }
                    }
                })
            },    
         }

 

.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325578553&siteId=291194637