随笔分类 -  Obj-c

objc语言相关
摘要:简单描述下需求:游戏要加入事件log,比如玩家升到10级;创建角色;或是,触发这些事件后要求客户端忘后台抛送一条log信息。一般情况下,我们可以直接使用cocos自带的HttpClient(底层用libcurl实现)来处理,但很多时候,我们游戏其他逻辑也在用HttpClient,比如登录、下载资源等... 阅读全文
posted @ 2014-12-26 17:34 haroel 阅读(564) 评论(0) 推荐(0)
摘要:- (BOOL)isJailbroken{ BOOL jailbroken = NO; //判断cydia商店是否存在; NSString *cydiaPath = @"/Applications/Cydia.app"; //判断apt目录存在 NSString *ap... 阅读全文
posted @ 2014-12-08 15:09 haroel 阅读(340) 评论(0) 推荐(0)
摘要:https://github.com/cocos2d/cocos2d-x/pull/8149 阅读全文
posted @ 2014-11-13 14:31 haroel 阅读(240) 评论(0) 推荐(0)
摘要:使得iOS设备震动有两个方法,均是传入kSystemSoundID_Vibrate常量。AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);AudioServicesPlayAlertSound方法在不支持震动的设备上(iPod)会播放一段特殊的声音。AudioServicesPlaySystemSound方法在不支持震动的设备上调用会保持静默。详情可以参考System Sound Services Reference,这两者调用都只对i 阅读全文
posted @ 2014-02-10 10:40 haroel 阅读(333) 评论(0) 推荐(0)
摘要:(cocos2dx版本 2.2.0)用CCEditBox制作帐号输入框,当输入的内容超过框的宽度时,框里面不会显示当前输入的字符,显示上总有一部分字符被分割修改方法如下CCEditBoxImplIOS.mm文件中 ,注掉以下代码@implementation CustomUITextField//- (CGRect)textRectForBounds:(CGRect)bounds {// float padding = CC_EDIT_BOX_PADDING * cocos2d::CCEGLView::sharedOpenGLView()->getScaleX() / [[EAGLVie 阅读全文
posted @ 2014-01-20 15:34 haroel 阅读(1075) 评论(0) 推荐(0)
摘要:1、判断两个日期是否是同一天,不要求小时,分钟要一样 用法NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];BOOL datesAreEqual = [calendar isDate:firstDate equalToDate:secondDate toUnitGranularity:NSDayCalendarUnit];NSCalendar+equalWithGranularity.h#import @interface NSCalendar (equalWit 阅读全文
posted @ 2013-12-10 13:49 haroel 阅读(399) 评论(0) 推荐(0)
摘要:-(BOOL)putStringToItunes:(SKPaymentTransaction*)transaction{ NSData * iapData = transaction.transactionReceipt; NSString*encodingStr = [iapData base64EncodedString]; // NSString *URL=@"https://sandbox.itunes.apple.com/verifyReceipt"; NSString *URL=@"https://buy.itunes.apple.com/verify 阅读全文
posted @ 2013-10-10 09:33 haroel 阅读(625) 评论(0) 推荐(0)
摘要:ios7后mac地址沦为鸡肋,所以必须得重新想办法获取设备的id信息,apple推荐用UUID,但app重新安装后,UUID需要重设,所以想到把UUID存储到ios系统的keychain中,既然存储在系统内,也就意味着即使app被删除也不会丢失该属性。//ios获取uuid#import "KeychainItemWrapper.h" KeychainItemWrapper *keychainItem = [[KeychainItemWrapperalloc] initWithIdentifier:@"UUID" ... 阅读全文
posted @ 2013-09-12 11:48 haroel 阅读(3090) 评论(0) 推荐(0)
摘要:字符串的是连接object-c和c++的最重要元素,以下总结常用的转换方法char * /const char *和NSString之间的转化//char * /const char *转NSStringNSString* strPath = [NSStringstringWithUTF8String:filename];//NSString转char * /const char *constchar* filePathChar = [filePathUTF8String];////////////////////////////////////////////////华丽的分割线////// 阅读全文
posted @ 2013-04-26 12:10 haroel 阅读(310) 评论(0) 推荐(0)
摘要:1.//顺时针旋转180度 splashView.transform=CGAffineTransformMakeRotation(180.0 * M_PI/180);2.注册计时器 timer = [NSTimerscheduledTimerWithTimeInterval:1.3f target:self selector:@selector(timeOutHandler) userInfo:nil repeats:YES];... 阅读全文
posted @ 2013-04-23 15:29 haroel 阅读(160) 评论(0) 推荐(0)
摘要:如何制作 iTunesArtwork?首先有一个 512*512的png格式icon,改名成为iTunesArtwork,然后右键,选择显示简介,如下图done! 阅读全文
posted @ 2013-04-18 15:52 haroel 阅读(883) 评论(0) 推荐(0)
摘要:要用到objc的单例模式,自己写了一个,发现出现内存泄漏,网上找了国外博文的方法,简单实用,于是记录下来头文件@interface ModelLocator : NSObject{ }+(id)sharedModelLocator;mm文件@implementation ModelLocatorstatic ModelLocator * _sharedModel = nil;+ (void)initialize{ if (self == [ModelLocator class]) { _sharedModel = [ [self alloc] init]; ... 阅读全文
posted @ 2013-04-12 10:52 haroel 阅读(159) 评论(0) 推荐(0)
摘要:ios支持unicode emoji字符集(转自http://blog.csdn.net/f520131480315/article/details/6560629)/ue415/ue056/ue057/ue414/ue405/ue106/ue418/ue417/ue40d/ue40a/ue404/ue105/ue409/ue40e/ue402/ue108/ue403/ue058/ue407/ue401/ue40f/ue40b/ue406/ue413/ue411/ue412/ue410/ue107/ue059/ue416/ue408/ue40c/ue11a/ue10c/ue32c/ue32a/ 阅读全文
posted @ 2013-04-10 11:20 haroel 阅读(738) 评论(0) 推荐(0)
摘要:需要在App目录Library/Caches 下创建新目录,创建一个“Map” 目录 NSFileManager *manager = [NSFileManagerdefaultManager]; std::string cacheDirectory = CCFileUtils::sharedFileUtils()->getWriteablePath(); NSString * cachePath = [NSString stringWithCString:cacheDirectory.c_str() encoding:NSUTF8StringEncoding]; NSString * 阅读全文
posted @ 2013-04-09 13:38 haroel 阅读(204) 评论(0) 推荐(0)
摘要:获取IOS设备型号方法 引入头文件#include #include #include "stdlib.h" size_t size; sysctlbyname("hw.machine", NULL, &size, NULL, 0); char* machine = (char*)malloc(size); sysctlbyname("hw.machine", machine, &size, NULL, 0); NSString *platform = [NSString stringWithCString:machi 阅读全文
posted @ 2013-04-09 13:34 haroel 阅读(264) 评论(0) 推荐(0)