监听ReactNative 在前台后台运行状态

 //监听前后台 这个功能暂时关闭  存在漏洞
    // AppState.addEventListener('change', (state) => {
    //     if (state === 'active') {
    //       starttime=new Date().valueOf();
    //     } else if (state === 'background') {
    //         let endtime=new Date().valueOf();
    //         let lineTime=endtime-starttime;
    //         console.log(lineTime/1000/3600)
    //         let token=this.props.token;
    //         let userId=this.props.userId;
    //         if (token!=""&&userId!=""&&lineTime>=1) {
    //           console.log('准备发送在线时长!');
    //           axios.post(`${configUrl}/User/on_line_time`,`token=${this.props.token}&userId=${this.props.userId}&lineTime=${lineTime}`)
    //           .then((res)=>{
    //             let time=eval('(' + res.data + ')');
    //             console.log(time);
    //           })
    //           .catch((err)=>{
    //             console.log(err);
    //           })
    //         }
    //     } else if (state === 'inactive') {
          
    //     }
    // });

 

你可能感兴趣的:(react,native)