2016-11-11 71 views
2

我在我的Ionic 2項目中有下面的代碼,它會接收推送通知。當我運行代碼時,我在控制檯中不斷收到錯誤消息,提示沒有提供者用於推送。Ionic 2問題:沒有提供者推送

import { Component, ViewChild } from '@angular/core'; 
import { ionicBootstrap, Platform, Nav } from 'ionic-angular'; 
import { StatusBar, Splashscreen} from 'ionic-native'; 
import { CloudSettings, PushToken, Push } from '@ionic/cloud-angular'; 

@Component({ 
    templateUrl:'build/app.html' 
}) 

constructor(public platform: Platform, private userProvider: UserProvider, public push: Push) {const cloudSettings: CloudSettings = { 
    'core': { 
     'app_id': 'XXXXXXX', 
    }, 
    'push': { 
     'sender_id': 'XXXXXXX', 
     'pluginConfig': { 
     'android': { 
      'iconColor': '#343434' 
     } 
     } 
    } 
    }; 

    this.push.register().then((t: PushToken) => { 
     return this.push.saveToken(t); 
    }).then((t: PushToken) => { 
     console.log('Token saved:', t.token); 
    }); 

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

}); 

我想這是某種離子2版本不匹配,這裏是我的離子信息的詳細內容下面

Gulp version: CLI version 3.9.1 
Gulp local: Local version 3.9.1 
Ionic Framework Version: 2.0.0-beta.11 
Ionic CLI Version: 2.0.0 
Ionic App Lib Version: 2.0.0-beta.20 
OS: Distributor ID:  Ubuntu Description:  Ubuntu 14.04.3 LTS 
Node Version: v4.5.0 
+0

我會考慮的錯誤消息說的話開始,並檢查,我確實在我的供應商列表中宣佈推。 –

+0

發佈您的NgModule –

+0

@JBNizet添加它檢查我的編輯 – kolexinfos

回答

-1
@NgModule({ 

    declarations: [ 
    MyApp, 
    AboutPage, 
    ContactPage, 
    HomePage, 
    TabsPage 
    ], 

    imports: [ 

    IonicModule.forRoot(MyApp), 
    CloudModule.forRoot(cloudSettings) 
    ], 
+0

Stack Overflow的良好做法是添加一個解釋爲什麼你的解決方案應該工有關更多信息,請閱讀[如何回答](// stackoverflow.com/help/how-to-answer)。 –

1

我解決了錯誤「無提供者推」(使用本地推進系統,而不是離子云),其中推動建立一個自定義提供商(在app.component.ts做不是直接)

    在app.module.ts
  1. (缺少provi DER是錯誤的原因)
 
    import { Push } from '@ionic-native/push'; 
    ... 
    providers: [ 
     Push, 
     ... 
    ] 
  • 在Provider,初始化推在platform.ready()(以確保插件準備好)。
  •  
        this.platform.ready().then(() => { 
         ... 
         this.pushObject = this.push.init(options); 
        });