添加phonegap-plugin-push插件后,Ionic app无法启动

时间:2017-07-18 02:53:26

标签: ionic-framework push-notification ionic3 ionic-native

我尝试在以下指南中添加phonegap-plugin-push插件后,我的Ionic应用程序停留在启动画面上:https://ionicframework.com/docs/native/push/

我尝试删除和添加平台,删除和添加phonegap-plugin-push插件,结果是一致的 - 只要将push插件添加到我的项目中,应用程序在启动屏幕时无故障地无故障。

以下是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));
  }

不再调用整个构造函数方法!

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

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:

phonegap-plugin-push 1.10.5 "PushPlugin"

2 个答案:

答案 0 :(得分:0)

我看到你正在使用wkwebview插件。由于这个插件,我在启动画面遇到了冻结。删除它对我有帮助。希望它也能帮到你。

答案 1 :(得分:0)

我发现了问题。我在ionic native documentation之后安装了@ ionic-native / push插件 - 示例代码中的语法导致了问题。只要我切换到v1.x guide中的示例代码,问题就会消失。