后台状态下如何处理网络

发布于 2024-10-08 14:04:35 字数 216 浏览 5 评论 0原文

             I am sending email using SMTP Implementation .Now i am switching to another app network to be suspend. How to handle network not to be suspended.

问候,

Arunkumar.P

             I am sending email using SMTP Implementation .Now i am switching to another app network to be suspend. How to handle network not to be suspended.

Regards,

Arunkumar.P

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

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

发布评论

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

评论(1

做个ˇ局外人 2024-10-15 14:04:35

登录iOS开发中心,搜索“后台任务”,您将找到您需要的文档。

更清楚地说,每次您的应用程序要启动一个可能需要一些时间才能完成并且即使在后台也应该处于活动状态的任务时,您应该在此类任务开始之前声明一个 UIBackgroundTaskIdentifier,并告诉 iOS 这是该任务需要在后台运行。而且你还必须确保当你的任务结束时,你应该总是告诉iOS它已经完成并且不再需要特殊的后台权限。

您的代码应如下所示:

//right before your critical task starts
UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];

//immediately after your critical task finishes
if (newTaskId != UIBackgroundTaskInvalid) {
    [[UIApplication sharedApplication] endBackgroundTask: newTaskId];
}

Login to iOS Dev Center, and search "background task", you'll find the document you need.

To be more clear, every time your app is to start a task that may take some time to finish and should be alive even in the background, you should declare a UIBackgroundTaskIdentifier before such a task starts, and tell the iOS that this is the task that needs to run in the background. And you also have to make sure that when your task ends, you should always tell iOS that it's finished and no more special background permission is needed.

Your code should look like this:

//right before your critical task starts
UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];

//immediately after your critical task finishes
if (newTaskId != UIBackgroundTaskInvalid) {
    [[UIApplication sharedApplication] endBackgroundTask: newTaskId];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文