0

Я пытаюсь настроить everlive API для моего {N} NG2 приложения и у меня есть следующие настройкиTelerik Everlive API Nativescript Angular2 Настройка

const Everlive = require('./utils/everlive.all'); 

@Component({ 
    selector: "main", 
    template: "<page-router-outlet></page-router-outlet>" 
}) 
export class AppComponent implements AfterViewInit { 
    el: any; 

    constructor(private utils: Utils) { } 

    ngAfterViewInit() { 
     this.el = new Everlive({ 
      appId: Config.telerikAppId, 
      offlineStorage: true, 
      offline: { 
       syncUnmodified: true, 
       typeSettings: { 
        "ContentTypeName": { 
         "autoGenerateId": false 
        } 
       }, 
       storage: { 
        provider: Everlive.Constants.StorageProvider.FileSystem 
       } 
      }, 
      syncStart: this.startSync, 
      syncEnd: this.endSync 
     }); 

     // start 
     this.el.online(); 

     // track 
     connectivity.startMonitoring((newConnectionType: number) => { 
      switch (newConnectionType) { 
       case connectivity.connectionType.none: 
        console.log("Connection type changed to none."); 
        this.goOffline(); 
        break; 
       case connectivity.connectionType.wifi: 
        console.log("Connection type changed to WiFi."); 
        this.goOnline(); 
        break; 
       case connectivity.connectionType.mobile: 
        console.log("Connection type changed to mobile."); 
        this.goOnline(); 
        break; 
      } 
     }); 
    } 

    startSync() { 
     this.utils.showLoader(); 
    }; 

    endSync(syncInfo) { 
     this.utils.hideLoader(); 
     alert('Sync with server complete'); 
     console.log(syncInfo); 
    }; 

    goOffline() { 
     this.utils.confirmBox('No internet connection, switch to offline mode?', '', 'Yes', 'No') 
      .then((result) => { 
       if (result) { 
        this.el.offline(); 
       } else { 
        this.logout(); 
       } 
      }); 
    } 

    goOnline() { 
     this.utils.confirmBox('Internet connection detected, switch to online mode and sync data?', '', 'Yes', 'No') 
      .then((result) => { 
       if (result) { 
        this.utils.showLoader(); 
        this.el.online(); 
        this.el.sync(); 
       } else { 
        this.logout(); 
       } 
      }); 
    } 

    logout() { 

    } 
} 

Когда я запустить приложение, перемещаться между кучей состояний надеясь, что данные кэшируются. Теперь, я выключаю Wi-Fi на моем ноутбуке, ожидая, что вытащить данные из файловой системы, которые он кэшированный, но вместо этого я вижу ошибку из zone.js

Unhandled Promise rejection: Response {_body: Error: The Internet connection appears to be offline., status: 200, ok: true, statusText: "", headers: Headers…} ; Zone: <root> ; Task: Promise.then ; Value: Response {_body: Error: The Internet connection appears to be offline., status: 200, ok: true, statusText: "", headers: Headers…} undefined 

это то, что я вижу, когда я вхожу в ответ, когда sync завершена

Object {syncedItems: undefined, syncedToServer: 0, syncedToClient: 0, failedItems: undefined, error: undefined} 

ответ

0

, кажется, что everlive SDK не знает, что у вас нет подключения к интернету и пытается сделать запрос.

проверить эту суть с некоторыми примерами кода инициализации https://gist.github.com/anonymous/0d94dc664ed83004e9a349bd5f9eabd0

+0

вы используете услуги бэкэнда Telerik или у вас есть свой собственный Java/PHP бэкенд, из которого вы изначально получить данные? – user7138736

+0

telerik backend services – d1mitar