moves from NSURLConnection to NSURLSession on iOS

This commit is contained in:
Justin R. Miller
2014-02-19 18:38:05 -08:00
parent 66a2c994ac
commit 2bb6163f64
3 changed files with 13 additions and 18 deletions

View File

@@ -377,7 +377,6 @@ class MBXMapView
MBXMapView *mapView;
CADisplayLink *displayLink;
NSOperationQueue *queue;
namespace llmr
{
@@ -390,20 +389,13 @@ namespace llmr
void request_http(std::string url, std::function<void(Response&)> background_function, std::function<void()> foreground_callback)
{
[[NSNotificationCenter defaultCenter] postNotificationName:MBXUpdateActivityNotification object:nil userInfo:[NSDictionary dictionaryWithObject:@1 forKey:@"count"]];
if (!queue)
queue = [NSOperationQueue new];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@(url.c_str())]];
[NSURLConnection sendAsynchronousRequest:urlRequest
queue:queue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@(url.c_str())] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
[[NSNotificationCenter defaultCenter] postNotificationName:MBXUpdateActivityNotification object:nil userInfo:[NSDictionary dictionaryWithObject:@(-1) forKey:@"count"]];
Response res;
if (error == nil)
if ( ! error)
{
res.code = [(NSHTTPURLResponse *)response statusCode];
res.body = { (const char *)[data bytes], [data length] };
@@ -413,12 +405,15 @@ namespace llmr
dispatch_async(dispatch_get_main_queue(), ^(void)
{
foreground_callback();
});
foreground_callback();
[[NSNotificationCenter defaultCenter] postNotificationName:MBXUpdateActivityNotification object:nil userInfo:[NSDictionary dictionaryWithObject:@(-1) forKey:@"count"]];
[[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil];
});
}];
[[NSNotificationCenter defaultCenter] postNotificationName:MBXUpdateActivityNotification object:nil userInfo:[NSDictionary dictionaryWithObject:@1 forKey:@"count"]];
[task resume];
}
double time()

View File

@@ -37,7 +37,7 @@
'INFOPLIST_FILE': 'Info.plist',
'CLANG_CXX_LIBRARY': 'libc++',
'CLANG_CXX_LANGUAGE_STANDARD':'c++11',
'IPHONEOS_DEPLOYMENT_TARGET':'6.0',
'IPHONEOS_DEPLOYMENT_TARGET':'7.0',
'TARGETED_DEVICE_FAMILY': '1,2',
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
'CLANG_ENABLE_OBJC_ARC': 'YES'

View File

@@ -140,7 +140,7 @@
'ARCHS': [ "armv7", "armv7s", "arm64", "i386" ],
'TARGETED_DEVICE_FAMILY': '1,2',
'CODE_SIGN_IDENTITY': 'iPhone Developer',
'IPHONEOS_DEPLOYMENT_TARGET': '5.0',
'IPHONEOS_DEPLOYMENT_TARGET': '7.0',
'PUBLIC_HEADERS_FOLDER_PATH': 'include',
'GCC_INPUT_FILETYPE':'sourcecode.cpp.cpp',
'OTHER_CPLUSPLUSFLAGS':[