1、当前位置信息的获取,app.json中添加
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},
"requiredPrivateInfos": [
"chooseLocation",
"choosePoi",
"chooseAddress"
],
2、小程序开发中使用sass语法,project.config.json
"setting": {
"useCompilerPlugins": [
"sass"
],
}
3、使用分包处理,app.js中添加
"subPackages":[
{
“root”:‘’,
“pages”:[]
}]
4、小程序页面适配iPhone和安卓的安全区域,在app.js中onLaunch使用
wx.getSystemInfo({
success: res => {
let { screenHeight, safeArea: { bottom } } = res
this.globalData.safeArea = screenHeight - bottom
this.globalData.bottom_spacing = (20 + (screenHeight - bottom)) + 'rpx'
this.globalData.tabbar = 68 + (screenHeight - bottom)
this.globalData.page_btn = (148 + (screenHeight - bottom)) + 'rpx'
}
})
5、强制更新新的版本,在app.js中onLaunch使用
autoUpdate:function(){
var self=this
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提⽰',
content: '新版本已经准备好,是否重启应⽤?',
success: function (res) {
if (res.confirm) {
updateManager.applyUpdate()
} else if (res.cancel) {
wx.showModal({
title: '温馨提⽰~',
content: '本次版本更新涉及到新的功能添加,旧版本⽆法正常访问的哦~',
success: function (res) {
if (res.confirm) {
updateManager.applyUpdate()
} else if (res.cancel) {
self.autoUpdate()
}
}
})
}
}
})
})
updateManager.onUpdateFailed(function () {
wx.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线啦~,请您删除当前⼩程序,重新搜索打开哟~',
})
})
}
})
} else {
wx.showModal({
title: '提⽰',
content: '当前微信版本过低,⽆法使⽤该功能,请升级到最新微信版本后重试。'
})
}
},
消息订阅弹框
},
openSend() {
var _that = this;
wx.getSetting({
withSubscriptions: true,
success(res) {
var itemSettings = res.subscriptionsSetting.itemSettings;
console.log("订阅情况",itemSettings);
if (itemSettings){
if (itemSettings['toQw1CWLNqV7vt6j34R6DfQxPcNgzojgihLuULH-SgA']== 'accept') {
return
}
}
wx.showModal({
title: '',
content: '活动开始提醒',
confirmText: "同意",
cancelText: "拒绝",
success: function (res) {
if (res.confirm) {
console.log('用户点击确定');
_that.requestSubscribe();
} else if (res.cancel) {
wx.showModal({
title: '',
content: '拒绝后您将无法收到活动开始提醒',
confirmText: "知道了",
showCancel: false,
success: function (res) {
}
});
}
}
});
}
})
},
requestSubscribe() {
wx.requestSubscribeMessage({
tmplIds: [''],
success: (res) => {
console.log("订阅消息 成功 " + res);
console.log(res);
},
fail: (errCode, errMessage) => {
console.log("订阅消息 失败 " + errCode + " message " + errMessage);
console.log(errCode);
},
complete: (errMsg) => {
console.log("订阅消息 完成 " + errMsg);
console.log(errMsg);
}
});
},