1.JSONをおかわりする際のsince_idを決めるのに、単にlimit分新しいidとlastidの差分をlastidから引くとむらが大きかったので結局id乖離平均にlimit+1(1足すのはsince_idは自分を含まないため)をかけた数値をlastidから引くようにした。
2.おかわりしたJSONのトップのidがlastidより小さい場合はpostの欠落を防ぐためにわざと重複させるようlastidとトップのidの差をsince_idに+=してたけど、since_idがlastidを超えたり、更には最新のpostidよりでかくなったりと傍若無人な感じになってたのでlastidを超える場合は一旦id乖離平均にlimit+1をかけた数値を半分(それでも多ければ戻ってくるたびに3分の1、4分の1〜)にしてlastidから引いてreqJSON。
3.lastidがおかわりしたJSONの最後のidより小さい場合がなぜか発生するので、その場合の対応を追加。lastidとおかわりしたJSONのトップのidの差分をsince_idに-=してreqJSONする。
これでひとまず1000postsまで検証したが、特に問題なく動いている。と思う。
- (void)apiTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data{
NSDictionary *bd=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
int skip=0;
if(!offsinceflg){
if(lastid>[[[bd valueForKeyPath:@"response.posts.id"]objectAtIndex:0]longLongValue]){
since_id+=(lastid-[[[bd valueForKeyPath:@"response.posts.id"]objectAtIndex:0]longLongValue]);
if(since_id>=lastid) since_id=lastid-(([[idArr objectAtIndex:0]longLongValue]-[[idArr lastObject]longLongValue])/([idArr count]-1)*(limit+1))/adj++;
offsinceval=[NSString stringWithFormat:@"%lld",since_id];[self reqJSON];return;
}else if(lastid<=[[[bd valueForKeyPath:@"response.posts.id"]lastObject]longLongValue]){
since_id-=([[[bd valueForKeyPath:@"response.posts.id"]objectAtIndex:0]longLongValue]-lastid);
offsinceval=[NSString stringWithFormat:@"%lld",since_id];[self reqJSON];return;
}else{
adj=2;
for(id idnum in [bd valueForKeyPath:@"response.posts.id"]){
if(lastid<=[idnum longLongValue]) skip++;
else break;
}
}
}else if(lastid!=0&&lastid<=[[[bd valueForKeyPath:@"response.posts.id"]objectAtIndex:0]longLongValue]){
offset++;offsinceval=[NSString stringWithFormat:@"%d",offset];[self reqJSON];return;
}
//type 別の処理は割愛
lastid=[[idArr lastObject]longLongValue];
[self mkSinglePostView];
}
- (void)npost{
if([pvlayer viewWithTag:now]==[pvArr lastObject]) return;
[[pvlayer viewWithTag:now++] removeFromSuperview];
[pvlayer addSubview:[pvArr objectAtIndex:now-1]];
[bprev removeFromSuperview];
[self na];
if(now+10>[contArr count]){
if(offset+limit<=50){
offsinceval=[NSString stringWithFormat:@"%d",offset+=limit];
}else{
offsinceflg=NO;
//since_id=2*lastid-[[idArr objectAtIndex:[idArr count]-limit-2]longLongValue];
since_id=lastid-(([[idArr objectAtIndex:0]longLongValue]-[[idArr lastObject]longLongValue])/([idArr count]-1)*(limit+1));
offsinceval=[NSString stringWithFormat:@"%lld",since_id];
}
[self reqJSON];
}
}
できた。次はついにreblogとlikeやるか。ジェスチャーの埋め込みもやらねば。夜は台風の中の神戸出張帰りにかねてより気になってたすっぽんラーメン太尊で超すっぽんラーメン+雑炊。雑炊が150円の割りにどっさり3人前くらい出てきたので焦ったが相当美味かったが体重が昨日より1.4kg増えた。
0 件のコメント:
コメントを投稿