diff --git a/Default-568h@2x.png b/Default-568h@2x.png new file mode 100644 index 0000000..0891b7a Binary files /dev/null and b/Default-568h@2x.png differ diff --git a/SocketIO.h b/SocketIO.h index 2fbb12e..dd7c175 100755 --- a/SocketIO.h +++ b/SocketIO.h @@ -92,10 +92,12 @@ typedef enum { @property (nonatomic, readonly) NSString *host; @property (nonatomic, readonly) NSInteger port; +@property (nonatomic) NSString *resource; @property (nonatomic, readonly) NSString *sid; @property (nonatomic, readonly) NSTimeInterval heartbeatTimeout; @property (nonatomic) BOOL useSecure; @property (nonatomic) NSArray *cookies; +@property (nonatomic) NSDictionary *headers; @property (nonatomic, readonly) BOOL isConnected, isConnecting; @property (nonatomic, weak) id delegate; @property (nonatomic) BOOL returnAllDataFromAck; @@ -117,6 +119,4 @@ typedef enum { - (void) sendEvent:(NSString *)eventName withData:(id)data andAcknowledge:(SocketIOCallback)function; - (void) sendAcknowledgement:(NSString*)pId withArgs:(NSArray *)data; -- (void) setResourceName:(NSString *)name; - @end \ No newline at end of file diff --git a/SocketIO.m b/SocketIO.m index 61ff67a..5a573a2 100755 --- a/SocketIO.m +++ b/SocketIO.m @@ -36,7 +36,6 @@ #define DEBUGLOG(...) #endif -static NSString* kResourceName = @"socket.io"; static NSString* kHandshakeURL = @"%@://%@%@/%@/1/?t=%.0f%@"; static NSString* kForceDisconnectURL = @"%@://%@%@/%@/1/xhr-polling/%@?disconnect"; @@ -90,6 +89,7 @@ - (id) initWithDelegate:(id)delegate _ackCount = 0; _acks = [[NSMutableDictionary alloc] init]; _returnAllDataFromAck = NO; + self.resource = @"socket.io"; } return self; } @@ -128,15 +128,17 @@ - (void) connectToHost:(NSString *)host // create a query parameters string NSMutableString *query = [[NSMutableString alloc] initWithString:@""]; - [params enumerateKeysAndObjectsUsingBlock: ^(id key, id value, BOOL *stop) { - [query appendFormat:@"&%@=%@", key, value]; + [params enumerateKeysAndObjectsUsingBlock: ^(id key, id val, BOOL *stop) { + NSString *k = [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *v = [val stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + [query appendFormat:@"&%@=%@", k, v]; }]; // do handshake via HTTP request NSString *protocol = _useSecure ? @"https" : @"http"; - NSString *port = _port ? [NSString stringWithFormat:@":%d", _port] : @""; + NSString *port = _port ? [NSString stringWithFormat:@":%ld", (long)_port] : @""; NSTimeInterval time = [[NSDate date] timeIntervalSince1970] * 1000; - NSString *handshakeUrl = [NSString stringWithFormat:kHandshakeURL, protocol, _host, port, kResourceName, time, query]; + NSString *handshakeUrl = [NSString stringWithFormat:kHandshakeURL, protocol, _host, port, self.resource, time, query]; DEBUGLOG(@"Connecting to socket with URL: %@", handshakeUrl); query = nil; @@ -151,9 +153,14 @@ - (void) connectToHost:(NSString *)host NSDictionary *headers = [NSHTTPCookie requestHeaderFieldsWithCookies:_cookies]; [request setAllHTTPHeaderFields:headers]; } - [request setHTTPShouldHandleCookies:YES]; - + + if (self.headers) { + [self.headers enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + [request setValue:obj forHTTPHeaderField:key]; + }]; + } + _handshake = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO]; [_handshake scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; [_handshake start]; @@ -182,8 +189,8 @@ - (void) disconnect - (void) disconnectForced { NSString *protocol = [self useSecure] ? @"https" : @"http"; - NSString *port = _port ? [NSString stringWithFormat:@":%d", _port] : @""; - NSString *urlString = [NSString stringWithFormat:kForceDisconnectURL, protocol, _host, port, kResourceName, _sid]; + NSString *port = _port ? [NSString stringWithFormat:@":%ld", (long)_port] : @""; + NSString *urlString = [NSString stringWithFormat:kForceDisconnectURL, protocol, _host, port, self.resource, _sid]; NSURL *url = [NSURL URLWithString:urlString]; DEBUGLOG(@"Force disconnect at: %@", urlString); @@ -259,13 +266,7 @@ - (void) sendAcknowledgement:(NSString *)pId withArgs:(NSArray *)data [self send:packet]; } -- (void) setResourceName:(NSString *)name -{ - kResourceName = [name copy]; -} - -# pragma mark - -# pragma mark private methods +# pragma mark - private methods - (void) sendDisconnect { @@ -653,7 +654,7 @@ - (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespo // check for server status code (http://gigliwood.com/weblog/Cocoa/Q__When_is_an_conne.html) if ([response respondsToSelector:@selector(statusCode)]) { NSInteger statusCode = [((NSHTTPURLResponse *)response) statusCode]; - DEBUGLOG(@"didReceiveResponse() %i", statusCode); + DEBUGLOG(@"didReceiveResponse() %li", (long)statusCode); if (statusCode >= 400) { // stop connecting; no more delegate messages diff --git a/SocketIOTransport.h b/SocketIOTransport.h index 9f8f7be..d53162f 100644 --- a/SocketIOTransport.h +++ b/SocketIOTransport.h @@ -28,6 +28,7 @@ @property (nonatomic, readonly) NSString *host; @property (nonatomic, readonly) NSInteger port; +@property (nonatomic, readonly) NSString *resource; @property (nonatomic, readonly) NSString *sid; @property (nonatomic, readonly) NSTimeInterval heartbeatTimeout; @property (nonatomic) BOOL useSecure; diff --git a/SocketIOTransportWebsocket.m b/SocketIOTransportWebsocket.m index 5b1579b..012d7f6 100644 --- a/SocketIOTransportWebsocket.m +++ b/SocketIOTransportWebsocket.m @@ -29,10 +29,10 @@ #define DEBUGLOG(...) #endif -static NSString* kInsecureSocketURL = @"ws://%@/socket.io/1/websocket/%@"; -static NSString* kSecureSocketURL = @"wss://%@/socket.io/1/websocket/%@"; -static NSString* kInsecureSocketPortURL = @"ws://%@:%d/socket.io/1/websocket/%@"; -static NSString* kSecureSocketPortURL = @"wss://%@:%d/socket.io/1/websocket/%@"; +static NSString* kInsecureSocketURL = @"ws://%@/%@/1/websocket/%@"; +static NSString* kSecureSocketURL = @"wss://%@/%@/1/websocket/%@"; +static NSString* kInsecureSocketPortURL = @"ws://%@:%d/%@/1/websocket/%@"; +static NSString* kSecureSocketPortURL = @"wss://%@:%d/%@/1/websocket/%@"; @implementation SocketIOTransportWebsocket @@ -58,11 +58,11 @@ - (void) open NSString *format; if (delegate.port) { format = delegate.useSecure ? kSecureSocketPortURL : kInsecureSocketPortURL; - urlStr = [NSString stringWithFormat:format, delegate.host, delegate.port, delegate.sid]; + urlStr = [NSString stringWithFormat:format, delegate.host, delegate.port, delegate.resource, delegate.sid]; } else { format = delegate.useSecure ? kSecureSocketURL : kInsecureSocketURL; - urlStr = [NSString stringWithFormat:format, delegate.host, delegate.sid]; + urlStr = [NSString stringWithFormat:format, delegate.host, delegate.resource, delegate.sid]; } NSURL *url = [NSURL URLWithString:urlStr]; diff --git a/SocketIOTransportXHR.m b/SocketIOTransportXHR.m index 771aef5..e8ac3f9 100644 --- a/SocketIOTransportXHR.m +++ b/SocketIOTransportXHR.m @@ -29,10 +29,10 @@ #define DEBUGLOG(...) #endif -static NSString* kInsecureXHRURL = @"http://%@/socket.io/1/xhr-polling/%@"; -static NSString* kSecureXHRURL = @"https://%@/socket.io/1/xhr-polling/%@"; -static NSString* kInsecureXHRPortURL = @"http://%@:%d/socket.io/1/xhr-polling/%@"; -static NSString* kSecureXHRPortURL = @"https://%@:%d/socket.io/1/xhr-polling/%@"; +static NSString* kInsecureXHRURL = @"http://%@/%@/1/xhr-polling/%@"; +static NSString* kSecureXHRURL = @"https://%@/%@/1/xhr-polling/%@"; +static NSString* kInsecureXHRPortURL = @"http://%@:%d/%@/1/xhr-polling/%@"; +static NSString* kSecureXHRPortURL = @"https://%@:%d/%@/1/xhr-polling/%@"; @interface SocketIOTransportXHR (Private) - (void) checkAndStartPoll; @@ -61,11 +61,11 @@ - (void) open NSString *format; if (delegate.port) { format = delegate.useSecure ? kSecureXHRPortURL : kInsecureXHRPortURL; - _url = [NSString stringWithFormat:format, delegate.host, delegate.port, delegate.sid]; + _url = [NSString stringWithFormat:format, delegate.host, delegate.port, delegate.resource, delegate.sid]; } else { format = delegate.useSecure ? kSecureXHRURL : kInsecureXHRURL; - _url = [NSString stringWithFormat:format, delegate.host, delegate.sid]; + _url = [NSString stringWithFormat:format, delegate.host, delegate.resource, delegate.sid]; } DEBUGLOG(@"Opening XHR @ %@", _url); [self poll:nil]; diff --git a/SocketTesterARC.xcodeproj/project.pbxproj b/SocketTesterARC.xcodeproj/project.pbxproj index e8e4616..3197901 100644 --- a/SocketTesterARC.xcodeproj/project.pbxproj +++ b/SocketTesterARC.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ 4ADCCBF315790FDF0022990C /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4ADCCBF215790FDF0022990C /* SystemConfiguration.framework */; }; 4ADCCD4D157915F00022990C /* SocketIO.m in Sources */ = {isa = PBXBuildFile; fileRef = 4ADCCBC715790DEC0022990C /* SocketIO.m */; }; C9E391A215E2A1B00004693A /* SocketIOJSONSerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = C9E391A115E2A1B00004693A /* SocketIOJSONSerialization.m */; }; + F4FF849E1A07830300D8A773 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F4FF849D1A07830300D8A773 /* Default-568h@2x.png */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -67,6 +68,7 @@ 4ADCCBF215790FDF0022990C /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; C9E391A015E2A1B00004693A /* SocketIOJSONSerialization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocketIOJSONSerialization.h; sourceTree = SOURCE_ROOT; }; C9E391A115E2A1B00004693A /* SocketIOJSONSerialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SocketIOJSONSerialization.m; sourceTree = SOURCE_ROOT; }; + F4FF849D1A07830300D8A773 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -105,6 +107,7 @@ 4ADCCB9215790D760022990C = { isa = PBXGroup; children = ( + F4FF849D1A07830300D8A773 /* Default-568h@2x.png */, 4ADCCBA715790D760022990C /* SocketTesterARC */, 4ADCCBA015790D760022990C /* Frameworks */, 4ADCCB9E15790D760022990C /* Products */, @@ -196,7 +199,7 @@ 4ADCCB9415790D760022990C /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0460; + LastUpgradeCheck = 0610; ORGANIZATIONNAME = beta_interactive; }; buildConfigurationList = 4ADCCB9715790D760022990C /* Build configuration list for PBXProject "SocketTesterARC" */; @@ -223,6 +226,7 @@ files = ( 4ADCCBAC15790D760022990C /* InfoPlist.strings in Resources */, 4ADCCBB815790D760022990C /* ViewController.xib in Resources */, + F4FF849E1A07830300D8A773 /* Default-568h@2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -273,14 +277,17 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -290,10 +297,13 @@ ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; @@ -303,20 +313,26 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; + ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; SDKROOT = iphoneos; diff --git a/socket.IO.podspec b/socket.IO.podspec new file mode 100644 index 0000000..e5942c8 --- /dev/null +++ b/socket.IO.podspec @@ -0,0 +1,15 @@ +Pod::Spec.new do |s| + s.name = "socket.IO" + s.version = "0.5.2" + s.summary = "socket.io v0.7.2+ for iOS devices" + s.description = <<-DESC + Interface to communicate between Objective C and Socket.IO with the help of websockets. It's based on fpotter's socketio-cocoa and uses other libraries/classes like SocketRocket, json-framework (optional) and jsonkit (optional). + DESC + s.homepage = "https://github.com/pkyeck/socket.IO-objc" + s.license = 'MIT' + s.author = { "Philipp Kyeck" => "philipp@beta-interactive.de" } + s.source = { :git => "https://github.com/EchoLiao/socket.IO-objc.git", :tag => s.version.to_s } + s.source_files = '*.{h,m}' + s.requires_arc = true + s.dependency 'SocketRocket', '~> 0.2' +end