简体   繁体   English

有什么解决方案可以在iPhone进入睡眠状态时暂停NSURLSessionTask并在iPhone处于活动状态时恢复

[英]Is there any solution to pause NSURLSessionTask when iPhone goes to sleep and resume when iPhone becomes active

I am performing some NSURLSessionTask. 我正在执行一些NSURLSessionTask。 It takes nearly 10-15 seconds to complete the task.Everything goes well when iPhone is in active state. 完成任务大约需要10-15秒。当iPhone处于活动状态时,一切都会顺利进行。

The problem here is while performing the task, if iPhones goes to sleep mode then task will stop with an error saying "Network connection lost". 这里的问题是在执行任务时,如果iPhone进入睡眠模式,则任务将停止,并显示一条错误消息“网络连接丢失”。

Is there any solution to continue/pause the task even in sleep mode. 是否有任何解决方案即使在睡眠模式下也可以继续/暂停任务。 I tried many solutions which I found in stackoverflow, but that didnt help me. 我尝试了许多在stackoverflow中找到的解决方案,但这并没有帮助我。

Please help me out. 请帮帮我。

According to a response on Apple's forum , downloading on iMac is not possible when the device is in sleep mode. 根据苹果论坛上的回复,当设备处于睡眠模式时,无法在iMac上下载。 I believe a similar case is with the iPhone. 我相信iPhone也有类似情况。 I think your best option would be to use the Background Transfer Service (iOS 7) .Here's an example to help you. 我认为您最好的选择是使用Background Transfer Service(iOS 7)。以下是一个可以帮助您的示例

The primary objective of the sleep mode is to save power.So in addition to keeping your app running in background, the device would have to perform an additional task of downloading files, which (I think) is in contrast with the objective. 睡眠模式的主要目的是节省电量,因此除了使您的应用程序在后台运行之外,该设备还必须执行下载文件的其他任务,这与我的目标形成了鲜明对比。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iPhone锁定/解锁时如何暂停/恢复音频 - How to pause/resume audio when iphone is locked/unlocked 当iPhone /设备进入睡眠或锁定状态时继续播放音频 - continue playing audio when iphone/device goes sleep or locked 当应用程序转到后台时暂停和恢复UIViewAnimation - Pause and Resume UIViewAnimation when app goes to background iphone的事件会自动进入睡眠状态 - Event for iphone goes to sleep automatically 当应用程序进入后台时暂停动画并在 Swift 中以前台模式恢复 - Pause animation when app goes background and resume in foreground mode in Swift 当 iPhone/Android 进入睡眠状态时,JavaScript 执行(settimeout 等)会发生什么情况? - What happens to JavaScript execution (settimeout, etc.) when iPhone/Android goes to sleep? 暂停/恢复文件从iPhone上载到服务器 - Pause/Resume file uploading to server from iphone iPhone进入深度睡眠状态时如何维护NSTimer? - How to maintain NSTimer when iPhone in deep sleep? 如何在iPhone(iOS)中暂停/恢复下载 - How to pause/resume downloads in iPhone (iOS) 当iPhone锁定/解锁且应用程序处于后台时如何恢复音频 - How to resume audio when iphone is locked/unlocked and the application was in background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM