當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript network.Network類代碼示例

本文整理匯總了TypeScript中@ionic-native/network.Network的典型用法代碼示例。如果您正苦於以下問題:TypeScript Network類的具體用法?TypeScript Network怎麽用?TypeScript Network使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Network類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: constructor

    constructor(mainMenuDelegate: CoreMainMenuDelegate, mainmenuHandler: AddonMessagesMainMenuHandler,
            contentLinksDelegate: CoreContentLinksDelegate, indexLinkHandler: AddonMessagesIndexLinkHandler,
            discussionLinkHandler: AddonMessagesDiscussionLinkHandler, sendMessageHandler: AddonMessagesSendMessageUserHandler,
            userDelegate: CoreUserDelegate, cronDelegate: CoreCronDelegate, syncHandler: AddonMessagesSyncCronHandler,
            network: Network, zone: NgZone, messagesSync: AddonMessagesSyncProvider, appProvider: CoreAppProvider,
            localNotifications: CoreLocalNotificationsProvider, messagesProvider: AddonMessagesProvider,
            sitesProvider: CoreSitesProvider, linkHelper: CoreContentLinksHelperProvider, updateManager: CoreUpdateManagerProvider,
            settingsHandler: AddonMessagesSettingsHandler, settingsDelegate: CoreSettingsDelegate,
            pushNotificationsDelegate: AddonPushNotificationsDelegate, utils: CoreUtilsProvider,
            addContactHandler: AddonMessagesAddContactUserHandler, blockContactHandler: AddonMessagesBlockContactUserHandler) {
        // Register handlers.
        mainMenuDelegate.registerHandler(mainmenuHandler);
        contentLinksDelegate.registerHandler(indexLinkHandler);
        contentLinksDelegate.registerHandler(discussionLinkHandler);
        userDelegate.registerHandler(sendMessageHandler);
        userDelegate.registerHandler(addContactHandler);
        userDelegate.registerHandler(blockContactHandler);
        cronDelegate.register(syncHandler);
        cronDelegate.register(mainmenuHandler);
        settingsDelegate.registerHandler(settingsHandler);

        // Sync some discussions when device goes online.
        network.onConnect().subscribe(() => {
            // Execute the callback in the Angular zone, so change detection doesn't stop working.
            zone.run(() => {
                messagesSync.syncAllDiscussions(undefined, true);
            });
        });

        const notificationClicked = (notification: any): void => {
            messagesProvider.isMessagingEnabledForSite(notification.site).then(() => {
                sitesProvider.isFeatureDisabled('CoreMainMenuDelegate_AddonMessages', notification.site).then((disabled) => {
                    if (disabled) {
                        // Messages are disabled, stop.
                        return;
                    }

                    messagesProvider.invalidateDiscussionsCache(notification.site).finally(() => {
                        linkHelper.goInSite(undefined, 'AddonMessagesIndexPage', undefined, notification.site);
                    });
                });
            });
        };

        if (appProvider.isDesktop()) {
            // Listen for clicks in simulated push notifications.
            localNotifications.registerClick(AddonMessagesProvider.PUSH_SIMULATION_COMPONENT, notificationClicked);
        }

        // Register push notification clicks.
        pushNotificationsDelegate.on('click').subscribe((notification) => {
            if (utils.isFalseOrZero(notification.notif)) {
                notificationClicked(notification);

                return true;
            }
        });

        // Allow migrating the table from the old app to the new schema.
        updateManager.registerSiteTableMigration({
            name: 'mma_messages_offline_messages',
            newName: AddonMessagesOfflineProvider.MESSAGES_TABLE,
            fields: [
                {
                    name: 'textformat',
                    delete: true
                }
            ]
        });

        // Migrate the component name.
        updateManager.registerLocalNotifComponentMigration('mmaMessagesPushSimulation',
                AddonMessagesProvider.PUSH_SIMULATION_COMPONENT);
    }
開發者ID:jleyva,項目名稱:moodlemobile2,代碼行數:74,代碼來源:messages.module.ts

示例2: Onconnection

 Onconnection(){
   // watch network for a disconnect
   let connect=1;
   let disconnectSubscription = this.network.onDisconnect().subscribe(() => {
   console.log('network was disconnected :-(');
   connect=0;
   });
   // stop disconnect watch
   disconnectSubscription.unsubscribe();
   return connect;
 }
開發者ID:sakulhameed,項目名稱:my-android-app,代碼行數:11,代碼來源:connections.ts

示例3: checkForUpdates

  async checkForUpdates() {
    if (this.checking) {
      return;
    } else {
      this.checking = true;
    }

    try {
      await this.platform.ready();
      await this.hasDeploy();

      const hasUpdate = await Promise.race([
        this.pro.deploy().check(),
        new Promise((_, reject) => setTimeout(reject, 8000)),
      ]);

      console.log(hasUpdate);
      if (hasUpdate !== 'true') {
        return false;
      }

      switch (this.network.type) {
        // Don't update if the network type is slow (it probably costs a little bit)
        case Connection.CELL:
        case Connection.CELL_2G:
        case Connection.CELL_3G:
        case Connection.UNKNOWN:
        case Connection.NONE:
          this.network
            .onchange()
            .pipe(take(1))
            .subscribe(() => {
              this.checkForUpdates();
            });
          return false;

        case Connection.WIFI:
        case Connection.CELL_4G:
        default:
          break;
      }

      await this.pro
        .deploy()
        .download()
        .pipe(
          tap(status => console.log('Download status:', status)),
          filter(status => status === 'true' || status === 'done'),
          switchMap(() => this.pro.deploy().extract()),
          tap(status => console.log('Extract status:', status)),
          filter(status => status === 'true' || status === 'done'),
          take(1),
          timeout(30 * 1000),
        )
        .toPromise();

      if (this.settings.isDeveloper) {
        const alert = await this.alertCtrl.show({
          title: 'New update available',
          message: 'There is a new update available',
          buttons: [
            {
              text: 'Install',
              role: 'install',
            },
            {
              text: 'Postpone',
              role: 'cancel',
            },
          ],
        });

        return new Promise(resolve => {
          alert.onDidDismiss((_, role) => {
            if (role === 'install') {
              this.pro.deploy().redirect();
              resolve(true);
            } else {
              resolve(false);
            }
          });
        });
      }
      return false;
    } finally {
      this.checking = false;
    }
  }
開發者ID:ifiske,項目名稱:iFiske,代碼行數:88,代碼來源:deploy.ts

示例4: watchOffline

 watchOffline(): any {
   return this.network.onDisconnect();
 }
開發者ID:nmrisrl11,項目名稱:Ecrotion_Buyer,代碼行數:3,代碼來源:connectivity-service.ts

示例5: watchOnline

 watchOnline(): any {
   return this.network.onConnect();
 }
開發者ID:nmrisrl11,項目名稱:Ecrotion_Buyer,代碼行數:3,代碼來源:connectivity-service.ts


注:本文中的@ionic-native/network.Network類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。