Yes, You should observer .willResignActiveNotification
because your application still exists below iOS's Phone Application, which is presented by iOS when there is an incoming call. .didEnterBackgroundNotification
will not be fired on incoming call, it will be fired when you press the home button.
Now, once you done with the call either by rejecting it or after finish your talk the Phone Application
of iOS is removed from top and make your application active. So there you can observe for .didBecomeActiveNotification
for all cases.
You can also check the commented lines in the methods provided by Xcode, when you create a new project. Checkout AppDelegate.swift
to understand the difference
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state.
// This can occur for certain types of temporary interruptions
// **(such as an incoming phone call or SMS message)**
// or when the user quits the application and
// it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers,
// and invalidate graphics rendering callbacks.
// Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data,
// invalidate timers, and store enough application state information to
// restore your application to its current state in case it is terminated later.
// If your application supports background execution,
// this method is called instead of applicationWillTerminate: when the user quits.
}
Summarising it with your cases:
Detect when the user receives a phone call
only .willResignActiveNotification
will be fired.
Detect when a user has pressed the home button to background the app
both .willResignActiveNotification
and .didEnterBackgroundNotification
will be fired respectively.
Hope it helps.