添加 phonegap-plugin-push 插件后,Ionic 应用程序无法启动 [英] Ionic app fails to launch after adding phonegap-plugin-push plugin

查看:28
本文介绍了添加 phonegap-plugin-push 插件后,Ionic 应用程序无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我尝试添加 phonegap-plugin-push 插件后,我的 Ionic 应用程序卡在了启动画面:https://ionicframework.com/docs/native/push/

My Ionic app stucks at splashscreen, after my attempt to add phonegap-plugin-push plugin following guides here: https://ionicframework.com/docs/native/push/

我尝试删除和添加平台,删除和添加phonegap-plugin-push插件,结果是一致的——只要将push插件添加到我的项目中,应用程序在启动屏幕时静默失败而没有错误.

I tried remove and adding platforms, removing and adding phonegap-plugin-push plugin, the outcome is consistent - as long as the push plugin is added into my project, the app silently fails at launching screen without error.

这里是 app.component.ts 的代码:

Here is the code at app.component.ts:

  constructor(
    public events: Events,
    public userData: UserData,
    public menu: MenuController,
    public platform: Platform,
    public parseData: ParseData,
    public storage: Storage,
    public splashScreen: SplashScreen,
    private iab: InAppBrowser,
    private push: Push
  ) {
    this.platform.ready().then(() => {
      console.log("platform ready called");
      this.nav.setRoot(TabsPage);
      this.menu.enable(true);
      this.splashScreen.hide();
      console.log("splash screen hide called");
    });
  }

  handlePush(){
    // to check if we have permission
    this.push.hasPermission()
      .then((res: any) => {

        if (res.isEnabled) {
          console.log('We have permission to send push notifications');
        } else {
          console.log('We do not have permission to send push notifications');
        }

      });

    // to initialize push notifications

    const options: PushOptions = {
       android: {
           senderID: '12345679'
       },
       ios: {
           alert: 'true',
           badge: true,
           sound: 'false'
       },
       windows: {}
    };

    const pushObject: PushObject = this.push.init(options);

    pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', notification));

    pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', registration));

    pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
  }

不再调用整个构造方法!

The entire constructor method no longer gets called!

这是运行应用程序时的日志输出:

This is the logs output when running the app:

2017-07-18 10:46:07.713123+0800 MY APP[669:222813] DiskCookieStorage changing policy from 2 to 0, cookie file: file:///private/var/mobile/Containers/Data/Application/18A748C9-06F2-438C-9F80-97BC122F5DDD/Library/Cookies/Cookies.binarycookies
2017-07-18 10:46:07.859886+0800 MY APP[669:222813] Apache Cordova native platform version 4.3.1 is starting.
2017-07-18 10:46:07.861502+0800 MY APP[669:222813] Multi-tasking -> Device: YES, App: YES
[INFO] GCDWebServer started on port 8080 and reachable at http://localhost:8080/
2017-07-18 10:46:07.899749+0800 MY APP[669:222813] CDVWKWebViewEngine: trying to inject XHR polyfill
2017-07-18 10:46:08.073686+0800 MY APP[669:222813] CDVWKWebViewEngine will reload WKWebView if required on resume
2017-07-18 10:46:08.073838+0800 MY APP[669:222813] Using Ionic WKWebView
2017-07-18 10:46:08.076407+0800 MY APP[669:222813] [CDVTimer][handleopenurl] 0.579000ms
2017-07-18 10:46:08.084461+0800 MY APP[669:222813] Unlimited access to network resources
2017-07-18 10:46:08.084753+0800 MY APP[669:222813] [CDVTimer][intentandnavigationfilter] 8.060038ms
2017-07-18 10:46:08.085132+0800 MY APP[669:222813] [CDVTimer][gesturehandler] 0.271976ms
2017-07-18 10:46:08.116414+0800 MY APP[669:222813] [CDVTimer][splashscreen] 31.165004ms
2017-07-18 10:46:08.123277+0800 MY APP[669:222813] [CDVTimer][statusbar] 6.673992ms
2017-07-18 10:46:08.127933+0800 MY APP[669:222813] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-07-18 10:46:08.129235+0800 MY APP[669:222813] [MC] Filtering mail sheet accounts for bundle ID: com.company.myapp, source account management: 1
2017-07-18 10:46:08.138180+0800 MY APP[669:222813] [MC] Result: NO
2017-07-18 10:46:08.138302+0800 MY APP[669:222813] [CDVTimer][socialsharing] 14.827967ms
2017-07-18 10:46:08.141556+0800 MY APP[669:222813] [CDVTimer][keyboard] 2.990007ms
2017-07-18 10:46:08.141773+0800 MY APP[669:222813] [CDVTimer][TotalPluginStartup] 66.100001ms
2017-07-18 10:46:08.161063+0800 MY APP[669:222813] createNotificationChecker
2017-07-18 10:46:08.161188+0800 MY APP[669:222813] not coldstart
2017-07-18 10:46:08.166413+0800 MY APP[669:222813] active
2017-07-18 10:46:08.168947+0800 MY APP[669:222813] PushPlugin skip clear badge
2017-07-18 10:46:10.731652+0800 MY APP[669:222813] Ionic Native: deviceready event fired after 781 ms

离子信息:

Cordova CLI: 6.5.0 
Ionic Framework Version: 3.3.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.7
ios-deploy version: 1.9.1 
ios-sim version: 6.0.0 
OS: macOS Sierra
Node Version: v7.6.0
Xcode version: Xcode 8.3.3 Build version 8E3004b

离子平台列表:

Installed platforms:
  android 6.1.0
  ios 4.3.1

推送插件版本为1.10.5:

Push plugin version is 1.10.5:

phonegap-plugin-push 1.10.5 "PushPlugin"

推荐答案

我发现了问题.我按照 离子原生文档 安装了 @ionic-native/push 插件 - 语法在示例代码导致问题.只要我切换到 中的示例代码v1.x 指南,问题消失了.

I found the problem. I installed the @ionic-native/push plugin following the ionic native documentation - the syntax in the example code are causing the problem. As long as I switch to sample code in the v1.x guide, the problems are gone.

这篇关于添加 phonegap-plugin-push 插件后,Ionic 应用程序无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆