Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: hoccer/ios-api
base: master
...
head fork: hoccer/ios-api
compare: mdns
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 13 files changed
  • 0 commit comments
  • 1 contributor
View
4 Hoccer/HoccerClient/EnvironmentController/HCEnvironment.h
@@ -37,16 +37,18 @@
@interface HCEnvironment : NSObject {
NSArray *bssids;
+ NSArray *mdnsClients;
CLLocation *location;
NSInteger hoccability;
}
@property (retain) NSArray *bssids;
+@property (retain) NSArray *mdnsClients;
@property (retain) CLLocation *location;
@property (assign) NSInteger hoccability;
-- (id)initWithLocation: (CLLocation *)theLocation bssids: (NSArray*) theBssids;
+- (id)initWithLocation: (CLLocation *)theLocation bssids: (NSArray*) theBssids mdnsClients: (NSArray*) theClients;
- (id)initWithCoordinate: (CLLocationCoordinate2D)coordinate accuracy: (CLLocationAccuracy)accuracy;
- (NSString *)JSONRepresentation;
- (NSDictionary *)dict;
View
20 Hoccer/HoccerClient/EnvironmentController/HCEnvironment.m
@@ -44,12 +44,14 @@ @implementation HCEnvironment
@synthesize location;
@synthesize bssids;
@synthesize hoccability;
+@synthesize mdnsClients;
-- (id) initWithLocation: (CLLocation *)theLocation bssids: (NSArray*) theBssids {
+- (id) initWithLocation: (CLLocation *)theLocation bssids: (NSArray*) theBssids mdnsClients:(NSArray *)theClients{
self = [super init];
if (self != nil) {
self.location = theLocation;
self.bssids = theBssids;
+ self.mdnsClients = theClients;
}
return self;
}
@@ -59,12 +61,13 @@ - (id)initWithCoordinate: (CLLocationCoordinate2D)coordinate accuracy: (CLLocati
horizontalAccuracy:accuracy verticalAccuracy:accuracy
timestamp:[NSDate date]] autorelease];
- return [self initWithLocation:newlocation bssids:nil];
+ return [self initWithLocation:newlocation bssids:nil mdnsClients:nil];
}
- (void) dealloc {
[location release];
[bssids release];
+ [mdnsClients release];
[super dealloc];
}
@@ -88,13 +91,24 @@ - (NSDictionary *)dict {
[dict setObject:locationDict forKey: @"gps"];
}
- if (self.bssids) {
+ if (self.bssids.count > 0) {
NSDictionary *wifi = [NSDictionary dictionaryWithObjectsAndKeys:
self.bssids, @"bssids",
[NSNumber numberWithDouble: [[NSDate date] timeIntervalSince1970]], @"timestamp", nil];
[dict setObject:wifi forKey:@"wifi"];
}
+
+ NSMutableDictionary *mdns = [NSMutableDictionary dictionary];
+
+ [mdns setObject:[[NSUserDefaults standardUserDefaults] stringForKey:@"mdnsId"] forKey:@"own_id"];
+
+ [mdns setObject:[NSNumber numberWithDouble: [[NSDate date] timeIntervalSince1970]] forKey:@"timestamp"];
+
+ if (self.mdnsClients.count > 0) {
+ [mdns setObject:self.mdnsClients forKey:@"seen_ids"];
+ }
+ [dict setObject:mdns forKey:@"mdns"];
return dict;
}
View
5 Hoccer/HoccerClient/EnvironmentController/HCEnvironmentManager.h
@@ -35,6 +35,7 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import "WifiScannerDelegate.h"
+#import "MDNSBrowserDelegate.h"
#import "HCEnvironmentManagerDelegate.h"
#define kHoccerPerfectLocation 0
@@ -43,7 +44,7 @@
@class HCEnvironment;
-@interface HCEnvironmentManager : NSObject <CLLocationManagerDelegate, WifiScannerDelegate> {
+@interface HCEnvironmentManager : NSObject <CLLocationManagerDelegate, WifiScannerDelegate, MDNSBrowserDelegate> {
@private
CLLocationManager *locationManager;
@@ -51,6 +52,7 @@
NSDate *lastLocationUpdate;
NSArray *bssids;
+ NSArray *mdnsClients;
id <HCEnvironmentManagerDelegate> delegate;
}
@@ -61,6 +63,7 @@
- (BOOL)hasLocation;
- (BOOL)hasBSSID;
+- (BOOL)hasMDNSCLients;
- (BOOL)hasEnvironment;
- (void)deactivateLocation;
- (void)activateLocation;
View
28 Hoccer/HoccerClient/EnvironmentController/HCEnvironmentManager.m
@@ -36,12 +36,15 @@
#import "HCEnvironmentManager.h"
#import "WifiScanner.h"
#import "HCEnvironment.h"
+#import "MDNSBrowser.h"
+#import "MDNSAnnouncer.h"
#define hoccerMessageErrorDomain @"HoccerErrorDomain"
@interface HCEnvironmentManager ()
@property (retain) NSDate *lastLocationUpdate;
@property (retain) NSArray *bssids;
+@property (retain) NSArray *mdnsClients;
- (void)updateHoccability;
+ (NSDictionary *)userInfoForImpreciseLocation: (NSDictionary *)hoccabilityInfo;
@@ -59,6 +62,7 @@ @implementation HCEnvironmentManager
@synthesize hoccability;
@synthesize delegate;
@synthesize bssids;
+@synthesize mdnsClients;
- (id) init {
self = [super init];
@@ -73,6 +77,11 @@ - (id) init {
[locationManager startUpdatingLocation];
[WifiScanner sharedScanner].delegate = self;
+
+ [MDNSBrowser sharedBrowser].delegate = self;
+
+ [[MDNSAnnouncer sharedAnnouncer] startAnnouncing];
+
[self updateHoccability];
[[WifiScanner sharedScanner] addObserver:self forKeyPath:@"bssids" options:NSKeyValueObservingOptionNew context:nil];
@@ -90,6 +99,9 @@ - (void) dealloc {
[locationManager stopUpdatingLocation];
[locationManager release];
+
+ [MDNSBrowser sharedBrowser].delegate = nil;
+ [[MDNSAnnouncer sharedAnnouncer] stopAnnouncing];
[super dealloc];
}
@@ -117,9 +129,14 @@ - (void)wifiScannerDidUpdateBssids: (WifiScanner *)scanner {
[self updateHoccability];
}
+- (void)mdnsBrowserDidUpdateDiscoveries:(MDNSBrowser *)browser {
+ self.mdnsClients = [MDNSBrowser sharedBrowser].discoveredClients;
+ [self updateHoccability];
+}
+
- (HCEnvironment *)environment {
HCEnvironment *location = [[HCEnvironment alloc]
- initWithLocation: locationManager.location bssids:[WifiScanner sharedScanner].bssids];
+ initWithLocation: locationManager.location bssids:[WifiScanner sharedScanner].bssids mdnsClients:[MDNSBrowser sharedBrowser].discoveredClients];
location.hoccability = hoccability;
return [location autorelease];
@@ -137,8 +154,11 @@ - (BOOL)hasBSSID {
return self.bssids != nil;
}
+- (BOOL)hasMDNSCLients {
+ return self.mdnsClients != nil;
+}
- (BOOL)hasEnvironment {
- return [self hasBSSID] || [self hasLocation];
+ return [self hasBSSID] || [self hasLocation] || [self hasMDNSCLients];
}
- (void)updateHoccability {
@@ -149,9 +169,13 @@ - (void)updateHoccability {
- (void)deactivateLocation{
[locationManager stopUpdatingLocation];
+ [[MDNSAnnouncer sharedAnnouncer] stopAnnouncing];
+ [[MDNSBrowser sharedBrowser] setDelegate:nil];
}
- (void)activateLocation{
[locationManager startUpdatingLocation];
+ [[MDNSBrowser sharedBrowser] setDelegate:self];
+ [[MDNSAnnouncer sharedAnnouncer] startAnnouncing];
}
+ (NSError *)messageForLocationInformation: (NSDictionary *)hoccabilityInfo {
View
35 Hoccer/HoccerClient/EnvironmentController/mDNS/MDNSAnnouncer.h
@@ -0,0 +1,35 @@
+//
+// MDNSAnnouncer.h
+// Hoccer
+//
+// Created by Philip Brechler on 30.04.12.
+// Copyright (c) 2012 Hoccer GmbH. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+typedef enum {
+ kCryptoServerCouldNotBindToIPv4Address = 1,
+ kCryptoServerCouldNotBindToIPv6Address = 2,
+ kCryptoServerNoSocketsAvailable = 3,
+ kCryptoServerCouldNotBindOrEstablishNetService = 4
+} CryptoServerErrorCode;
+
+
+@interface MDNSAnnouncer : NSObject <NSNetServiceDelegate> {
+ NSMutableSet * connectionBag;
+ NSNetService *mdnsService;
+ CFSocketRef ipv4socket;
+ BOOL isAnnouncing;
+}
+
+@property (nonatomic, retain) NSNetService *mdnsService;
+@property (nonatomic, retain) NSMutableSet *connectionBag;
+@property (assign) CFSocketRef ipv4socket;
+
++ (MDNSAnnouncer *)sharedAnnouncer;
+
+- (void) setupServer:(NSError **)error;
+- (void)startAnnouncing;
+- (void)stopAnnouncing;
+@end
View
137 Hoccer/HoccerClient/EnvironmentController/mDNS/MDNSAnnouncer.m
@@ -0,0 +1,137 @@
+//
+// MDNSAnnouncer.m
+// Hoccer
+//
+// Created by Philip Brechler on 30.04.12.
+// Copyright (c) 2012 Hoccer GmbH. All rights reserved.
+//
+
+#import "MDNSAnnouncer.h"
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#import <arpa/inet.h>
+#include <CFNetwork/CFSocketStream.h>
+
+static MDNSAnnouncer *mdnsAnnouncerInstance;
+
+
+@implementation MDNSAnnouncer
+@synthesize mdnsService,connectionBag,ipv4socket;
+
++ (MDNSAnnouncer *)sharedAnnouncer {
+ if (mdnsAnnouncerInstance == nil) {
+ mdnsAnnouncerInstance = [[MDNSAnnouncer alloc] init];
+ }
+ return mdnsAnnouncerInstance;
+}
+
+- (id)init {
+ self = [super init];
+ isAnnouncing = NO;
+ return self;
+}
+
+-(void)netServiceDidPublish:(NSNetService *)sender {
+ NSLog(@"We did it");
+}
+
+- (void)netService:(NSNetService *)sender didNotPublish:(NSDictionary *)errorDict {
+
+ NSLog(@"Oh noes!");
+}
+
+- (void) setupServer:(NSError **)error {
+ uint16_t chosenPort = 0;
+ struct sockaddr_in serverAddress;
+ socklen_t nameLen = 0;
+ nameLen = sizeof(serverAddress);
+
+ if (self.mdnsService && ipv4socket) {
+ // Calling [self run] more than once should be a NOP.
+ return;
+ } else {
+
+ if (!ipv4socket) {
+ CFSocketContext socketCtxt = {0, self, NULL, NULL, NULL};
+ self.ipv4socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, IPPROTO_TCP, kCFSocketAcceptCallBack, NULL, &socketCtxt);
+
+ if (!ipv4socket) {
+ if (error) * error = [[NSError alloc] initWithDomain:@"HoccerErrorDomain" code:kCryptoServerNoSocketsAvailable userInfo:nil];
+ [self stopAnnouncing];
+ return;
+ }
+
+ int yes = 1;
+ setsockopt(CFSocketGetNative(ipv4socket), SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
+
+ // set up the IPv4 endpoint; use port 0, so the kernel will choose an arbitrary port for us, which will be advertised using Bonjour
+ memset(&serverAddress, 0, sizeof(serverAddress));
+ serverAddress.sin_len = nameLen;
+ serverAddress.sin_family = AF_INET;
+ serverAddress.sin_port = 0;
+ serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
+ NSData * address4 = [NSData dataWithBytes:&serverAddress length:nameLen];
+
+ if (kCFSocketSuccess != CFSocketSetAddress(ipv4socket, (CFDataRef)address4)) {
+ if (error) *error = [[NSError alloc] initWithDomain:@"HoccerErrorDomain" code:kCryptoServerCouldNotBindToIPv4Address userInfo:nil];
+ if (ipv4socket) CFRelease(ipv4socket);
+ ipv4socket = NULL;
+ return;
+ }
+
+ // now that the binding was successful, we get the port number
+ // -- we will need it for the NSNetService
+ NSData * addr = [(NSData *)CFSocketCopyAddress(ipv4socket) autorelease];
+ memcpy(&serverAddress, [addr bytes], [addr length]);
+ chosenPort = ntohs(serverAddress.sin_port);
+
+ // set up the run loop sources for the sockets
+ CFRunLoopRef cfrl = CFRunLoopGetCurrent();
+ CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(kCFAllocatorDefault, ipv4socket, 0);
+ CFRunLoopAddSource(cfrl, source, kCFRunLoopCommonModes);
+ CFRelease(source);
+ }
+
+ if (!self.mdnsService && ipv4socket) {
+ self.mdnsService = [[NSNetService alloc] initWithDomain:@"local" type:@"_hoccer._tcp" name:[[UIDevice currentDevice] name] port:chosenPort];
+ NSDictionary *clientId = [NSDictionary dictionaryWithObjectsAndKeys:[[NSUserDefaults standardUserDefaults] stringForKey:@"mdnsId"],@"id", nil];
+ NSData *clientData = [NSNetService dataFromTXTRecordDictionary:clientId];
+ if (![self.mdnsService setTXTRecordData:clientData]) {
+ NSLog(@"FAIL");
+ }
+ [self.mdnsService setDelegate:self];
+ }
+
+ if (!self.mdnsService && !ipv4socket) {
+ if (error) *error = [[NSError alloc] initWithDomain:@"HoccerErrorDomain" code:kCryptoServerCouldNotBindOrEstablishNetService userInfo:nil];
+ [self stopAnnouncing];
+ return;
+ }
+ }
+}
+
+
+- (void)startAnnouncing {
+ if (!isAnnouncing){
+ [self setupServer:nil];
+ [self.mdnsService scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
+ [self.mdnsService publish];
+ isAnnouncing = YES;
+ }
+}
+
+- (void)stopAnnouncing {
+ if (self.mdnsService) {
+ [self.mdnsService stop];
+ [self.mdnsService removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
+ self.mdnsService = nil;
+ isAnnouncing = NO;
+ }
+ if (self.ipv4socket) {
+ CFSocketInvalidate(self.ipv4socket);
+ CFRelease(self.ipv4socket);
+ self.ipv4socket = NULL;
+ }}
+@end
View
25 Hoccer/HoccerClient/EnvironmentController/mDNS/MDNSBrowser.h
@@ -0,0 +1,25 @@
+//
+// MDNSBrowser.h
+// Hoccer
+//
+// Created by Philip Brechler on 30.04.12.
+// Copyright (c) 2012 Hoccer GmbH. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "MDNSBrowserDelegate.h"
+
+@interface MDNSBrowser : NSObject <NSNetServiceBrowserDelegate,NSNetServiceDelegate> {
+ NSNetServiceBrowser *mdnsBrowser;
+ NSMutableArray *discoveredClients;
+
+ id <MDNSBrowserDelegate>delegate;
+}
+
+@property (nonatomic, retain)NSNetServiceBrowser *mdnsBrowser;
+@property (nonatomic, retain)NSMutableArray *discoveredClients;
+@property (atomic, assign) id <MDNSBrowserDelegate> delegate;
+
++ (MDNSBrowser *)sharedBrowser;
+
+@end
View
74 Hoccer/HoccerClient/EnvironmentController/mDNS/MDNSBrowser.m
@@ -0,0 +1,74 @@
+//
+// MDNSBrowser.m
+// Hoccer
+//
+// Created by Philip Brechler on 30.04.12.
+// Copyright (c) 2012 Hoccer GmbH. All rights reserved.
+//
+
+#import "MDNSBrowser.h"
+
+static MDNSBrowser *mdnsBrowserInstance;
+
+
+@implementation MDNSBrowser
+
+@synthesize discoveredClients;
+@synthesize delegate;
+@synthesize mdnsBrowser;
+
++ (MDNSBrowser *)sharedBrowser {
+
+ if (mdnsBrowserInstance == nil) {
+ mdnsBrowserInstance = [[MDNSBrowser alloc] init];
+ }
+
+ return mdnsBrowserInstance;
+}
+
+- (id) init {
+ self = [super init];
+
+ self.mdnsBrowser = [[NSNetServiceBrowser alloc] init];
+ self.mdnsBrowser.delegate = self;
+ [self.mdnsBrowser searchForServicesOfType:@"_Hoccer._tcp." inDomain:@""];
+
+ self.discoveredClients = [[NSMutableArray alloc] init];
+
+ return self;
+}
+
+- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing {
+ NSLog(@"Found a Service");
+
+ [aNetService retain];
+ [aNetService setDelegate:self];
+ [aNetService startMonitoring];
+ [aNetService resolveWithTimeout:1];
+
+}
+
+- (void)netService:(NSNetService *)sender didUpdateTXTRecordData:(NSData *)data {
+ NSDictionary *aClient = [NSNetService dictionaryFromTXTRecordData:data];
+
+ if ([aClient objectForKey:@"id"])
+ [self.discoveredClients addObject:[[NSString alloc] initWithData:[aClient objectForKey:@"id"] encoding:NSUTF8StringEncoding]];
+
+ [delegate mdnsBrowserDidUpdateDiscoveries:self];
+}
+
+- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didRemoveService:(NSNetService *)aNetService moreComing:(BOOL)moreComing {
+ NSLog(@"Removed Service");
+
+
+ for (int i; i < self.discoveredClients.count; i++) {
+ if ([[[NSString alloc] initWithData:aNetService.TXTRecordData encoding:NSUTF8StringEncoding] isEqualToString:[self.discoveredClients objectAtIndex:i]]){
+ [self.discoveredClients removeObjectAtIndex:i];
+ }
+ }
+
+ [delegate mdnsBrowserDidUpdateDiscoveries:self];
+
+}
+
+@end
View
16 Hoccer/HoccerClient/EnvironmentController/mDNS/MDNSBrowserDelegate.h
@@ -0,0 +1,16 @@
+//
+// MDNSBrowserDelegate.h
+// Hoccer
+//
+// Created by Philip Brechler on 30.04.12.
+// Copyright (c) 2012 Hoccer GmbH. All rights reserved.
+//
+
+
+@class MDNSBrowser;
+
+@protocol MDNSBrowserDelegate <NSObject>
+
+@optional
+- (void)mdnsBrowserDidUpdateDiscoveries: (MDNSBrowser *)browser;
+@end
View
6 Hoccer/HoccerClient/HCFileCache.m
@@ -40,9 +40,9 @@
#import "NSString+URLHelper.h"
#import "NSData+CommonCrypto.h"
-#define FILECACHE_URI @"https://filecache.hoccer.com/v3"
-#define FILECACHE_SANDBOX_URI @"https://filecache-experimental.hoccer.com/v3"
-//#define FILECACHE_SANDBOX_URI @"https://filecache-sandbox.hoccer.com/v3"
+#define FILECACHE_URI @"https://filecache-production.hoccer.com/v3"
+//#define FILECACHE_SANDBOX_URI @"https://filecache-experimental.hoccer.com/v3"
+#define FILECACHE_SANDBOX_URI @"https://filecache-development.hoccer.com/v3"
@implementation HCFileCache
View
2  Hoccer/HoccerClient/HCLinccer.h
@@ -76,6 +76,7 @@ enum HoccerErrors {
NSDictionary *userInfo;
NSString *uuid;
+ NSString *mdnsId;
NSMutableDictionary *clientIDCache;
}
@@ -102,6 +103,7 @@ enum HoccerErrors {
- (void)cancelAllRequest;
- (NSString *)uuid;
+- (NSString *)mdnsId;
- (void)updateEnvironment;
View
41 Hoccer/HoccerClient/HCLinccer.m
@@ -48,9 +48,9 @@
#import "RSA.h"
#import "PublicKeyManager.h"
-#define LINCCER_URI @"https://linccer.hoccer.com/v3"
-#define LINCCER_SANDBOX_URI @"https://linccer-experimental.hoccer.com/v3"
-//#define LINCCER_SANDBOX_URI @"https://linccer-sandbox.hoccer.com/v3"
+#define LINCCER_URI @"https://linccer-production.hoccer.com/v3"
+//#define LINCCER_SANDBOX_URI @"https://linccer-experimental.hoccer.com/v3"
+#define LINCCER_SANDBOX_URI @"https://linccer-development.hoccer.com/v3"
#define HOCCER_CLIENT_ID_KEY @"hoccerClientUri"
@interface HCLinccer ()
@@ -87,7 +87,7 @@ - (id) initWithApiKey:(NSString *)key secret:(NSString *)secret sandboxed: (BOOL
self = [super init];
if (self != nil) {
userInfo = [[NSDictionary dictionaryWithObject:@"<unknown>" forKey:@"client_name"] retain];
-
+ [self mdnsId];
environmentController = [[HCEnvironmentManager alloc] init];
environmentController.delegate = self;
@@ -339,10 +339,15 @@ - (void)httpConnection: (HttpConnection *)connection didSendData: (NSData *)data
[self didFailWithError:error];
return;
}
-
- if ([delegate respondsToSelector:@selector(linccer:didSendData:)]) {
- [delegate linccer: self didSendData: [data yajl_JSON]];
- }
+ @try {
+ if ([delegate respondsToSelector:@selector(linccer:didSendData:)]) {
+ [delegate linccer: self didSendData: [data yajl_JSON]];
+ }
+ }
+ @catch (NSException *exception) {
+ NSLog(@"%@", exception);
+ }
+
}
- (void)httpConnection: (HttpConnection *)connection didReceiveData: (NSData *)data {
@@ -476,6 +481,8 @@ - (void)updateEnvironment {
}
NSString *enviromentAsString = [environment yajl_JSONString];
+
+ NSLog(@"Environment %@",enviromentAsString);
[httpClient putURI:[uri stringByAppendingPathComponent:@"/environment"]
payload:[enviromentAsString dataUsingEncoding:NSUTF8StringEncoding]
@@ -522,7 +529,22 @@ - (NSString *)uuid {
return uuid;
}
-
+- (NSString *)mdnsId {
+ if (mdnsId != nil) {
+ return mdnsId;
+ }
+
+ BOOL shouldCreateNewUUID = [[NSUserDefaults standardUserDefaults] boolForKey:@"renewUUID"];
+ mdnsId = [[[NSUserDefaults standardUserDefaults] stringForKey:@"mdnsId"] copy];
+
+ if (shouldCreateNewUUID || !mdnsId) {
+ mdnsId = [[NSString stringWithUUID] copy];
+ [[NSUserDefaults standardUserDefaults] setObject:mdnsId forKey:@"mdnsId"];
+ }
+ NSLog(@"MDNS: %@",mdnsId);
+ return mdnsId;
+
+}
#pragma mark -
#pragma mark Setter
@@ -564,6 +586,7 @@ - (void)dealloc {
[uuid release];
+ [mdnsId release];
[userInfo release];
[super dealloc];
}
View
21 Hoccer/HoccerClient/HttpClient/HttpClient.m
@@ -108,7 +108,8 @@ - (NSString *)getURI: (NSString *)uri success: (SEL)success {
}
- (NSString *)putURI: (NSString *)uri payload: (NSData *)payload success: (SEL)success {
- return [self requestMethod:@"PUT" URI: uri payload:payload success:success];
+ //NSLog(@"URI: %@ Payload: %@",uri, [[NSString alloc] initWithData:payload encoding:NSUTF8StringEncoding] );
+ return [self requestMethod:@"PUT" URI: uri payload:payload success:success];
}
- (NSString *)postURI: (NSString *)uri payload: (NSData *)payload success: (SEL)success {
@@ -158,14 +159,14 @@ - (NSString *)requestMethod:(NSString *)method absoluteURI:(NSString *)URLString
[connections setObject: container forKey:[connection description]];
httpConnection.startTimestamp = [NSDate date];
-
+ /*
// background task
UIApplication *app = [UIApplication sharedApplication];
httpConnection.bgTask = [app beginBackgroundTaskWithExpirationHandler: ^{
[app endBackgroundTask:httpConnection.bgTask];
httpConnection.bgTask = UIBackgroundTaskInvalid;
}];
-
+ */
return URLString;
}
@@ -204,10 +205,10 @@ - (void)connection:(NSURLConnection *)aConnection didFailWithError:(NSError *)er
if (container == nil) {
return;
}
-
+ /*
[[UIApplication sharedApplication] endBackgroundTask:container.httpConnection.bgTask];
container.httpConnection.bgTask = UIBackgroundTaskInvalid;
-
+ */
if (!container.httpConnection.canceled && [target respondsToSelector:@selector(httpConnection:didFailWithError:)]) {
[target performSelector:@selector(httpConnection:didFailWithError:) withObject: container.httpConnection withObject:error];
}
@@ -225,7 +226,7 @@ - (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLRespo
container.httpConnection.endTimestamp = [NSDate date];
container.httpConnection.response = (NSHTTPURLResponse *)response;
- //NSLog(@"%d, %@", [container.httpConnection.response statusCode], container.httpConnection.uri);
+ //NSLog(@"CODE: %d, URL: %@", [container.httpConnection.response statusCode], container.httpConnection.uri);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)aConnection {
@@ -233,10 +234,10 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)aConnection {
if (container == nil) {
return;
}
-
+ /*
[[UIApplication sharedApplication] endBackgroundTask:container.httpConnection.bgTask];
container.httpConnection.bgTask = UIBackgroundTaskInvalid;
-
+ */
NSError *error = [self hasHttpError: (NSHTTPURLResponse *)container.httpConnection.response];
if (error != nil) {
[self connection:aConnection didFailWithError:error];
@@ -279,10 +280,10 @@ - (void)cancelRequest:(NSString *)uri {
[cancelableConnection.connection cancel];
cancelableConnection.httpConnection.canceled = YES;
-
+ /*
[[UIApplication sharedApplication] endBackgroundTask:cancelableConnection.httpConnection.bgTask];
cancelableConnection.httpConnection.bgTask = UIBackgroundTaskInvalid;
-
+ */
[connections removeObjectForKey:[cancelableConnection description]];
}

No commit comments for this range

Something went wrong with that request. Please try again.