Fork me on GitHub

2012年5月15日

摘要: 使用NSStream来实现Socket#import <Foundation/Foundation.h> #import <CFNetwork/CFNetwork.h>#import <SystemConfiguration/SystemConfiguration.h>#import <netinet/in.h>#import <arpa/inet.h>@interface Stream : NSObject { NSInputStream *inStream; NSOutputStream *outStream; NSMutable 阅读全文
posted @ 2012-05-15 20:41 pengyingh 阅读(594) 评论(0) 推荐(0)
摘要: 正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串、将匹配的子串做替换或者从某个串中取出符合某个条件的子串等。列目录时, dir *.txt或ls *.txt中的*.txt就不是一个正则表达式,因为这里*与正则式的*的含义是不同的。为便于理解和记忆,先从一些概念入手,所有特殊字符或字符组合有一个总表在后面,最后一些例子供理解相应的概念。正则表达式是由普通字符(例如字符 a 到 z)以及特殊字符(称为元字符)组成的文字模式。正则表达式作为一个模板,将某个字符模式与所搜索的字符串进行匹配。可以通过在一对分隔符之间放入表达式模式的各种组件 阅读全文
posted @ 2012-05-15 20:27 pengyingh 阅读(227) 评论(0) 推荐(0)
摘要: 在XCODE编译项目之后,会在app旁看见一个同名的dSYM文件.他是一个编译的中转文件,简单说就是debug的symbols包含在这个文件中.他有什么作用? 当release的版本 crash的时候,会有一个日志文件,包含出错的内存地址, 使用symbolicatecrash工具能够把日志和dSYM文件转换成可以阅读的log信息,也就是将内存地址,转换成程序里的函数或变量和所属于的 文件名.有一篇详细的blog讲了这个过程http://www.anoshkin.net/blog/2008/09/09/iphone-crash-logs/将类似Thread 0 Crashed:0 libobj 阅读全文
posted @ 2012-05-15 20:25 pengyingh 阅读(2602) 评论(0) 推荐(0)
摘要: @interface NSManagedObject (FirstLetter)- (NSString *)uppercaseFirstLetterOfName;@end@implementation NSManagedObject (FirstLetter)- (NSString *)uppercaseFirstLetterOfName {[self willAccessValueForKey:@"uppercaseFirstLetterOfName"];NSString *aString = [[self valueForKey:@"ContactName&q 阅读全文
posted @ 2012-05-15 20:24 pengyingh 阅读(210) 评论(0) 推荐(0)
摘要: 果SDK自带的就有密码保护,使用方法很简单,如下:1、引入Security.frameWork框架。2、引入头文件:SFHKeychainUtils.h.3、存密码:[SFHFKeychainUtilsstoreUsername:@"dd"andPassword:@"aa"forServiceName:SERVICE_NAMEupdateExisting:1error:nil];[SFHFKeychainUtilsdeleteItemForUsername:@"dd"andServiceName:SERVICE_NAMEerror:n 阅读全文
posted @ 2012-05-15 20:22 pengyingh 阅读(260) 评论(0) 推荐(0)
摘要: 上个月,Bolt Creative宣布他们99美分的Pocket God游戏销量达到了120万份。这个游戏是1月份发布的,3月份排名达到了第一名,并保持这个位置大概一个月。这个游戏依然在前10名中。Pocket God是小团队在iPhone上取得成功的最新例子。这款游戏由Dave Castelnuovo的创建人Bolt Creative和他的美术Allan Dye一起开发。在竞争强烈的AppStore中,你的游戏或应用如何在iPhone取得成功?下面是Castelnuovo提供的10个方法。1、选择你能够完成的项目成为独立的开发者是非常辛苦的。我们大多数都是在周末和晚上进行自己的梦想工程,期盼 阅读全文
posted @ 2012-05-15 20:21 pengyingh 阅读(165) 评论(0) 推荐(0)
摘要: 有时候你的程序需要知道用户使用的设备是iPhone还是iPod。因为有些特性iPod是没有的,比如电话功能。方法很简单:NSString *deviceType = [UIDevice currentDevice].model;如果你想得到一个本地化的字符串,可以使用以下命令:NSString *deviceType = [UIDevice currentDevice].localizedModel;NSLog(@”type: %@”, deviceType);JavaScrpit代码:if((navigator.userAgent.match(/iPhone/i)) || (navigato 阅读全文
posted @ 2012-05-15 20:19 pengyingh 阅读(442) 评论(0) 推荐(0)
摘要: 判断 iPhone 是否插入了 SIM 卡,可以参考苹果官网的 systemconfigure framework 教程,将下面的代码复制到头文件extern NSString* const kCTSMSMessageReceivedNotification;extern NSString* const kCTSMSMessageReplaceReceivedNotification;extern NSString* const kCTSIMSupportSIMStatusNotInserted;extern NSString* const kCTSIMSupportSIMStatusRead 阅读全文
posted @ 2012-05-15 20:19 pengyingh 阅读(452) 评论(0) 推荐(0)
摘要: -(void)drawRect:(CGRect)rect {NSString* imageName = [[NSString alloc]initWithFormat:@”b%d.png”,m_Index];UIImage* aImage = [UIImage imageNamed:imageName];[imageName release];int width = aImage.size.width;int height = aImage.size.height;CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();CGCont 阅读全文
posted @ 2012-05-15 20:19 pengyingh 阅读(282) 评论(0) 推荐(0)
摘要: 发现很多砸几百万、几千万甚至上亿的投入做游戏失败的,大都是没有认真做好DEMO。DEMO可是个好东西,做游戏想赚钱、想省钱,非它不可。但它既区别于小说的提纲,也区别于摘要。那DEMO到底是什么呢?从预算来说,开发DEMO的预算不要超过整体预算的30%;如果DEMO的预算超过了30%,估计开发者、项目经理从心里就没有勇气砍掉这个项目了,他们经常会说:大钱都花了,索性把后面的小钱也花了,万一赚钱呢!万一是个好产品呢。自己骗自己,自己给自己编美好的未来了。这30%着实是心理防线。从时间上来说,开发DEMO的时间不要超过2个月,也不要超过整个项目时间的20%。手机游戏开发团队,不少公司都是很小型的公司 阅读全文
posted @ 2012-05-15 20:17 pengyingh 阅读(410) 评论(0) 推荐(0)
摘要: UUID含义是通用唯一识别码 (Universally Unique Identifier),这 是一个软件建构的标准,也是被开源软件基金会 (Open Software Foundation, OSF) 的组织应用在分布式计算环境(Distributed Computing Environment, DCE) 领域的一部份。UUID 的目的,是让分布式系统中的所有元素,都能有唯一的辨识资讯,而不需要透过中央控制端来做辨识资讯的指定。如此一来,每个人都可以建立不与其它人冲突的 UUID。在这样的情况下,就不需考虑数据库建立时的名称重复问题。目前最广泛应用的 UUID,即是微软的 Microso 阅读全文
posted @ 2012-05-15 20:16 pengyingh 阅读(2901) 评论(1) 推荐(1)
摘要: 在 iPhone 应用或者是游戏的开发过程中,对声音的支持是必不可少的。在我做过的几个应用中,每个都涉及到音效,所以在这里做个简单的归纳,很多都是引用自《iPhone Application Programming Guide》(需要有 Apple ID 才能打开链接),加了一些实际使用的经验。iPhone OS 主要提供以下了几种播放音频的方法:System Sound ServicesAVAudioPlayer 类Audio Queue ServicesOpenAL1. System Sound ServicesSystem Sound Services 是最底层也是最简单的声音播放服务, 阅读全文
posted @ 2012-05-15 20:14 pengyingh 阅读(237) 评论(0) 推荐(0)
摘要: <script type=”text/javascript”>function OnLoad(){document.documentElement.style.webkitTouchCallout = “none”;}</script> 阅读全文
posted @ 2012-05-15 20:12 pengyingh 阅读(187) 评论(0) 推荐(0)
摘要: @implementationNSString (PasteboardGoodies)- (void) sendToPasteboard{[[NSPasteboardgeneralPasteboard]declareTypes: [NSArrayarrayWithObject:NSStringPboardType]owner:nil];[[NSPasteboardgeneralPasteboard]setString:selfforType:NSStringPboardType];}// sendToPasteboard@end// PasteboardGoodiesNSPasteboard 阅读全文
posted @ 2012-05-15 20:12 pengyingh 阅读(519) 评论(0) 推荐(0)
摘要: AirPrint 是苹果 iOS 系统自带的无线打印功能,阅读、新闻等类型的应用内如能集成 AirPrint,会给消费者带来极大便利。CocoaChina 会员分享了在应用里加入 AirPrint 功能的方法,希望下面的代码能为相关应用的开发者们节省时间。NSString *path = [[NSBundle mainBundle] pathForResource:@”test” ofType:@”jpg”];NSData *data = [NSData dataWithContentsOfFile: path];UIPrintInteractionController *pic = [UIP 阅读全文
posted @ 2012-05-15 20:10 pengyingh 阅读(351) 评论(0) 推荐(0)
摘要: UIAccelerometer *accelerometer =[UIAccelerometer sharedAccelerometer];accelerometer.delegate =self;accelerometer.updateInterval =1.0f/60.0f;- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{if(fabs(acceleration.x)>2.0||fabs(acceleration.y)>2.0| 阅读全文
posted @ 2012-05-15 20:09 pengyingh 阅读(163) 评论(0) 推荐(0)
摘要: (1.给图层添加背景图片:myView.layer.contents = (id)[UIImage imageNamed:@"view_BG.png"].CGImage;(2.将图层的边框设置为圆脚myWebView.layer.cornerRadius = 8;myWebView.layer.masksToBounds = YES;(3.给图层添加一个有色边框myWebView.layer.borderWidth = 5;myWebView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0. 阅读全文
posted @ 2012-05-15 20:08 pengyingh 阅读(179) 评论(0) 推荐(0)
摘要: [timer release] only needs to be called if you “own” the timer. From Apple’s documentation:Because the run loop maintains the timer, from the perspective of memory management there’s typically no need to keep a reference to a timer once you’ve scheduled it. Since the timer is passed as an argument w 阅读全文
posted @ 2012-05-15 20:06 pengyingh 阅读(1098) 评论(0) 推荐(0)
摘要: 本文介绍Objective C中实现观察者模式(也被称为广播者/监听者、发布/注册或者通知)的五种方法以及每种方法的价值所在。该文章将包括:1 手动广播者和监听者(Broadcaster and listeners)2 键-值观察(Key Value Observing)3 通知中心(Notification center)4 上下文通知(Context notification)5 用于观察的委托(Delegate)关于观察者观察者模式是维持两个模块之间抽象关系的最强大的方式之一。观察者模式包括一个发布已发生事件的模块以及响应该事件的另一模块的若干个的实例。它和直接调 用第二个模块的方法不同 阅读全文
posted @ 2012-05-15 20:05 pengyingh 阅读(309) 评论(0) 推荐(0)
摘要: 1、确定你的项目工程的resouce下有你要用的字体文件(.ttf,.odf)。2、 然后在你的工程的Info.plist文件中新建一行(Add Row),添加key为:UIAppFonts,类型为Array或Dictionary都行;在UIAppFonts下再建立一个键值对,key 为:Item 0,添加Value为XXX.ttf(你字体的名字,string型),可以添加多个,使用的时候写对应字体名字就行。3、在你的项目里要用字体的时候 xx.font = [UIFont fontWithName:@"XXX" size:20.0],这样就可以了 阅读全文
posted @ 2012-05-15 20:04 pengyingh 阅读(260) 评论(0) 推荐(0)
摘要: http://www.10bay.com/一般来说UINavigationController是作为UIWindow的子view来使用的,例如当你创建一个Navigation类型的应用程序时,系统会将AppDelegate中的navigationController做为window的根控制器self.window.rootViewController = self.navigationController; [self.window.makeKeyAndVisible];UINavigationController在放置自己的位置时,会默认考虑到状态条,并在顶部留出20px的空白位置。但是当将 阅读全文
posted @ 2012-05-15 19:31 pengyingh 阅读(1191) 评论(0) 推荐(0)
摘要: ModalViewController可以有不同的呈现类型(modalPresentationStyle),在ipad下要提供多方向支持时,就要注意可能要改变ModalViewController的呈现方式,列举如下:1. UIModalPresentationFullScreen:全屏模式,即弹出窗口占满整个屏幕,在portrait模式和landscape模式下都一样。2. UIModalPresentationFormSheet:会将窗口缩小,使之居于屏幕中间,在portrait和landscape下都一样,但要注意landscape下如果软键盘出现,窗口位置会调整。3. UIModalP 阅读全文
posted @ 2012-05-15 19:29 pengyingh 阅读(623) 评论(0) 推荐(0)
摘要: rom:http://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-way/Recently, I was working on a project which required detection of tap and events on the UIWebView. We wanted to find out the HTML element on which the user taps in the UIWebView and then depending on the element tapp 阅读全文
posted @ 2012-05-15 19:28 pengyingh 阅读(489) 评论(0) 推荐(0)
摘要: http://www.10bay.com/?p=149[[session inputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];因主线程有事务要处理,会阻塞主线程外设事件的触发;解决:“将socket的runloopsource添加到新开的线程的runloop中,并在新线程中显示启动runloop就可以了”创建一个线程,取得它的runloop,然后用类似上面的代码将其加入,这样就不会阻塞接收数据事件的回调了。即[NSThread detachNewThreadSelec.. 阅读全文
posted @ 2012-05-15 19:25 pengyingh 阅读(618) 评论(0) 推荐(0)
摘要: I'm trying to useCommonCryptoto generate keys usingPBKDF2but I can't seem to importCommonCrypto/CommonKeyDerivation.h, I just errors that it is not found.Any ideas?edit: I should probably mention I have already added the security framework and I can import all of the otherCommonCryptoheaders 阅读全文
posted @ 2012-05-15 12:01 pengyingh 阅读(3373) 评论(1) 推荐(0)
摘要: ask: I want to upload an image to server .I know to convert image ti NSData and then send it to server but is there any way to send complete image from your bundle to server without byte conversion? If there is a way i will be thankful if someone provide me details about thisanswer:Any thing that ha 阅读全文
posted @ 2012-05-15 11:58 pengyingh 阅读(267) 评论(0) 推荐(0)
摘要: Apple Keychain Services offer a secure means to store sensitive information. Through the keychain, all the hardwork is managed for you to store and retrieve content. As powerful as the keychain services are, I was recently tinkering with some code to see if I could obfuscate content within an applic 阅读全文
posted @ 2012-05-15 11:00 pengyingh 阅读(441) 评论(0) 推荐(0)
摘要: Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一。Base64 主要不是加密,它主要的用途是把一些二进制数转成普通字符用于网络传输。由于一些二进制字符在传输协议中属于控制字符,不能直接传送需要转换一下。最常见的用途是作为电子邮件或WebService附件的传输编码#import<CommonCrypto/CommonCryptor.h>#import"GTMBase64.h"//Opensource,base64处理,就两个文件,自己从网上下载下吧+(NSString*)TripleDES:(NSString*)plainTextencrypt 阅读全文
posted @ 2012-05-15 09:16 pengyingh 阅读(3021) 评论(0) 推荐(0)

导航