对于每次用户杀死我的应用程序时通知我的应用程序是非常重要的(不是将其移至后台,而是通过双击主页"按钮并向上滑动我的应用程序屏幕截图实际上完全将其退出).我知道applicationWillTerminate()几乎没有被调用过,所以我想知道当用户杀死该应用程序时最安全的通知方式是什么.苹果似乎没有提供任何形式的解决方案的可能性很小,因为许多iOS用户将它当成一种习惯,当它们用完后就杀死了这些应用程序,因此,如果真的这样做,那真的很不可思议.无法赶上此事件.我唯一需要做的就是解除URLRequest以便向我的Web服务发送一些更新指令.
It's very important for my app to be notified every time the user kills my app (not moving it to the background, but actually quitting it altogether by double-tapping the Home button and swiping my app screenshot up). I know applicationWillTerminate() barely ever gets called, so I was wondering what the safest way is to be notified when a user will kill the app. It seems very unlikely that Apple hasn't provided ANY form of solution for this, as a lot of iOS users make it a custom to kill apps when they're done using it, so it would be really really REALLY weird if it would be impossible to catch this event. The only thing I need to do is fire off a URLRequest to send some updating instructions to my web service.
推荐答案当我添加观察者来处理UIApplicationWillTerminateNotification时,我会获得更多的一致性.当用户双击主页"按钮并滑动应用以将其杀死时,它将被调用.
I get more consistency when I add an observer to handle UIApplicationWillTerminateNotification. It gets called when the user double-taps the Home button and swipe the app to kill it.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(AppDelegate.onAppWillTerminate(_:)), name:UIApplicationWillTerminateNotification, object:nil) return true } func onAppWillTerminate(notification:NSNotification) { print("onAppWillTerminate") }更多推荐
当应用程序被杀死时,向Web服务发送请求? (快速3)
发布评论