Skip to content

Instantly share code, notes, and snippets.

@DonMag
Last active March 30, 2016 21:06
Show Gist options
  • Select an option

  • Save DonMag/6fccb6ef882b8116ced36ee58989a863 to your computer and use it in GitHub Desktop.

Select an option

Save DonMag/6fccb6ef882b8116ced36ee58989a863 to your computer and use it in GitHub Desktop.
// this is ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
// end of ViewController.h
// 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