窟べんち for iPhone


大きなお友達の間で有名な日記サイト変人窟ですが、ページ読み込み速度のベンチマークとして使われている事は周知の事実です。

先日画像サーバをダウンさせた事件は記憶に新しいですが、元祖(?)Windows版が青くなった開発者によって削除されたり、Android版がリリースされたり、画像ストレージがPicasaになったり、何故かAndroid版がアップデートされたりと、未だ活発なようです。

んで。

[oEmbedTweet 160263749645766658]

……!!!

Android Marketは自由度が高いので気軽にアプリを出せるようですが、iPhoneはそういうわけにも行きません。審査で蹴られる気がします。多分。

だからと言って「アイフィョーン」とか「きもーい」とか言われているのは癪なので、簡単に作ってみました。

窟べんち for iPhone アイコン 窟べんち for iPhone 実行例

以下、適当なコード。

  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface ViewController : UIViewController
  4. {
  5.     NSTimer *timer;
  6. }
  7. @property (retain, nonatomic) IBOutlet UIWebView *browser;
  8. @property (retain, nonatomic) IBOutlet UIBarButtonItem *doBtn;
  9. @property (retain, nonatomic) IBOutlet UIBarButtonItem *resetBtn;
  10. @property (retain, nonatomic) IBOutlet UILabel *score;
  11. @property (retain, nonatomic) IBOutlet UILabel *condition;
  12.  
  13. - (void)loadPage;
  14. - (void)clearPage;
  15.  
  16. - (void)webViewDidStartLoad:(UIWebView *)webView;
  17. - (void)webViewDidFinishLoad:(UIWebView *)webView;
  18.  
  19. - (IBAction)startDown:(id)sender;
  20. - (IBAction)resetDown:(id)sender;
  21.  
  22. @property (assign) BOOL measuring;
  23. @property (assign) BOOL timerAvailable;
  24. @property (retain, nonatomic) NSDate *stDate;
  25.  
  26. - (void)startTimer;
  27. - (void)stopTimer;
  28. - (void)resetTimer;
  29. - (void)onTimer:(NSTimer *)timer;
  30.  
  31. @end
  1. #import "ViewController.h"
  2.  
  3. @implementation ViewController
  4. @synthesize browser;
  5. @synthesize doBtn;
  6. @synthesize resetBtn;
  7. @synthesize score;
  8. @synthesize condition;
  9.  
  10. @synthesize measuring;
  11. @synthesize timerAvailable;
  12. @synthesize stDate;
  13.  
  14. - (void)didReceiveMemoryWarning
  15. {
  16.     [super didReceiveMemoryWarning];
  17.     // Release any cached data, images, etc that aren&#39;t in use.
  18. }
  19.  
  20. #pragma mark - View lifecycle
  21.  
  22. - (void)viewDidLoad
  23. {
  24.     [super viewDidLoad];
  25.     measuring = FALSE;
  26.     self.score.text = @"tap start";
  27.     timerAvailable = FALSE;
  28.     [self resetTimer];
  29.     timer = [NSTimer scheduledTimerWithTimeInterval:(0.01)
  30.                                              target:self
  31.                                            selector:@selector(onTimer:)
  32.                                            userInfo:nil
  33.                                             repeats:YES];
  34.  
  35. 	// Do any additional setup after loading the view, typically from a nib.
  36. }
  37.  
  38. - (void)viewDidUnload
  39. {
  40.     [self setBrowser:nil];
  41.     [self setDoBtn:nil];
  42.     [self setResetBtn:nil];
  43.     [self setScore:nil];
  44.     [self setCondition:nil];
  45.     [super viewDidUnload];
  46.     // Release any retained subviews of the main view.
  47.     // e.g. self.myOutlet = nil;
  48. }
  49.  
  50. - (void)viewWillAppear:(BOOL)animated
  51. {
  52.     [super viewWillAppear:animated];
  53. }
  54.  
  55. - (void)viewDidAppear:(BOOL)animated
  56. {
  57.     [super viewDidAppear:animated];
  58. }
  59.  
  60. - (void)viewWillDisappear:(BOOL)animated
  61. {
  62. 	[super viewWillDisappear:animated];
  63. }
  64.  
  65. - (void)viewDidDisappear:(BOOL)animated
  66. {
  67. 	[super viewDidDisappear:animated];
  68. }
  69.  
  70. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  71. {
  72.     // Return YES for supported orientations
  73.     return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  74. }
  75.  
  76. - (void)dealloc {
  77.     [browser release];
  78.     [doBtn release];
  79.     [resetBtn release];
  80.     [score release];
  81.     [condition release];
  82.     [super dealloc];
  83. }
  84.  
  85. - (void)loadPage
  86. {
  87.     [browser loadRequest:[NSURLRequest requestWithURL:[NSURL
  88. URLWithString:@"http://www.henjinkutsu.net"]]];
  89. }
  90.  
  91. - (void)clearPage
  92. {
  93.     NSString *htmlString = @"≶html style=\"background-color:#444\"></html>";
  94.     [browser loadHTMLString:htmlString baseURL:nil];
  95. }
  96.  
  97. - (void)webViewDidStartLoad:(UIWebView *)webView
  98. {
  99.     NSLog(@"start load...");
  100.     [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
  101.     if (timerAvailable)
  102.     {
  103.         [self startTimer];
  104.  
  105.     }
  106. }
  107.  
  108. - (void)webViewDidFinishLoad:(UIWebView *)webView
  109. {
  110.     [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
  111.     NSLog(@"finish load...");
  112.     if (timerAvailable)
  113.     {
  114.         [self stopTimer];
  115.     }
  116. }
  117.  
  118. - (IBAction)startDown:(id)sender
  119. {
  120.     NSLog(@"start...");
  121.     timerAvailable = TRUE;
  122.     [self loadPage];
  123. }
  124.  
  125. - (IBAction)resetDown:(id)sender
  126. {
  127.     NSLog(@"reset...");
  128.     [self resetTimer];
  129. }
  130.  
  131. - (void)startTimer
  132. {
  133.     measuring = TRUE;
  134.     condition.text = @"loading: ";
  135.     stDate = [NSDate date];
  136.     [stDate retain];
  137. }
  138. - (void)stopTimer
  139. {
  140.     condition.text = @"done: ";
  141.     measuring = FALSE;
  142. }
  143. - (void)resetTimer
  144. {
  145.     self.timerAvailable = FALSE;
  146.     [self clearPage];
  147.     condition.text = @"prepared: ";
  148.     score.text = @"0.00 sec";
  149. }
  150.  
  151. - (void)onTimer:(NSTimer *)timer
  152. {
  153.     if (measuring)
  154.     {
  155.         NSDate *now = [NSDate date];
  156.         self.score.text = [NSString stringWithFormat:@"%.2f sec", [now
  157. timeIntervalSinceDate:stDate]];
  158.     }
  159. }
  160.  
  161. @end

ご利用は計画的にお願いします。

↓アイコンもどうぞ↓

窟べんちicon 窟べんちicon retina

No Comments.

Leave a Reply

(required)

(required)