I have an app which saves some state data with CloudKit. The save and restore work properly however, I want to save the last state when the user selects the Quit command. I issue the call;
func applicationWillTerminate(_ aNotification: Notification) {
cmsHW.saveState()
}
but the CloudKit save called in saveState() never completes. Is there a way to wait for it to finish before the app exits?
答案 0 :(得分:0)
我自己的解决方法是;
1-在applicationShouldTerminate中调用saveState函数
func applicationShouldTerminate(_ sender : NSApplication) -> NSApplication.TerminateReply
{
cmsHW.saveState(sender:self)
return NSApplication.TerminateReply.terminateLater
}
和 2-商店操作完成后;
NSApp.reply(toApplicationShouldTerminate: true)
完成终止。