【问题标题】:How to use Ionic Cloud with Ionic 2, Angular 2如何在 Ionic 2、Angular 2 中使用 Ionic Cloud
【发布时间】:2016-10-27 15:06:00
【问题描述】:

文档非常不清楚。我想知道我应该把代码放在哪里:

 this.deploy.check().then((snapshotAvailable: boolean) => {
    this.deploy.download().then(() => {
        return this.deploy.extract().then( () => {
         this.deploy.load();
         console.log('Extract Succesful');
     };
  });
 });

所以我想要像 Ionic 1 上的旧行为一样。我可以将代码放在 app.ts 中,它会监视所有内容(所有页面和所有提供程序)并检测是否有任何更改并在客户端设备上进行自动更新.但是医生说我需要在每个页面中从“@ionic/cloud-angular”注入 import {Deploy}?这真的让我很困惑。我怎样才能将 1 个代码放在 1 个地方并监视所有内容。有点设置它并忘记它像 Ionic 1 这样的解决方案......

请帮忙!

【问题讨论】:

    标签: angular ionic-framework ionic2


    【解决方案1】:

    如果您想在整个应用程序中使用某些东西,通常会将其添加到 app.ts 文件构造函数中。

    看看ionic-cloud-angular 库,它有一个代码示例说明如何在app.ts 文件中使用它

    【讨论】:

      【解决方案2】:

      http://tphangout.com/ionic-2-push-notifications/

      浏览此视频教程。适合初学者

      完整的文档将在此链接http://docs.ionic.io/ 中提供

      【讨论】:

        【解决方案3】:

        需要在app.component.ts之后添加代码

        platform.ready().then(() => {
          ...
          this.watchDeploy();
        }
        

        比你可以添加的功能:

        watchDeploy(){
        // check for update once then with a delay
          this.checkNewVersion().then(()=> {
          setTimeout(()=>this.watchDeploy(), 20 * 1000);
        })
        
        checkNewVersion():Promise<any> {
         return new Promise<any>((resolve, reject)=> {
          return this.deploy.check().then((snapshotAvailable: boolean) => {
           if (snapshotAvailable) {
            return this.deploy.download().then(() => {
              return this.deploy.extract().then( () => {
               this.deploy.load();
               console.log('Extract Succesful');
               resolve();
              };
            });
           } else {
               resolve();
           }
          })
         })
        }
        

        您只需要在使用它的页面中注入“import {Deploy} from '@ionic/cloud-angular'”即可。在这里它只会在 app.component.ts 中。 最佳实践是为此创建一个新服务。

        【讨论】:

          猜你喜欢
          • 2016-06-26
          • 2018-04-10
          • 1970-01-01
          • 2016-04-18
          • 1970-01-01
          • 2017-01-16
          • 2017-04-08
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多