0
我有一个代码,一旦应用程序正在运行请求。我的问题是我如何每5秒发出一次请求?有史以来5秒的安静请求
代码:
NSDictionary* headers = @{@"X-Mashape-Authorization": @"Key"};
NSDictionary* parameters = @{};
UNIHTTPJsonResponse* response = [[UNIRest get:^(UNISimpleRequest* request) {
[request setUrl:@"https://willjw-statsfc-competitions.p.mashape.com/live.json?key=free&competition=premier-league&timezone=Europe%2FLondon"];
[request setHeaders:headers];
[request setParameters:parameters];
}] asJson];
NSData* rawBody = [response rawBody];
results = [NSJSONSerialization JSONObjectWithData:rawBody options:NSJSONReadingMutableContainers error:nil];
NSLog(@"%@", results);
for (int i = 0; i <= results.count-1; i++)
{
NSString *homeTeam = [[results valueForKey:@"homeshort"] objectAtIndex:i ];
NSString *awayTeam = [[results valueForKey:@"awayshort"] objectAtIndex:i ];
NSString *time = [[results valueForKey:@"statusshort"] objectAtIndex:i ];
NSString *homeScore = [NSString stringWithFormat:@"%@", [[[results valueForKey:@"runningscore"] objectAtIndex:i ] objectAtIndex:0]];
NSString *awayScore = [NSString stringWithFormat:@"%@", [[[results valueForKey:@"runningscore"] objectAtIndex:i ] objectAtIndex:1]];
[arrayBarclay addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:homeTeam,@"hometeam", awayTeam,@"awayteam", time, @"time", homeScore, @"homescore", awayScore, @"awayscore", nil]];
}