简体   繁体   English

iPhone关闭时,为什么异步URL请求返回错误?

[英]Why does Asynchronous URL Request return error when iPhone is turned off?

I am developing an iOS application and I'm using the NSURLConnection sendAsynchronousRequest: queue: completionHandler: method. 我正在开发一个iOS应用程序,并且正在使用NSURLConnection sendAsynchronousRequest: queue: completionHandler:方法。 When I started testing the app on the iPhone, whenever the app is calling the method and I lock the phone, the method returns an error. 当我开始在iPhone上测试该应用程序时,只要该应用程序正在调用该方法并锁定手机,该方法都会返回错误。 Why is this so? 为什么会这样呢? Is there anyway I can prevent it from doing this, so that the method still runs even when the phone is locked? 无论如何,我可以阻止它执行此操作,以便即使手机被锁定时该方法仍然可以运行吗?

Your app is placed in the background when the UI is locked. 锁定用户界面后,您的应用将置于后台。 The same thing will happen if someone presses the home button while your app is running. 如果在您的应用程序运行时有人按下主页按钮,将会发生同样的事情。 You should change your app to handle being placed in the background. 您应该更改您的应用程序以处理被放置在后台。

https://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html https://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

this may help -- 这可能会帮助-

applicationProtectedDataWillBecomeUnavailable applicationProtectedDataWillBecome不可用

If your application is currently accessing a protected file, you can use this method to release any references to that file. 如果您的应用程序当前正在访问受保护的文件,则可以使用此方法释放对该文件的所有引用。 Although it is not an error to access the file while the device is locked, any attempts to do so will fail. 虽然在设备锁定时访问文件不是错误,但是任何尝试都会失败。 Therefore, if your application depends on the file, you might want to take steps to avoid using that file while the device is locked. 因此,如果您的应用程序依赖于该文件,则您可能需要采取措施避免在设备锁定时使用该文件。

On a device that uses content protection, protected files are stored in an encrypted form and made available only at certain times, usually when the device is unlocked. 在使用内容保护的设备上,受保护的文件以加密形式存储,并且仅在特定时间(通常是在设备解锁时)才可用。 This notification lets your application know that the device is about to be locked and that any protected files it is currently accessing might become unavailable shortly. 该通知使您的应用程序知道该设备即将被锁定,并且该设备当前正在访问的所有受保护文件可能很快将不可用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM