简体   繁体   English

当应用程序在后台时,使用AFNetworking上传图像。

[英]Upload image using AFNetworking when App is in Background.

I want to upload an image, using AFnetworking, which I have done successfully, now I want that to be uploaded even if it the app is in background execution , Is that possible? 我想使用AFnetworking成功完成上载图像,现在我希望即使应用程序在后台执行中也可以上载图像,这可能吗?

I have tried this code: 我已经试过这段代码:

- (void)applicationWillResignActive:(UIApplication *)application {
UIBackgroundTaskIdentifier backgroundIdentifier = [application beginBackgroundTaskWithExpirationHandler:^(void) {
    [[AFHTTPClient sharedClient] cancelAllHTTPOperations]; }]; [application endBackgroundTask:backgroundIdentifier];

} }

But it is showing error on shared-client selector and cancelallHTTPoperations method that they are undefined. 但是它在共享客户端选择器和cancelallHTTPoperations方法上显示错误,它们未定义。

Any help will be greatly appreciated. 任何帮助将不胜感激。

When an app goes to background, the iOS will decide whether or not to completely stop your app or give it some time to complete what it's doing. 当某个应用程序进入后台运行时,iOS将决定是否完全停止您的应用程序或给它一些时间来完成其工作。

In case it wants your app to stop, the expiration handler is called. 如果它希望您的应用程序停止,则调用到期处理程序。

If that's happening you should suspend all your tasks as fast as possible and prepare for a complete kill of the app, because that is what will happen a very short time after (5 seconds max). 如果发生这种情况,您应该尽快挂起所有任务,并准备彻底杀死该应用程序,因为这将在很短的时间内(最多5秒)发生。 Take a look here . 在这里看看。

Hope this helps you. 希望这对您有所帮助。

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

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