在iOS目标C中从前台过渡到后台后继续调用webservice [英] Continue webservice call after transition from foreground to background in iOS objective C

查看:26
本文介绍了在iOS目标C中从前台过渡到后台后继续调用webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在应用程序处于前台时调用网络服务.现在,如果用户将应用程序发送到后台,那么我如何确保此网络服务调用在后台继续执行.

这是我在我的应用中使用的一段代码.

Login* login = [[Login alloc]init];[登录启动SignInProcess];

<块引用>

initiateSignInProcess 有 4 个网络服务调用.他们很正常职能.我正在使用 AFNetworking.

如果任何服务失败,我会再次调用它,并在 afnetworking 代码的失败块中延迟,如下所示:-

失败:^(AFHTTPRequestOperation *operation, NSError *error){[self performSelector:@selector(getUserId) withObject:nil afterDelay:5];}

现在我想知道如果用户将应用程序发送到后台,那么代码将如何执行?它会在 bakcground 中调用这个函数直到它成功吗?

解决方案

最好使用后台进程来获取.这是解决方案 [http://code.tutsplus.com/tutorials/ios-7-sdk-working-with-background-fetch--mobile-20520

Suppose I call a webservice when the app is in foreground. Now if the user sends the app to background then how do I make sure that this webservice call keeps executing in the background.

This is the piece of code that I am using in my app.

Login* login = [[Login alloc]init];
[login initiateSignInProcess];

initiateSignInProcess has 4 web service calls. they are normal functions. I am using AFNetworking.

If any of the services fail, I call it again with a delay in the failure block of afnetworking code like below:-

failure:^(AFHTTPRequestOperation *operation, NSError *error)
         {
[self performSelector:@selector(getUserId)  withObject:nil afterDelay:5];
}

Now I want to know that if the user sends the app to background, then how will the code execute? Will it call this function in bakcground till it succeeds?

解决方案

Best to use Background Process for fetch. Here is great tutorial for solution [ http://code.tutsplus.com/tutorials/ios-7-sdk-working-with-background-fetch--mobile-20520

这篇关于在iOS目标C中从前台过渡到后台后继续调用webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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