【发布时间】:2021-03-24 02:30:21
【问题描述】:
当我的应用程序强制被用户终止时,我正在尝试将 API 写入 Firebase。我尝试更新我的 info.plist 以将“应用程序不在前台运行”包括为否,并从 AppDelegate 文件中的 func ApplicationWillEnterBackground 调用我的方法,但我也没有成功。事实上,我无法使用该方法注册任何打印语句。我的打印语句正在 ApplicationWillTerminate 下注册,但我猜应用程序实例在 Firebase 写入发生之前就被杀死了。有谁知道这样做的正确方法?新手来了代码如下:
应用程序委托(不包括默认方法):
protocol ForcedOfflineDelegate {
func goOffline(_ AppDelegate: AppDelegate)
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var delegate: ForcedOfflineDelegate?
func applicationWillTerminate(_ application: UIApplication) {
self.delegate?.goOffline(self)
}
我的视图控制器:
class MyViewController: UIViewController, ForcedOfflineDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let appDelegate = AppDelegate()
appDelegate.delegate = self
}
func goOffline(_ AppDelegate: AppDelegate) {
// API Call to Firebase etc. etc.
}
}
【问题讨论】:
标签: swift xcode firebase google-cloud-firestore appdelegate