0

后叫stop()方法我在离子3.x版做了一步计数器的问题, 这是代码步骤计数器插件提供了错误时,第一次

import { Stepcounter } from '@ionic-native/stepcounter'; 

startPedometer() { 

if (this.buttonIcon === 'md-walk') { 
    this.buttonIcon = "md-man"; 
    this.startbuttonDisabled = false 
    this.stopbuttonDisabled = true 
    let startOffset = 0 
    this.stepcounter.start(startOffset).then((res: any) => { 
    this.success("Started : " + res) 
    }).catch((err) => this.failure(err)) 
} 
else if (this.buttonIcon === 'md-man') { 
    this.buttonIcon = "md-walk"; 
    this.stopbuttonDisabled = false 
    this.startbuttonDisabled = true 
    this.stepcounter.stop().then((res: any) => { 
    this.count = res 
    }).catch((err) => this.failure(err)) 
} 
} 

ionViewDidEnter(){ 
this.stepcounter.getStepCount().then((res:any)=>{ 
    console.log("---------counts-----------"+JSON.stringify(res)); 
    this.count = res 
}) 
} 

我得到以下错误

service not registered: [email protected] 

请帮我一把。 任何建议表示赞赏。 谢谢。

+0

您是否尝试导入“https:// github.com/ihadeed/cordova-plugin-stepcounter.git”而不是“https:// github.com/texh/cordova-plugin-stepcounter.git”? – Johny

+0

感谢您的这一点,但我实际上放弃使用stepcounter插件的想法,因为它不支持所有的android设备,所以我用谷歌适合api计数用户的步骤 –

回答

-1

使用md-man和实际开始请求完成,您将按钮转换为“停止”按钮之间有一段时间。

注释说明:

if (this.buttonIcon === 'md-walk') { 

    // Change buttons (instant) 

    this.stepcounter.start(startOffset).then((res: any) => { 

    // The counter has actually started (remember this is async) 

    }).catch((err) => this.failure(err)) 
} 

为了解决这个问题,你应该启用then内停止按钮“开始完成”。

+0

感谢您的回复 但问题不在于那里。 您是否看到我在代码下编写的错误? –

+0

你在哪一行得到错误? – Fenton