[英]How can I schedule hourly request to a server and store data on my own server to access from iOS app?
I have very little server side experience. 我对服务器端的经验很少。 I am wondering what my best option would be for the following situation. 我想知道在以下情况下我最好的选择是什么。 There is an API I want to get data from, but there is a limit to how many times I access that data per second, something like less than 10 requests per minute or so, before it gets frozen. 有一个我想从中获取数据的API,但是每秒被冻结多少次是有限制的,例如每分钟少于10次左右的请求,然后才被冻结。 What can I use as a server to schedule a request to the API for all the information I need, every hour or so, so that I can then access the data from my server as many times as I want to from my mobile app? 怎样才能用作服务器,以每小时一小时左右的时间来调度对API的请求,以获取所需的所有信息,以便可以从服务器访问移动应用程序中所需次数的数据?
Are there tools out there that I can take advantage of? 有没有我可以利用的工具?
Good question, I recently had to learn a bit on the server side for the push notifications i'm trying to implement in a market data (fx) app i'm writing. 很好的问题,我最近不得不在服务器端学习一些有关我正在尝试编写的市场数据(fx)应用程序中的推送通知的信息。
The best solution i've found is: 我发现的最佳解决方案是:
Assuming you're on a Mac, 假设您使用的是Mac,
Get MAMP here - it's PHP, MySQL and Apache webserver. 在此处获取MAMP-它是PHP,MySQL和Apache Web服务器。
You can write PHP code to pull the data from the API, store it on your MySQL database you set up with MAMP. 您可以编写PHP代码以从API中提取数据,并将其存储在使用MAMP设置的MySQL数据库中。
You can then write a little objective C code, to hit up your Apache webserver on another PHP file that pulls the data you stored earlier. 然后,您可以编写一些客观的C代码,以在另一个PHP文件中启动Apache Web服务器,该文件将提取您之前存储的数据。
That's basically it, now I know what you're thinking, you probably don't know any PHP. 基本上就是这样,现在我知道您在想什么,您可能不知道任何PHP。 Either did I until last weekend and you should see what I'm able to do in it now! 直到上周末我一直都在做,您现在应该看看我能在其中做什么!
I only knew objective C, but even so learning PHP was very easy - and i'm not the best coder out there. 我只知道目标C,但是即使如此,学习PHP也非常容易-而且我不是那里最好的编码器。
I have a PHP script that (within about 10 lines of code) goes to a website's API pulls JSON values for FX prices and stores them in my DB. 我有一个PHP脚本(大约10行代码)进入网站的API,以获取FX价格的JSON值并将其存储在我的数据库中。 I can then hit up my Webserver and pull the values. 然后,我可以启动我的Web服务器并提取值。
Learning all of this has made me realise that Web applications are incredibly powerful, where before I never considered them when developing iOS apps. 学习所有这些使我意识到Web应用程序功能强大,在开发iOS应用程序之前从未考虑过它们。
if you want to call your webservice after some time interval continuously then i guess NSTimer is the thing that helps you i have a bit of code that might help you for calling your method of parsing 如果您想在某个时间间隔后连续调用Web服务,那么我想NSTimer可以为您提供帮助,我有一些代码可以帮助您调用解析方法
- (void)viewDidLoad{
NSTimer *timer = [NSTimer
scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(methodOfParsing)
userInfo:nil
repeats:YES];
}
it will be called after every 2 second so you can manage this by replacing 2.0 by your desired value 每隔2秒就会调用一次,因此您可以通过将2.0替换为所需的值来进行管理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.