diff --git a/PomeloChat.xcodeproj/project.pbxproj b/PomeloChat.xcodeproj/project.pbxproj index c43c0af..ecc4c75 100644 --- a/PomeloChat.xcodeproj/project.pbxproj +++ b/PomeloChat.xcodeproj/project.pbxproj @@ -16,8 +16,6 @@ B20B257F16773678005F5A82 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = B20B257E16773678005F5A82 /* Default.png */; }; B20B258116773678005F5A82 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B20B258016773678005F5A82 /* Default@2x.png */; }; B20B258316773678005F5A82 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B20B258216773678005F5A82 /* Default-568h@2x.png */; }; - B20B25AE16773A9B005F5A82 /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = B20B25A716773A9B005F5A82 /* base64.c */; }; - B20B25AF16773A9B005F5A82 /* NSData+SRB64Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = B20B25AA16773A9B005F5A82 /* NSData+SRB64Additions.m */; }; B20B25B016773A9B005F5A82 /* SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = B20B25AD16773A9B005F5A82 /* SRWebSocket.m */; }; B20B25BE167745F0005F5A82 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B20B25BD167745F0005F5A82 /* libicucore.dylib */; }; B20B25C016774600005F5A82 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B20B25BF16774600005F5A82 /* CFNetwork.framework */; }; @@ -34,6 +32,8 @@ B280B8C1168C506B002B48AF /* ContactsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B280B8C0168C506B002B48AF /* ContactsViewController.m */; }; B280B8C5168C5248002B48AF /* ChatViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B280B8C3168C5248002B48AF /* ChatViewController.m */; }; B280B8C6168C5248002B48AF /* ChatViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = B280B8C4168C5248002B48AF /* ChatViewController.xib */; }; + EA4750841EB07467001EF118 /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = EA47507F1EB07467001EF118 /* base64.c */; }; + EA4750851EB07467001EF118 /* NSData+SRB64Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = EA4750821EB07467001EF118 /* NSData+SRB64Additions.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -50,11 +50,6 @@ B20B257E16773678005F5A82 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; B20B258016773678005F5A82 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = ""; }; B20B258216773678005F5A82 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; - B20B25A716773A9B005F5A82 /* base64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = base64.c; path = SocketRocket/base64.c; sourceTree = ""; }; - B20B25A816773A9B005F5A82 /* base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = base64.h; path = SocketRocket/base64.h; sourceTree = ""; }; - B20B25A916773A9B005F5A82 /* NSData+SRB64Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSData+SRB64Additions.h"; path = "SocketRocket/NSData+SRB64Additions.h"; sourceTree = ""; }; - B20B25AA16773A9B005F5A82 /* NSData+SRB64Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSData+SRB64Additions.m"; path = "SocketRocket/NSData+SRB64Additions.m"; sourceTree = ""; }; - B20B25AB16773A9B005F5A82 /* SocketRocket-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "SocketRocket-Prefix.pch"; path = "SocketRocket/SocketRocket-Prefix.pch"; sourceTree = ""; }; B20B25AC16773A9B005F5A82 /* SRWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SRWebSocket.h; path = SocketRocket/SRWebSocket.h; sourceTree = ""; }; B20B25AD16773A9B005F5A82 /* SRWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SRWebSocket.m; path = SocketRocket/SRWebSocket.m; sourceTree = ""; }; B20B25BD167745F0005F5A82 /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; }; @@ -83,6 +78,11 @@ B280B8C2168C5248002B48AF /* ChatViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChatViewController.h; sourceTree = ""; }; B280B8C3168C5248002B48AF /* ChatViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChatViewController.m; sourceTree = ""; }; B280B8C4168C5248002B48AF /* ChatViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ChatViewController.xib; sourceTree = ""; }; + EA47507F1EB07467001EF118 /* base64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = base64.c; path = SocketRocket/base64.c; sourceTree = ""; }; + EA4750801EB07467001EF118 /* base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = base64.h; path = SocketRocket/base64.h; sourceTree = ""; }; + EA4750811EB07467001EF118 /* NSData+SRB64Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSData+SRB64Additions.h"; path = "SocketRocket/NSData+SRB64Additions.h"; sourceTree = ""; }; + EA4750821EB07467001EF118 /* NSData+SRB64Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSData+SRB64Additions.m"; path = "SocketRocket/NSData+SRB64Additions.m"; sourceTree = ""; }; + EA4750831EB07467001EF118 /* SocketRocket-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "SocketRocket-Prefix.pch"; path = "SocketRocket/SocketRocket-Prefix.pch"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -188,11 +188,11 @@ B20B25901677369F005F5A82 /* SocketRocket */ = { isa = PBXGroup; children = ( - B20B25A716773A9B005F5A82 /* base64.c */, - B20B25A816773A9B005F5A82 /* base64.h */, - B20B25A916773A9B005F5A82 /* NSData+SRB64Additions.h */, - B20B25AA16773A9B005F5A82 /* NSData+SRB64Additions.m */, - B20B25AB16773A9B005F5A82 /* SocketRocket-Prefix.pch */, + EA47507F1EB07467001EF118 /* base64.c */, + EA4750801EB07467001EF118 /* base64.h */, + EA4750811EB07467001EF118 /* NSData+SRB64Additions.h */, + EA4750821EB07467001EF118 /* NSData+SRB64Additions.m */, + EA4750831EB07467001EF118 /* SocketRocket-Prefix.pch */, B20B25AC16773A9B005F5A82 /* SRWebSocket.h */, B20B25AD16773A9B005F5A82 /* SRWebSocket.m */, ); @@ -238,6 +238,11 @@ attributes = { LastUpgradeCheck = 0450; ORGANIZATIONNAME = "netease pomelo team"; + TargetAttributes = { + B20B256716773678005F5A82 = { + DevelopmentTeam = XUUJD5P9J8; + }; + }; }; buildConfigurationList = B20B256216773678005F5A82 /* Build configuration list for PBXProject "PomeloChat" */; compatibilityVersion = "Xcode 3.2"; @@ -277,8 +282,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + EA4750851EB07467001EF118 /* NSData+SRB64Additions.m in Sources */, B245D833168E876400879092 /* Pomelo.m in Sources */, B245D835168E876400879092 /* PomeloProtocol.m in Sources */, + EA4750841EB07467001EF118 /* base64.c in Sources */, B26482EA16898055006D39A1 /* SocketIO.m in Sources */, B26482EC16898055006D39A1 /* SocketIOJSONSerialization.m in Sources */, B26482EE16898055006D39A1 /* SocketIOPacket.m in Sources */, @@ -286,8 +293,6 @@ B26482F316898055006D39A1 /* SocketIOTransportXHR.m in Sources */, B20B257916773678005F5A82 /* main.m in Sources */, B20B257D16773678005F5A82 /* AppDelegate.m in Sources */, - B20B25AE16773A9B005F5A82 /* base64.c in Sources */, - B20B25AF16773A9B005F5A82 /* NSData+SRB64Additions.m in Sources */, B20B25B016773A9B005F5A82 /* SRWebSocket.m in Sources */, B280B8BD168C4806002B48AF /* LoginViewController.m in Sources */, B280B8C1168C506B002B48AF /* ContactsViewController.m in Sources */, @@ -362,10 +367,12 @@ B20B258D16773678005F5A82 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + DEVELOPMENT_TEAM = XUUJD5P9J8; + ENABLE_BITCODE = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PomeloChat/PomeloChat-Prefix.pch"; INFOPLIST_FILE = "PomeloChat/PomeloChat-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -374,10 +381,12 @@ B20B258E16773678005F5A82 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + DEVELOPMENT_TEAM = XUUJD5P9J8; + ENABLE_BITCODE = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PomeloChat/PomeloChat-Prefix.pch"; INFOPLIST_FILE = "PomeloChat/PomeloChat-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; diff --git a/PomeloChat/AppDelegate.m b/PomeloChat/AppDelegate.m index f5dfc4e..a2aa0c1 100644 --- a/PomeloChat/AppDelegate.m +++ b/PomeloChat/AppDelegate.m @@ -23,7 +23,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( LoginViewController *root = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil]; root.pomelo = pomelo; self.navController = [[UINavigationController alloc] initWithRootViewController:root]; - [self.window addSubview:navController.view]; + self.window.rootViewController = self.navController; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; diff --git a/PomeloChat/ChatViewController.m b/PomeloChat/ChatViewController.m index b3833c5..824c21b 100644 --- a/PomeloChat/ChatViewController.m +++ b/PomeloChat/ChatViewController.m @@ -69,8 +69,9 @@ - (void)initEvents { [pomelo onRoute:@"onChat" withCallback:^(NSDictionary *data){ NSLog(@"onChat------"); - NSString *target = [[data objectForKey:@"target"] isEqualToString:@"*"] ? @"" : @" to you"; - [chatStr appendFormat:@"%@ says%@: %@\n", [data objectForKey:@"from"], target, [data objectForKey:@"msg"] ]; + NSDictionary *dataDic = [data objectForKey:@"body"]; + NSString *target = [[dataDic objectForKey:@"target"] isEqualToString:@"*"] ? @"" : @" to you"; + [chatStr appendFormat:@"%@ says%@: %@\n", [dataDic objectForKey:@"from"], target, [dataDic objectForKey:@"msg"] ]; [self updateChat]; }]; } diff --git a/PomeloChat/ChatViewController.xib b/PomeloChat/ChatViewController.xib index 08278e4..dd0436f 100644 --- a/PomeloChat/ChatViewController.xib +++ b/PomeloChat/ChatViewController.xib @@ -1,318 +1,61 @@ - - - 1296 - 12C3006 - 2844 - 1187.34 - 625.00 - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 1930 - - - IBProxyObject - IBUIButton - IBUITextField - IBUITextView - IBUIView - - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - PluginDependencyRecalculationVersion - - - - - IBFilesOwner - IBCocoaTouchFramework - - - IBFirstResponder - IBCocoaTouchFramework - - - - 274 - - - - 292 - {{13, 20}, {219, 30}} - - - - _NS:9 - NO - YES - IBCocoaTouchFramework - 0 - - 3 - say something ... - - 3 - MAA - - 2 - - - YES - 17 - - IBCocoaTouchFramework - - - 1 - 14 - - - Helvetica - 14 - 16 - - - - - 292 - {{240, 20}, {68, 31}} - - - - _NS:9 - NO - IBCocoaTouchFramework - 0 - 0 - 1 - Send - - 3 - MQA - - - 1 - MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA - - - 3 - MC41AA - - - 2 - 15 - - - Helvetica-Bold - 15 - 16 - - - - - 292 - {{13, 58}, {295, 354}} - - - _NS:9 - - 1 - MSAxIDEAA - - YES - YES - IBCocoaTouchFramework - NO - - - 2 - IBCocoaTouchFramework - - - - - - {{0, 20}, {320, 460}} - - - - - 3 - MQA - - - - - IBUIScreenMetrics - - YES - - - - - - {320, 480} - {480, 320} - - - IBCocoaTouchFramework - Retina 3.5 Full Screen - 0 - - IBCocoaTouchFramework - - - - - - - view - - - - 3 - - - - chatTextField - - - - 77 - - - - inputTextField - - - - 78 - - - - send: - - - 7 - - 79 - - - - - - 0 - - - - - - 1 - - - - - - - - - - -1 - - - File's Owner - - - -2 - - - - - 4 - - - - - - 9 - - - - - - 29 - - - - - - - ChatViewController - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - - - 79 - - - - - ChatViewController - UIViewController - - send: - id - - - send: - - send: - id - - - - UITextView - UITextField - - - - chatTextField - UITextView - - - inputTextField - UITextField - - - - IBProjectSource - ./Classes/ChatViewController.h - - - - - 0 - IBCocoaTouchFramework - - com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS - - - - com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 - - - YES - 3 - 1930 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PomeloChat/ContactsViewController.m b/PomeloChat/ContactsViewController.m index 0ef48cc..4832149 100644 --- a/PomeloChat/ContactsViewController.m +++ b/PomeloChat/ContactsViewController.m @@ -50,7 +50,8 @@ - (void)initEvents { [pomelo onRoute:@"onAdd" withCallback:^(NSDictionary *data){ NSLog(@"user add -----"); - NSString *name = [data objectForKey:@"user"]; + NSDictionary *bodyDic = [data objectForKey:@"body"]; + NSString *name = [bodyDic objectForKey:@"user"]; [self.tableView beginUpdates]; [contactList addObject:name]; NSArray *paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:[contactList count]-1 inSection:0]]; diff --git a/PomeloChat/LoginViewController.m b/PomeloChat/LoginViewController.m index bf0c428..e50c903 100644 --- a/PomeloChat/LoginViewController.m +++ b/PomeloChat/LoginViewController.m @@ -9,6 +9,8 @@ #import "LoginViewController.h" #import "ContactsViewController.h" +#define SERVER_ADDRESS @"192.168.1.15" + @interface LoginViewController () @property (strong, nonatomic) ContactsViewController *contactsViewController; @@ -39,7 +41,7 @@ - (IBAction)login:(id)sender NSString *channel = channelText.text; if (([name length] > 0) && ([channel length] > 0)) { - [pomelo connectToHost:@"127.0.0.1" onPort:3014 withCallback:^(Pomelo *p){ + [pomelo connectToHost:SERVER_ADDRESS onPort:3014 withCallback:^(Pomelo *p){ NSDictionary *params = [NSDictionary dictionaryWithObject:name forKey:@"uid"]; [pomelo requestWithRoute:@"gate.gateHandler.queryEntry" andParams:params andCallback:^(NSDictionary *result){ [pomelo disconnectWithCallback:^(Pomelo *p){ diff --git a/PomeloChat/SocketRocket/SRWebSocket.m b/PomeloChat/SocketRocket/SRWebSocket.m index ef7c65c..4ed5f22 100644 --- a/PomeloChat/SocketRocket/SRWebSocket.m +++ b/PomeloChat/SocketRocket/SRWebSocket.m @@ -309,7 +309,7 @@ - (void)_SR_commonInit; _workQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); _callbackQueue = dispatch_get_main_queue(); - dispatch_retain(_callbackQueue); +// dispatch_retain(_callbackQueue); _readBuffer = [[NSMutableData alloc] init]; _outputBuffer = [[NSMutableData alloc] init]; @@ -329,8 +329,8 @@ - (void)dealloc [_inputStream close]; [_outputStream close]; - dispatch_release(_callbackQueue); - dispatch_release(_workQueue); +// dispatch_release(_callbackQueue); +// dispatch_release(_workQueue); if (_receivedHTTPHeaders) { CFRelease(_receivedHTTPHeaders); diff --git a/README.md b/README.md index f53ef19..8875519 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,25 @@ -pomelo-ioschat -============== +#导语 +最近笔者总是有一颗骚动的心不停地跳跃着,那就是想独立开发一款小型的网游。独立开发网游,简直是我的天!对于个人来说实在太难了,不光要客户端这边搞定,还得把后端服务器这边也得搞定。虽然难,但还是想一试,梦想总要有的,万一实现了呢:-) +首先技术选型,因为笔者对ios的Scene Kit更熟,恰巧ios 8又已出来多年,所以客户端这边我只考虑iOS的话已完全够啦。那服务器端呢,我也是看了一些引擎,最后看下来还是网易的Pomelo框架比较适合我,这款引擎不但完全开源,甚至还有比较不错的线上demo,除了这些nodejs也是我选择的原因,轻量便捷,语法简洁,相信我能学的比较快。 -A chat demo for pomelo [iOS client](https://github.com/NetEase/pomelo-iosclient) +#测试我想要的demo +1.[iOS客户端测试demo](https://github.com/NetEase/pomelo-ioschat) +2.[服务端demo](https://github.com/NetEase/chatofpomelo) -## Install - get the source code +#遇到问题 +1.可能这个iOS demo年代久远的原因,我一运行就挂了,当然毕竟我是专业的ios人员,所以修改了一下,这个ios demo可以跑出来了。修改内容主要如下: +![修改内容](http://upload-images.jianshu.io/upload_images/2197489-ed544759a60d6e24.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) -```bash -git clone git://github.com/NetEase/pomelo-ioschat.git -``` +2.根据[chat源码下载与安装指南](https://github.com/NetEase/pomelo/wiki/chat源码下载与安装),我成功地在本地运行起Game Server。但是当我试图用模拟器登录时,又一次出现了,问题,登录不了,并出现如下错误: +![错误](http://upload-images.jianshu.io/upload_images/2197489-9f29ded62eb89110.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) +在网上查找了一下原因,说是客户端和服务器端socket.io库版本不匹配的原因。查看一下当前Game Server使用的socket.io库版本: +![1](http://upload-images.jianshu.io/upload_images/2197489-8059128392321d56.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) +![2](http://upload-images.jianshu.io/upload_images/2197489-cd555e23dd15735b.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) +当前使用的pomelo2.2.5的库里使用的socket.io 1.0以上的版本,正是因为1.0以上和客户端这边的socket.io不匹配才出现了这个问题。那么有两种方案,一种是升级ios客户端这边socketio库,还有一种是降低pomelo使用的socketio版本。前者笔者尝试了,但没有得到解决,出于能力有限的原因,如果有能解决的朋友希望能指导下我们。这边我只摸索出了第二种解决方法,我查看了一下pomelo的上一个版本: +![1](http://upload-images.jianshu.io/upload_images/2197489-ed6cb5d40d22947e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) +它使用的正是是我们想要的socket.io库1.0以下版本。解决方案如下: +![1](http://upload-images.jianshu.io/upload_images/2197489-6907be7071e180fd.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) -open the project in your xCode (v4.3 +, iOS5 +) - -## Server -the chat server [https://github.com/NetEase/chatofpomelo](https://github.com/NetEase/chatofpomelo) +再次测试后,我们的ios客户端确实可以和服务器通信了,感兴趣的读者可以尝试用自己的iphone手机和ios模拟器进行通讯。 +以下是模拟器和我真机通过pomelo服务器模拟的同一个频道的聊天。 +![demo.gif](http://upload-images.jianshu.io/upload_images/2197489-f61dd60e8c2ac20f.gif?imageMogr2/auto-orient/strip)