const logfilepath = `${wx.env.USER_DATA_PATH}/LogData.txt`
App({
onLaunch() {
let that = this
if (that.onAccessFile11(logfilepath)) {
try {
wx.getFileSystemManager().unlinkSync(logfilepath);
} catch (error) {
console.log('onDeleteFile,删除文件异常' + error);
}
} else {
console.log('onDeleteFile,文件不存在');
}
let buffer = new ArrayBuffer(300)
let dataView = new DataView(buffer)
for (let i = 0; i < 300; i++) {
dataView.setUint8(i, i)
}
console.log(buffer)
try {
wx.getFileSystemManager().writeFileSync(logfilepath, buffer, 'binary')
console.log('保存到文件中OK');
} catch (error) {
console.log('保存到文件中出错' + error);
}
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
console.log('login=' + JSON.stringify(res))
}
})
},
onAccessFile11: function (filepath) {
try {
wx.getFileSystemManager().accessSync(filepath);
return true
} catch (error) {
return false
}
},
})