Last active
March 30, 2016 21:06
-
-
Save DonMag/6fccb6ef882b8116ced36ee58989a863 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // this is ViewController.h | |
| #import <UIKit/UIKit.h> | |
| @interface ViewController : UIViewController | |
| @end | |
| // end of ViewController.h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // this is ViewController.m | |
| #import "ViewController.h" | |
| @interface ViewController () | |
| @end | |
| @implementation ViewController | |
| - (void)viewDidLoad { | |
| [super viewDidLoad]; | |
| // Do any additional setup after loading the view, typically from a nib. | |
| } | |
| - (void)didReceiveMemoryWarning { | |
| [super didReceiveMemoryWarning]; | |
| // Dispose of any resources that can be recreated. | |
| } | |
| - (void)viewDidAppear:(BOOL)animated { | |
| [super viewDidAppear:animated]; | |
| [self doTest]; | |
| } | |
| - (void)doTest { | |
| // 1 | |
| NSString *dataUrl = @"https://www.example.com"; | |
| NSURL *url = [NSURL URLWithString:dataUrl]; | |
| NSURLRequest *req = [[NSURLRequest alloc] initWithURL:url]; | |
| // 2 | |
| NSURLSessionDataTask *downloadTask = [[NSURLSession sharedSession] | |
| dataTaskWithRequest:req | |
| completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { | |
| // 4: Handle response here | |
| NSString *s = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; | |
| NSLog(@"Data: %@", s); | |
| }]; | |
| // 3 | |
| [downloadTask resume]; | |
| } | |
| @end | |
| // end of ViewController.m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment