即使按下主屏幕按钮或电话进入待机状态,如何继续在iOS中进行RESTKit通话 [英] How to make RESTKit call in iOS continue even if home button is pressed or phone goes into standby

查看:120
本文介绍了即使按下主屏幕按钮或电话进入待机状态,如何继续在iOS中进行RESTKit通话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个异步调用来上传照片,该照片只是一个base64编码的字符串,并且已经过调整大小,因此它不是超级大,也许是800x800或类似的东西。

I currently have an async call to upload a photo, the photo is just a base64 encoded string, and it has been resized so it's not super huge, maybe 800x800 or something like that.

我目前遇到的问题是,即使上载成功,用户也无法关闭应用程序,按主页按钮或以其他方式离开应用程序。他们可以在应用程序中的其他地方工作,但我认为这是一个奖励,但是即使他们离开了应用程序,我也如何继续通话呢?

The problem I currently have is that even though the upload works, the user can't close the app, hit the home button, or otherwise leave the app while it runs. They CAN however work elsewhere in the app which I guess is a bonus, but how do I make this call continue even if they leave the app?

谢谢!

这是我的代码(正在运行),(如果他们坐在那里,那么它就可以运行)

Here is the code I have (it's working), (well it's working if they just sit there)

NSMutableURLRequest *request = [gad.globalObjectManager requestWithObject:nil method:RKRequestMethodPOST path:@"/api/photo/SavePhoto" parameters:paramsSave];

[request setTimeoutInterval:6000];

AFHTTPRequestOperation *operation = [gad.globalClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Photo Upload" message:@"Your photo was successfuly uploaded" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Photo Upload" message:@"Your photo took long to upload or the harvest server is down, please try again when you are on a wi-fi connection" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }];


    [gad.globalClient enqueueHTTPRequestOperation:operation];

我使用可变请求的原因是为了增加超时时间,我读了其他文章说,如果我需要更大的超时时间,我不得不直接进入AF Networking,并且由于RESTKit位于顶部,所以我必须这样做。

The reason I used a mutable request is to increase the timeout, I read other articles that said if I needed a larger timeout I had to go to AF Networking directly, and since RESTKit sits on top I had to do it this way.

推荐答案

RestKit网络操作是AFNetworking操作的子类,因此您仍然可以访问。

RestKit network operations are subclasses of AFNetworking operations so you have access anyway.

调用 setShouldExecuteAsBackgroundTaskWithExpirationHandler: operation 将其配置为在后台运行。

Call setShouldExecuteAsBackgroundTaskWithExpirationHandler: on your operation to configure it to run in the background.

这篇关于即使按下主屏幕按钮或电话进入待机状态,如何继续在iOS中进行RESTKit通话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆