Advertisement
segadude

TodayViewController.h

Nov 4th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "TodayViewController.h"
  2. #import <NotificationCenter/NotificationCenter.h>
  3.  
  4. @interface TodayViewController () <NCWidgetProviding>
  5.  
  6. @end
  7.  
  8. @implementation TodayViewController
  9.  
  10. - (void)getDLNumber {
  11.     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"URL withheld"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15.0];
  12.     NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  13.     if (connection) {
  14.         label.stringValue = @"Connecting...";
  15.     } else {
  16.        
  17.     }
  18.    
  19. }
  20.  
  21. - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
  22.     response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  23. }
  24.  
  25. - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
  26.     //Cleans up string and returns just the number
  27.     NSString *newString = [[response componentsSeparatedByCharactersInSet:
  28.                             [[NSCharacterSet characterSetWithCharactersInString:@"0123456789,"] invertedSet]]
  29.                            componentsJoinedByString:@""];
  30.     label.stringValue = newString;
  31.  
  32. }
  33.  
  34. - (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult result))completionHandler {
  35.     // Update your data and prepare for a snapshot. Call completion handler when you are done
  36.     // with NoData if nothing has changed or NewData if there is new data since the last
  37.     // time we called you
  38.     completionHandler(NCUpdateResultNoData);
  39.     [self getDLNumber];
  40.    
  41. }
  42. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement