NativeScript / ios-jsc

NativeScript for iOS using JavaScriptCore
http://docs.nativescript.org/runtimes/ios
Apache License 2.0
298 stars 59 forks source link

Background Launch of App Crashes on Startup #922

Open vtjon opened 6 years ago

vtjon commented 6 years ago

Please, provide the following version numbers that your issue occurs with:

I have simpllified my applicationDidFinishLaunchingWithOptions so that it does not make any calls out to the Applozic SDK if the applicationState==Background.

Is there any code involved?

main.ios.ts

// this import should be first in order to load some required settings (like globals and reflect-metadata)
import { platformNativeScriptDynamic } from "nativescript-angular/platform";
import { AppModule } from "./app.module";
import app = require("application");

const { CustomAppDelegate } = require("./delegate");
app.ios.delegate = CustomAppDelegate;

platformNativeScriptDynamic({ startPageActionBarHidden: true }).bootstrapModule(
  AppModule
);

My app delegate has a lot of other callbacks but here is the applicationDidFinishLaunchingWithOptions.

applicationDidFinishLaunchingWithOptions(
    application: UIApplication,
    launchOptions
  ): boolean {
    console.log("applicationWillFinishLaunchingWithOptions: ", this);

    if (application.applicationState == UIApplicationState.Background) {
      console.log("APP STATE BACKGROUND");
      return false;
    }
    if (application.applicationState == UIApplicationState.Inactive)
      console.log("APP STATE INACTIVE");

    let manager = IQKeyboardManager.sharedManager();
    manager.disabledDistanceHandlingClasses.addObject(
      ALChatViewController.class
    );

    let localNotification = ALAppLocalNotifications.alloc();
    localNotification.dataConnectionNotificationHandler();

    application.applicationIconBadgeNumber = 0;
    application.cancelAllLocalNotifications();
    if (launchOptions) {
      let dictionary = launchOptions.objectForKey(
        UIApplicationLaunchOptionsRemoteNotificationKey
      );
      if (dictionary != null) {
        console.log(
          "Launched from push notification: " + dictionary.toString()
        );
        let alPushNotificationService = ALPushNotificationService.alloc().init();
        let applozicProcessed = alPushNotificationService.processPushNotificationUpdateUI(
          dictionary,
          APP_TRI_STATE.STATE_INACTIVE
        );
        if (applozicProcessed) {
          console.log("APPLZOIC PROCESSED LAUNCH OPTIONS");
        }
      }
    }

    return true;
  }

Console log at the time the background notification is sent: https://gist.github.com/vtjon/4fabbdf55c67e406fe6f638149849347

In the console log, there is a " Launch Event " message. At the top of my AppModule, I have:

application.on(application.launchEvent ...

This just prints out the message that you see and no additional logic.

Crash Log (this has times on it that are earlier than the Console Log but it's the same crash each time and the device logs are slow to load) https://gist.github.com/vtjon/f675296d93971ac0e694e59ea506549a

I have to assume that this is due to the CPU required to load Angular. I have tried a bundle version and I get the behavior.

vtjon commented 6 years ago

Quick Note: When I compile my app with AOT, I no longer get the crash though I'm still getting some odd behaviors with regards to network access. I will leave this open while I research and provide more info.