applicationWillTerminate 和背景:非常混乱

发布于 2024-09-09 09:42:11 字数 602 浏览 3 评论 0原文

据我所知,实际上在 iOS4 中不再调用 applicationWillTerminate 。但我遇到了这种情况:

  • 我的有声读物进入后台模式并继续播放音频;
  • 直到 SDK 3.x 版本为止,我将收听 MP3 文件的点保存在 applicationWillTerminate 中;
  • 现在我被告知将此保存保留在 applicationWillTerminate (适用于 iPhone 3G)中,并在 applicationDidEnterBackground: 中实现相同的方法:但这保存的不是用户最后的点,而是他进入后台的点......

但是,用户从应用程序坞退出应用程序的那一刻,或者更好的是调用的方法?这存在吗?

当出现内存问题时,ApplicationWillTerminate 会被调用,但实际上我无法弄清楚当用户自己关闭应用程序时会发生什么。

我再说一遍:applicationDidEnterBackground对我没有帮助,因为当用户进入后台模式时,他可以长时间停留在这个位置听有声读物,当他再次启动应用程序时,在关闭之后,我的意思是,他会当他进入后台模式时找到音频文件的位置...

我真的很困惑...

感谢您的帮助!

I understand that applicationWillTerminate is no longer called in iOS4, practically. But I have this situation:

  • my audiobook goes in background mode and keeps playing audio;
  • until version 3.x of SDK I saved the point where one listened to the MP3 file, in applicationWillTerminate;
  • now I was told to keep this saving in applicationWillTerminate (for iPhone 3G) and to implement the same method in applicationDidEnterBackground: but this saves NOT the point where user was at the end, just the point when he entered the background...

But, which is the moment, or better the invoked method, where user exits the application from the application dock? Does this exist?

ApplicationWillTerminate is called when there is a memory problem, but really I can't figure what happens when the user himself shuts down the app.

I repeat: applicationDidEnterBackground does not help me because when the user enters in background mode, he can stays in this position for a long time listening to the audiobook and when he starts again the app, after this is shut down, I mean, he will find the position of the audio file when he entered the background mode…

I'm really confused…

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫以 2024-09-16 09:42:11

无论音频是否继续播放,您都应该在 applicationWillResignActive:applicationDidEnterBackground: 中自动保存播放位置。然后在 applicationWillTerminate 中再次保存。这样,无论接下来发生什么,最后的播放位置都会被保存。下一个事件只需覆盖保存的播放位置即可更新它。

更好的选择是让音频播放器对象本身在中断时触发保存,例如 [AVAudioPlayerDelegate audioPlayerBeginInterruption:] 或类似的。这可能需要一些额外的工作,但它可以保证无论中断原因如何,始终保存播放位置。

You should save the play location automatically in applicationWillResignActive:, applicationDidEnterBackground: regardless of whether the audio keeps playing or not. Then put another save in applicationWillTerminate. That way the last play location is saved regardless of what happens next. The next event simply overwrites the saved play location to update it.

An even better option would be to have the audio player object itself trigger the save whenever it is interrupted e.g [AVAudioPlayerDelegate audioPlayerBeginInterruption:] or similar. It might takes some extra work but it would guarantee that the play location was always saved regardless of the cause of the interruption.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文