当应用程序被杀死时,向Web服务发送请求? (快速3)

编程入门 行业动态 更新时间:2024-10-10 03:29:58
本文介绍了当应用程序被杀死时,向Web服务发送请求? (快速3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对于每次用户杀死我的应用程序时通知我的应用程序是非常重要的(不是将其移至后台,而是通过双击主页"按钮并向上滑动我的应用程序屏幕截图实际上完全将其退出).我知道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)

本文发布于:2023-11-27 11:15:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637842.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:被杀   应用程序   死时   快速   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!