Topics

When does AppDelegate:applicationDidFinishLaunching get called?

Dave
 

Mac Project.
MacOS 10.14.6

Hi All,

I have some code that needs to be initialized before any Window/View are displayed. The App was working ok, but it looks like something has changed?

I have a call to initialise AppDelegate:applicationDidFinishLaunching BUT, the Initial Window/View Controller viewDidAppear method is being called before applicationDidFinishLaunching. Is this correct behaviour and if so where is the best place to initialise things?

Thanks a lot
All the Best
Dave

Alex Zavatone
 

You can also look at other methods in the AppDelegate, such as init, applicationWillFinishLaunchingWithOptions and so on.

Just look at the header. They are easy to try.

On Jan 14, 2020, at 9:59 AM, Dave <dave@...> wrote:

Mac Project.
MacOS 10.14.6

Hi All,

I have some code that needs to be initialized before any Window/View are displayed. The App was working ok, but it looks like something has changed?

I have a call to initialise AppDelegate:applicationDidFinishLaunching BUT, the Initial Window/View Controller viewDidAppear method is being called before applicationDidFinishLaunching. Is this correct behaviour and if so where is the best place to initialise things?

Thanks a lot
All the Best
Dave



Sandor Szatmari
 

-(void)awakeFromNib might work for you.

Sandor

On Jan 14, 2020, at 11:13, Dave <dave@...> wrote:

Mac Project.
MacOS 10.14.6

Hi All,

I have some code that needs to be initialized before any Window/View are displayed. The App was working ok, but it looks like something has changed?

I have a call to initialise AppDelegate:applicationDidFinishLaunching BUT, the Initial Window/View Controller viewDidAppear method is being called before applicationDidFinishLaunching. Is this correct behaviour and if so where is the best place to initialise things?

Thanks a lot
All the Best
Dave



Dave
 

Hi,

It seems that whichever method I use, the view get called first. I need a way of initialising App Sub-systems before any view gets called. I’m not sure if this has changed or not or whether its because I’m using Storyboards. I have a "main.storyboard” that’s gets setup automatically be the OS. I think before I was manually instantiating the Window/View Controller from a NIB file.

So, does the Views inside "main.storyboard” get initialized before applicationWillFinishLaunching/applicationDidFinishLaunching get called?

Thanks a lot for your help
Dave

On 14 Jan 2020, at 17:25, Alex Zavatone via Groups.Io <zav=mac.com@groups.io> wrote:

You can also look at other methods in the AppDelegate, such as init, applicationWillFinishLaunchingWithOptions and so on.

Just look at the header. They are easy to try.
On Jan 14, 2020, at 9:59 AM, Dave <dave@...> wrote:

Mac Project.
MacOS 10.14.6

Hi All,

I have some code that needs to be initialized before any Window/View are displayed. The App was working ok, but it looks like something has changed?

I have a call to initialise AppDelegate:applicationDidFinishLaunching BUT, the Initial Window/View Controller viewDidAppear method is being called before applicationDidFinishLaunching. Is this correct behaviour and if so where is the best place to initialise things?

Thanks a lot
All the Best
Dave





Dave
 

The thing is, this Code is supposed to initialize the App Sub-system before any other parts of the App get called. If I put it in AwakeFromNib then the initalization will be dependant of which Window or View Controller gets called first.

I had thought that applicationDidFinishLaunching was a safe place to put this code, but for some reason it doesn’t seem to work anymore.

All the Best
Dave

On 14 Jan 2020, at 17:32, Sandor Szatmari <admin.szatmari.net@...> wrote:

-(void)awakeFromNib might work for you.

Sandor

On Jan 14, 2020, at 11:13, Dave <dave@...> wrote:

Mac Project.
MacOS 10.14.6

Hi All,

I have some code that needs to be initialized before any Window/View are displayed. The App was working ok, but it looks like something has changed?

I have a call to initialise AppDelegate:applicationDidFinishLaunching BUT, the Initial Window/View Controller viewDidAppear method is being called before applicationDidFinishLaunching. Is this correct behaviour and if so where is the best place to initialise things?

Thanks a lot
All the Best
Dave




Jonathan Prescott
 

Since you referenced a Window, I’m assuming MacOS application, not iOS. Probably the same, but not sure since I don’t program for iOS.

According to the documentation, applicationDidFinishLaunching is called by NSApplication just before entering into the application event loop. You could try applicationWillFinishLaunching, which is called just after the application object is initialized, which should be before any controllers are created, if that is appropriate. You could also override the init() method (Swift or Objective-C) if that makes sense.

Jonathan

On Jan 14, 2020, at 10:59 AM, Dave <dave@...> wrote:

Mac Project.
MacOS 10.14.6

Hi All,

I have some code that needs to be initialized before any Window/View are displayed. The App was working ok, but it looks like something has changed?

I have a call to initialise AppDelegate:applicationDidFinishLaunching BUT, the Initial Window/View Controller viewDidAppear method is being called before applicationDidFinishLaunching. Is this correct behaviour and if so where is the best place to initialise things?

Thanks a lot
All the Best
Dave



Sandor Szatmari
 

On Jan 14, 2020, at 11:47, Alex Zavatone via Groups.Io <zav=mac.com@groups.io> wrote:

You can also look at other methods in the AppDelegate, such as init,
If you’re going to look at -init, if it’s an object coming from a NIB then look at overriding -initWithCoder:
applicationWillFinishLaunchingWithOptions and so on.

Just look at the header. They are easy to try.
On Jan 14, 2020, at 9:59 AM, Dave <dave@...> wrote:

Mac Project.
MacOS 10.14.6

Hi All,

I have some code that needs to be initialized before any Window/View are displayed. The App was working ok, but it looks like something has changed?

I have a call to initialise AppDelegate:applicationDidFinishLaunching BUT, the Initial Window/View Controller viewDidAppear method is being called before applicationDidFinishLaunching. Is this correct behaviour and if so where is the best place to initialise things?

Thanks a lot
All the Best
Dave





Jim
 

On Jan 14, 2020, at 10:59 AM, Dave <dave@...> wrote:

Mac Project.
MacOS 10.14.6

Hi All,

I have some code that needs to be initialized before any Window/View are displayed. The App was working ok, but it looks like something has changed?

I have a call to initialise AppDelegate:applicationDidFinishLaunching BUT, the Initial Window/View Controller viewDidAppear method is being called before applicationDidFinishLaunching. Is this correct behaviour and if so where is the best place to initialise things?
Is this a document-based app or a single-window type app?

In my single-window apps, AppDelegate:applicationDidFinishLaunching is called first, and instantiates and displays the main window, so the window’s init and awakeFromNib methods are called before AppDelegate:applicationDidFinishLaunching ends.

In my document-based app, the DocumentWIndowController:windowDidLoad (and presumably viewDidAppear) are called before the AppDelegate:applicationDidFinishLaunching.

Jim Crate

Dave
 

Hi,

This is a Mac project but I will be doing an IOS version too.

I’ve tried applicationWillFinishLaunching and applicationDidFinishLaunching, but the View Controller gets control before either are called.

This is a Single Window based App.

The difference is that before I was manually instantiating the View Controller in applicationDidFinishLaunching (after initialising the App), now its being instantiated automatically by the OS.

Seems a bit weird to be honest, the fact that the Window has displayed means that the App

What dictates whether an App has launched? I’m guessing that the automatic loading is considered part of the Launch process, which would make sense given the naming of the methods.

Maybe there should be a “applicationDidBeginLauching”.

If there really isn’t a safe place to perform this type of initialisation then I guess I could always go back to manually instantiating the Window/View Controller…..

All the Best
Dave


Is this a document-based app or a single-window type app?

In my single-window apps, AppDelegate:applicationDidFinishLaunching is called first, and instantiates and displays the main window, so the window’s init and awakeFromNib methods are called before AppDelegate:applicationDidFinishLaunching ends.

In my document-based app, the DocumentWIndowController:windowDidLoad (and presumably viewDidAppear) are called before the AppDelegate:applicationDidFinishLaunching.

Jim Crate

Dave
 

Hi,

A little more on this.

If I uncheck “Is Initial Controller”, then applicationDidFinishLaunching gets calls as expected.

So I put the code back to instantiate it manually and all works as expected.

All the Best
Dave

Sandor Szatmari
 

I see different behaviour. Here’s a test app. No matter what I do, -awakeFromNib is always called first. I tried it both in the AppDelegate, and in the ViewController subclass.

Cheers,
Sandor

On Jan 15, 2020, at 05:51, Dave <dave@...> wrote:

Hi,

A little more on this.

If I uncheck “Is Initial Controller”, then applicationDidFinishLaunching gets calls as expected.

So I put the code back to instantiate it manually and all works as expected.

All the Best
Dave




Sandor Szatmari
 

There’s a test app attached to demonstrate…

Sandor

On Jan 15, 2020, at 07:49, Sandor Szatmari via Groups.Io <admin.szatmari.net=gmail.com@groups.io> wrote:

I see different behaviour. Here’s a test app. No matter what I do, -awakeFromNib is always called first. I tried it both in the AppDelegate, and in the ViewController subclass.

Cheers,
Sandor


On Jan 15, 2020, at 05:51, Dave <dave@...> wrote:

Hi,

A little more on this.

If I uncheck “Is Initial Controller”, then applicationDidFinishLaunching gets calls as expected.

So I put the code back to instantiate it manually and all works as expected.

All the Best
Dave






<tester.zip>

Dave
 

Hi,

Ahhh, you mean, awakeFromNib in the AppDelegate not the window/view controller. I think I was trying to avoid tying the initialisation to a NIB (in case I ever created it programmatically), but I guess in the case of the NSApplication object it will always be from a NIB so it’s safe.

Thanks a lot
Dave

On 15 Jan 2020, at 13:49, Sandor Szatmari <admin.szatmari.net@...> wrote:

I see different behaviour. Here’s a test app. No matter what I do, -awakeFromNib is always called first. I tried it both in the AppDelegate, and in the ViewController subclass.

Cheers,
Sandor


On Jan 15, 2020, at 05:51, Dave <dave@...> wrote:

Hi,

A little more on this.

If I uncheck “Is Initial Controller”, then applicationDidFinishLaunching gets calls as expected.

So I put the code back to instantiate it manually and all works as expected.

All the Best
Dave






<tester.zip>

Sandor Szatmari
 

Excellent! Glad that was the trick!

On Jan 15, 2020, at 08:13, Dave <dave@...> wrote:

Hi,

Ahhh, you mean, awakeFromNib in the AppDelegate not the window/view controller. I think I was trying to avoid tying the initialisation to a NIB (in case I ever created it programmatically), but I guess in the case of the NSApplication object it will always be from a NIB so it’s safe.

Thanks a lot
Dave


On 15 Jan 2020, at 13:49, Sandor Szatmari <admin.szatmari.net@...> wrote:

I see different behaviour. Here’s a test app. No matter what I do, -awakeFromNib is always called first. I tried it both in the AppDelegate, and in the ViewController subclass.

Cheers,
Sandor


On Jan 15, 2020, at 05:51, Dave <dave@...> wrote:
Hi,

A little more on this.

If I uncheck “Is Initial Controller”, then applicationDidFinishLaunching gets calls as expected.

So I put the code back to instantiate it manually and all works as expected.

All the Best
Dave






<tester.zip>