0

我使用离子2应用程序推送通知与下面的代码离子即成:运行时错误platform.toLowerCase不是一个函数

import { Push, PushToken } from '@ionic/cloud-angular'; 
    @Component({...}) 
    export MyPage {  
    constructor(public platform: Platform, public menu: MenuController, public push: Push){ 
    this.initializeApp(); 
    } 
    initializeApp() { 
     this.platform.ready().then(() => { 
     if (this.push) { 
     this.push.register().then((t: PushToken) => { 
      return this.push.saveToken(t); 
     }).then((t: PushToken) => { 
      console.log('Token saved:', t.token); 
      window.localStorage.setItem("deviceToken", t.token); 
     }); 

     this.push.rx.notification() 
      .subscribe((msg) => { 
      alert(msg.title + ': ' + msg.text); 
      console.log('notification msg', msg); 
      }); 
     } 
     } 
    } 
} 

当我在设备上运行它正常工作。但我做的离子为它服务,给出以下原因推注射的误差在构造函数中

error_handler.js:53 TypeError: platform.toLowerCase is not a function 
    at Insights.normalizeDevicePlatform (http://localhost:8100/build/main.js:70460:25) 
    at Insights.markActive (http://localhost:8100/build/main.js:70450:33) 
    at Insights.checkActivity (http://localhost:8100/build/main.js:70439:22) 
    at http://localhost:8100/build/main.js:70415:27 
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9723) 
    at Object.onInvokeTask (http://localhost:8100/build/main.js:41825:37) 
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9659) 
    at e.runTask (http://localhost:8100/build/polyfills.js:3:7083) 
    at invoke (http://localhost:8100/build/polyfills.js:3:10836) 
    at e.args.(anonymous function) (http://localhost:8100/build/polyfills.js:2:30123) 
ErrorHandler.handleError @ error_handler.js:53 
+0

推送通知将无法使用离子发球机工作。它只会在真正的设备 –

+0

我知道这一点。我已经通过在platform.ready中检查了它,但它仍然不允许我使用离子服务来调试其他页面。这就像是如果我在构造函数中注入push,那么我无法使用离子服务来测试我的应用程序。我想用离子服务测试其他代码。 –

回答

1

至于马诺Rejinthala评论,推送通知将不会在浏览器(ionic serve)工作。但是,旅游应用程序的其他部分应该在浏览器中正确运行,并使用ionic serve

您描述的错误是Ionic Cloud的问题。检查您的package.json文件中是否有"@ionic/cloud-angular":"^ 0.9.0"行,dependencies

如果是这样,请将其切换到^0.9.1,保存该文件并在项目根文件夹中运行npm install。这应该更新@ionic/cloud-angular0.9.1及其@ionic/cloud依赖关系到0.15.1

然后运行ionic serve它应该工作。

相关问题