我的应用程序是一个使用语音和视频的直播应用程序。我要:
对于检测这些事件应该观察哪些通知我有些困惑。
我的猜测是:
.willResignActiveNotification
.willResignActiveNotification
.willResignActiveNotification
或.didEnterBackgroundNotification
?.didEnterBackgroundNotification
.willTerminateNotification
要检测应用何时恢复到活动状态1到4,我需要.didBecomeActiveNotification
吗?
这是对的吗?哪个是3号?
答案 0 :(得分:0)
是的,您应该是观察者.willResignActiveNotification
,因为您的应用程序仍然存在于iOS的电话应用程序下,该应用程序在有来电时由iOS呈现。 .didEnterBackgroundNotification
不会在来电中触发,当您按下主屏幕按钮时会触发。
现在,通过拒绝通话或结束通话完成通话后,iOS的Phone Application
将从顶部移除,并使您的应用程序处于活动状态。因此,您可以在所有情况下观察.didBecomeActiveNotification
。
在创建新项目时,还可以在Xcode提供的方法中检查注释的行。结帐AppDelegate.swift
来了解区别
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.
}
根据您的案例进行总结:
在用户接到电话时检测
将仅触发
.willResignActiveNotification
。
当用户按下主屏幕按钮以使应用程序后台运行时进行检测
.willResignActiveNotification
和.didEnterBackgroundNotification
都将被触发。
希望有帮助。