CCDevice-ios.mm 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2013-2017 Chukong Technologies Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #include "platform/CCPlatformConfig.h"
  22. #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
  23. #include "platform/CCDevice.h"
  24. #include "base/ccTypes.h"
  25. #include "platform/apple/CCDevice-apple.h"
  26. #include "base/CCEventDispatcher.h"
  27. #include "base/CCEventAcceleration.h"
  28. #include "base/CCDirector.h"
  29. #import <UIKit/UIKit.h>
  30. // Accelerometer
  31. #if !defined(CC_TARGET_OS_TVOS)
  32. #import<CoreMotion/CoreMotion.h>
  33. #endif
  34. #import<CoreFoundation/CoreFoundation.h>
  35. #import <CoreText/CoreText.h>
  36. // Vibrate
  37. #import <AudioToolbox/AudioToolbox.h>
  38. const float MAX_MEASURE_HEIGHT = 10000;
  39. static NSAttributedString* __attributedStringWithFontSize(NSMutableAttributedString* attributedString, CGFloat fontSize)
  40. {
  41. {
  42. [attributedString beginEditing];
  43. [attributedString enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, attributedString.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
  44. UIFont* font = value;
  45. font = [font fontWithSize:fontSize];
  46. [attributedString removeAttribute:NSFontAttributeName range:range];
  47. [attributedString addAttribute:NSFontAttributeName value:font range:range];
  48. }];
  49. [attributedString endEditing];
  50. }
  51. return [[attributedString copy] autorelease];
  52. }
  53. static CGFloat _calculateTextDrawStartHeight(cocos2d::Device::TextAlign align, CGSize realDimensions, CGSize dimensions)
  54. {
  55. float startH = 0;
  56. // vertical alignment
  57. unsigned int vAlignment = ((int)align >> 4) & 0x0F;
  58. switch (vAlignment) {
  59. //bottom
  60. case 2:startH = dimensions.height - realDimensions.height;break;
  61. //top
  62. case 1:startH = 0;break;
  63. //center
  64. case 3: startH = (dimensions.height - realDimensions.height) / 2;break;
  65. default:
  66. break;
  67. }
  68. return startH;
  69. }
  70. static CGSize _calculateShrinkedSizeForString(NSAttributedString **str,
  71. id font,
  72. CGSize constrainSize,
  73. bool enableWrap,
  74. int& newFontSize)
  75. {
  76. CGRect actualSize = CGRectMake(0, 0, constrainSize.width + 1, constrainSize.height + 1);
  77. int fontSize = [font pointSize];
  78. fontSize = fontSize + 1;
  79. if (!enableWrap) {
  80. while (actualSize.size.width > constrainSize.width ||
  81. actualSize.size.height > constrainSize.height) {
  82. fontSize = fontSize - 1;
  83. if(fontSize < 0) {
  84. actualSize = CGRectMake(0, 0, 0, 0);
  85. break;
  86. }
  87. NSMutableAttributedString *mutableString = [[*str mutableCopy] autorelease];
  88. *str = __attributedStringWithFontSize(mutableString, fontSize);
  89. CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)*str);
  90. CGSize targetSize = CGSizeMake(MAX_MEASURE_HEIGHT, MAX_MEASURE_HEIGHT);
  91. CGSize fitSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0, [(*str) length]), NULL, targetSize, NULL);
  92. CFRelease(framesetter);
  93. if (fitSize.width == 0 || fitSize.height == 0) {
  94. continue;
  95. }
  96. actualSize.size = fitSize;
  97. if (constrainSize.width <= 0) {
  98. constrainSize.width = fitSize.width;
  99. }
  100. if (constrainSize.height <= 0) {
  101. constrainSize.height = fitSize.height;
  102. }
  103. if (fontSize <= 0) {
  104. break;
  105. }
  106. }
  107. }
  108. else {
  109. while (actualSize.size.height > constrainSize.height ||
  110. actualSize.size.width > constrainSize.width) {
  111. fontSize = fontSize - 1;
  112. if(fontSize < 0) {
  113. actualSize = CGRectMake(0, 0, 0, 0);
  114. break;
  115. }
  116. NSMutableAttributedString *mutableString = [[*str mutableCopy] autorelease];
  117. *str = __attributedStringWithFontSize(mutableString, fontSize);
  118. CGSize fitSize = [*str boundingRectWithSize:CGSizeMake(constrainSize.width, MAX_MEASURE_HEIGHT)
  119. options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
  120. context:nil].size;
  121. if (fitSize.width == 0 || fitSize.height == 0) {
  122. continue;
  123. }
  124. actualSize.size = fitSize;
  125. if (constrainSize.height <= 0) {
  126. constrainSize.height = fitSize.height;
  127. }
  128. if (constrainSize.width <= 0) {
  129. constrainSize.width = fitSize.width;
  130. }
  131. if (fontSize <= 0) {
  132. break;
  133. }
  134. }
  135. }
  136. newFontSize = fontSize;
  137. return CGSizeMake(ceilf(actualSize.size.width), ceilf(actualSize.size.height));
  138. }
  139. #define SENSOR_DELAY_GAME 0.02
  140. #if !defined(CC_TARGET_OS_TVOS)
  141. @interface CCAccelerometerDispatcher : NSObject<UIAccelerometerDelegate>
  142. {
  143. cocos2d::Acceleration *_acceleration;
  144. CMMotionManager *_motionManager;
  145. }
  146. + (id) sharedAccelerometerDispatcher;
  147. - (id) init;
  148. - (void) setAccelerometerEnabled: (bool) isEnabled;
  149. - (void) setAccelerometerInterval:(float) interval;
  150. @end
  151. @implementation CCAccelerometerDispatcher
  152. static CCAccelerometerDispatcher* s_pAccelerometerDispatcher;
  153. + (id) sharedAccelerometerDispatcher
  154. {
  155. if (s_pAccelerometerDispatcher == nil) {
  156. s_pAccelerometerDispatcher = [[self alloc] init];
  157. }
  158. return s_pAccelerometerDispatcher;
  159. }
  160. - (id) init
  161. {
  162. if( (self = [super init]) ) {
  163. _acceleration = new (std::nothrow) cocos2d::Acceleration();
  164. _motionManager = [[CMMotionManager alloc] init];
  165. _motionManager.accelerometerUpdateInterval = SENSOR_DELAY_GAME;
  166. }
  167. return self;
  168. }
  169. - (void) dealloc
  170. {
  171. s_pAccelerometerDispatcher = nullptr;
  172. delete _acceleration;
  173. [_motionManager release];
  174. [super dealloc];
  175. }
  176. - (void) setAccelerometerEnabled: (bool) isEnabled
  177. {
  178. if (isEnabled)
  179. {
  180. [_motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
  181. [self accelerometer:accelerometerData];
  182. }];
  183. }
  184. else
  185. {
  186. [_motionManager stopAccelerometerUpdates];
  187. }
  188. }
  189. -(void) setAccelerometerInterval:(float)interval
  190. {
  191. _motionManager.accelerometerUpdateInterval = interval;
  192. }
  193. - (void)accelerometer:(CMAccelerometerData *)accelerometerData
  194. {
  195. _acceleration->x = accelerometerData.acceleration.x;
  196. _acceleration->y = accelerometerData.acceleration.y;
  197. _acceleration->z = accelerometerData.acceleration.z;
  198. _acceleration->timestamp = accelerometerData.timestamp;
  199. double tmp = _acceleration->x;
  200. switch ([[UIApplication sharedApplication] statusBarOrientation])
  201. {
  202. case UIInterfaceOrientationLandscapeRight:
  203. _acceleration->x = -_acceleration->y;
  204. _acceleration->y = tmp;
  205. break;
  206. case UIInterfaceOrientationLandscapeLeft:
  207. _acceleration->x = _acceleration->y;
  208. _acceleration->y = -tmp;
  209. break;
  210. case UIInterfaceOrientationPortraitUpsideDown:
  211. _acceleration->x = -_acceleration->y;
  212. _acceleration->y = -tmp;
  213. break;
  214. case UIInterfaceOrientationPortrait:
  215. break;
  216. default:
  217. NSAssert(false, @"unknown orientation");
  218. }
  219. cocos2d::EventAcceleration event(*_acceleration);
  220. auto dispatcher = cocos2d::Director::getInstance()->getEventDispatcher();
  221. dispatcher->dispatchEvent(&event);
  222. }
  223. @end
  224. #endif // !defined(CC_TARGET_OS_TVOS)
  225. //
  226. NS_CC_BEGIN
  227. int Device::getDPI()
  228. {
  229. static int dpi = -1;
  230. if (dpi == -1)
  231. {
  232. float scale = 1.0f;
  233. if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
  234. scale = [[UIScreen mainScreen] scale];
  235. }
  236. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  237. dpi = 132 * scale;
  238. } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  239. dpi = 163 * scale;
  240. } else {
  241. dpi = 160 * scale;
  242. }
  243. }
  244. return dpi;
  245. }
  246. void Device::setAccelerometerEnabled(bool isEnabled)
  247. {
  248. #if !defined(CC_TARGET_OS_TVOS)
  249. [[CCAccelerometerDispatcher sharedAccelerometerDispatcher] setAccelerometerEnabled:isEnabled];
  250. #endif
  251. }
  252. void Device::setAccelerometerInterval(float interval)
  253. {
  254. #if !defined(CC_TARGET_OS_TVOS)
  255. [[CCAccelerometerDispatcher sharedAccelerometerDispatcher] setAccelerometerInterval:interval];
  256. #endif
  257. }
  258. void Device::setGyroScopeEnabled(bool isEnabled){
  259. }
  260. void Device::setGyroScopeInterval(float interval){
  261. }
  262. typedef struct
  263. {
  264. unsigned int height;
  265. unsigned int width;
  266. bool isPremultipliedAlpha;
  267. bool hasShadow;
  268. CGSize shadowOffset;
  269. float shadowBlur;
  270. float shadowOpacity;
  271. bool hasStroke;
  272. float strokeColorR;
  273. float strokeColorG;
  274. float strokeColorB;
  275. float strokeColorA;
  276. float strokeSize;
  277. float tintColorR;
  278. float tintColorG;
  279. float tintColorB;
  280. float tintColorA;
  281. unsigned char* data;
  282. } tImageInfo;
  283. static CGSize _calculateStringSize(NSAttributedString *str, id font, CGSize *constrainSize, bool enableWrap, int overflow)
  284. {
  285. CGSize textRect = CGSizeZero;
  286. textRect.width = constrainSize->width > 0 ? constrainSize->width
  287. : MAX_MEASURE_HEIGHT;
  288. textRect.height = constrainSize->height > 0 ? constrainSize->height
  289. : MAX_MEASURE_HEIGHT;
  290. if (overflow == 1) {
  291. if(!enableWrap) {
  292. textRect.width = MAX_MEASURE_HEIGHT;
  293. textRect.height = MAX_MEASURE_HEIGHT;
  294. } else {
  295. textRect.height = MAX_MEASURE_HEIGHT;
  296. }
  297. }
  298. CGSize dim;
  299. dim = [str boundingRectWithSize:CGSizeMake(textRect.width, textRect.height)
  300. options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
  301. context:nil].size;
  302. dim.width = ceilf(dim.width);
  303. dim.height = ceilf(dim.height);
  304. return dim;
  305. }
  306. static id _createSystemFont( const char * fontName, int size)
  307. {
  308. NSString * fntName = [NSString stringWithUTF8String:fontName];
  309. // On iOS custom fonts must be listed beforehand in the App info.plist (in order to be usable) and referenced only the by the font family name itself when
  310. // calling [UIFont fontWithName]. Therefore even if the developer adds 'SomeFont.ttf' or 'fonts/SomeFont.ttf' to the App .plist, the font must
  311. // be referenced as 'SomeFont' when calling [UIFont fontWithName]. Hence we strip out the folder path components and the extension here in order to get just
  312. // the font family name itself. This stripping step is required especially for references to user fonts stored in CCB files; CCB files appear to store
  313. // the '.ttf' extensions when referring to custom fonts.
  314. fntName = [[fntName lastPathComponent] stringByDeletingPathExtension];
  315. // create the font
  316. id font = [UIFont fontWithName:fntName size:size];
  317. if (!font)
  318. {
  319. font = [UIFont systemFontOfSize:size];
  320. }
  321. return font;
  322. }
  323. static bool _initWithString(const char * text, cocos2d::Device::TextAlign align, const char * fontName, int size, tImageInfo* info, bool enableWrap, int overflow)
  324. {
  325. bool bRet = false;
  326. do
  327. {
  328. CC_BREAK_IF(! text || ! info);
  329. id font = _createSystemFont(fontName, size);
  330. CC_BREAK_IF(! font);
  331. NSString * str = [NSString stringWithUTF8String:text];
  332. CC_BREAK_IF(!str);
  333. CGSize dimensions;
  334. dimensions.width = info->width;
  335. dimensions.height = info->height;
  336. NSTextAlignment nsAlign = FontUtils::_calculateTextAlignment(align);
  337. NSMutableParagraphStyle* paragraphStyle = FontUtils::_calculateParagraphStyle(enableWrap, overflow);
  338. paragraphStyle.alignment = nsAlign;
  339. // measure text size with specified font and determine the rectangle to draw text in
  340. UIColor *foregroundColor = [UIColor colorWithRed:info->tintColorR
  341. green:info->tintColorG
  342. blue:info->tintColorB
  343. alpha:info->tintColorA];
  344. // adjust text rect according to overflow
  345. NSMutableDictionary* tokenAttributesDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
  346. foregroundColor,NSForegroundColorAttributeName,
  347. font, NSFontAttributeName,
  348. paragraphStyle, NSParagraphStyleAttributeName, nil];
  349. NSAttributedString *stringWithAttributes =[[[NSAttributedString alloc] initWithString:str
  350. attributes:tokenAttributesDict] autorelease];
  351. int shrinkFontSize = size;
  352. CGSize realDimensions;
  353. if (overflow == 2) {
  354. realDimensions = _calculateShrinkedSizeForString(&stringWithAttributes, font, dimensions, enableWrap, shrinkFontSize);
  355. } else {
  356. realDimensions = _calculateStringSize(stringWithAttributes, font, &dimensions, enableWrap, overflow);
  357. }
  358. CC_BREAK_IF(realDimensions.width <= 0 || realDimensions.height <= 0);
  359. if (dimensions.width <= 0) {
  360. dimensions.width = realDimensions.width;
  361. }
  362. if (dimensions.height <= 0) {
  363. dimensions.height = realDimensions.height;
  364. }
  365. // compute start point
  366. CGFloat yPadding = _calculateTextDrawStartHeight(align, realDimensions, dimensions);
  367. CGFloat xPadding = FontUtils::_calculateTextDrawStartWidth(align, realDimensions, dimensions);
  368. NSInteger POTWide = dimensions.width;
  369. NSInteger POTHigh = dimensions.height;
  370. CGRect textRect = CGRectMake(xPadding, yPadding,
  371. realDimensions.width, realDimensions.height);
  372. NSUInteger textureSize = POTWide * POTHigh * 4;
  373. unsigned char* data = (unsigned char*)malloc(sizeof(unsigned char) * textureSize);
  374. memset(data, 0, textureSize);
  375. // draw text
  376. CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  377. CGContextRef context = CGBitmapContextCreate(data,
  378. POTWide,
  379. POTHigh,
  380. 8,
  381. POTWide * 4,
  382. colorSpace,
  383. kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
  384. if (!context)
  385. {
  386. CGColorSpaceRelease(colorSpace);
  387. CC_SAFE_FREE(data);
  388. break;
  389. }
  390. // text color
  391. CGContextSetRGBFillColor(context,
  392. info->tintColorR,
  393. info->tintColorG,
  394. info->tintColorB,
  395. info->tintColorA);
  396. // move Y rendering to the top of the image
  397. CGContextTranslateCTM(context, 0.0f, POTHigh);
  398. //NOTE: NSString draws in UIKit referential i.e. renders upside-down compared to CGBitmapContext referential
  399. CGContextScaleCTM(context, 1.0f, -1.0f);
  400. // store the current context
  401. UIGraphicsPushContext(context);
  402. CGColorSpaceRelease(colorSpace);
  403. CGContextSetShouldSubpixelQuantizeFonts(context, false);
  404. CGContextBeginTransparencyLayerWithRect(context, textRect, NULL);
  405. if ( info->hasStroke )
  406. {
  407. CGContextSetTextDrawingMode(context, kCGTextStroke);
  408. UIColor *strokeColor = [UIColor colorWithRed:info->strokeColorR
  409. green:info->strokeColorG
  410. blue:info->strokeColorB
  411. alpha:info->strokeColorA];
  412. NSMutableDictionary* tokenAttributesDict2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
  413. foregroundColor,NSForegroundColorAttributeName,
  414. font, NSFontAttributeName,
  415. paragraphStyle, NSParagraphStyleAttributeName, nil];
  416. [tokenAttributesDict2 setObject:[NSNumber numberWithFloat: info->strokeSize / shrinkFontSize * 100]
  417. forKey:NSStrokeWidthAttributeName];
  418. [tokenAttributesDict2 setObject:strokeColor forKey:NSStrokeColorAttributeName];
  419. NSAttributedString *strokeString =[[[NSAttributedString alloc] initWithString:str
  420. attributes:tokenAttributesDict2] autorelease];
  421. if(overflow == 2){
  422. _calculateShrinkedSizeForString(&strokeString, font, dimensions, enableWrap, shrinkFontSize);
  423. }
  424. [strokeString drawInRect:textRect];
  425. }
  426. CGContextSetTextDrawingMode(context, kCGTextFill);
  427. // actually draw the text in the context
  428. [stringWithAttributes drawInRect:textRect];
  429. CGContextEndTransparencyLayer(context);
  430. // pop the context
  431. UIGraphicsPopContext();
  432. // release the context
  433. CGContextRelease(context);
  434. // output params
  435. info->data = data;
  436. info->isPremultipliedAlpha = true;
  437. info->width = static_cast<int>(POTWide);
  438. info->height = static_cast<int>(POTHigh);
  439. bRet = true;
  440. } while (0);
  441. return bRet;
  442. }
  443. Data Device::getTextureDataForText(const char * text, const FontDefinition& textDefinition, TextAlign align, int &width, int &height, bool& hasPremultipliedAlpha)
  444. {
  445. Data ret;
  446. do {
  447. tImageInfo info = {0};
  448. info.width = textDefinition._dimensions.width;
  449. info.height = textDefinition._dimensions.height;
  450. info.hasShadow = textDefinition._shadow._shadowEnabled;
  451. info.shadowOffset.width = textDefinition._shadow._shadowOffset.width;
  452. info.shadowOffset.height = textDefinition._shadow._shadowOffset.height;
  453. info.shadowBlur = textDefinition._shadow._shadowBlur;
  454. info.shadowOpacity = textDefinition._shadow._shadowOpacity;
  455. info.hasStroke = textDefinition._stroke._strokeEnabled;
  456. info.strokeColorR = textDefinition._stroke._strokeColor.r / 255.0f;
  457. info.strokeColorG = textDefinition._stroke._strokeColor.g / 255.0f;
  458. info.strokeColorB = textDefinition._stroke._strokeColor.b / 255.0f;
  459. info.strokeColorA = textDefinition._stroke._strokeAlpha / 255.0f;
  460. info.strokeSize = textDefinition._stroke._strokeSize;
  461. info.tintColorR = textDefinition._fontFillColor.r / 255.0f;
  462. info.tintColorG = textDefinition._fontFillColor.g / 255.0f;
  463. info.tintColorB = textDefinition._fontFillColor.b / 255.0f;
  464. info.tintColorA = textDefinition._fontAlpha / 255.0f;
  465. if (! _initWithString(text, align, textDefinition._fontName.c_str(), textDefinition._fontSize, &info, textDefinition._enableWrap, textDefinition._overflow))
  466. {
  467. break;
  468. }
  469. height = info.height;
  470. width = info.width;
  471. ret.fastSet(info.data,width * height * 4);
  472. hasPremultipliedAlpha = true;
  473. } while (0);
  474. return ret;
  475. }
  476. void Device::setKeepScreenOn(bool value)
  477. {
  478. [[UIApplication sharedApplication] setIdleTimerDisabled:(BOOL)value];
  479. }
  480. /*!
  481. @brief Only works on iOS devices that support vibration (such as iPhone). Should only be used for important alerts. Use risks rejection in iTunes Store.
  482. @param duration ignored for iOS
  483. */
  484. void Device::vibrate(float duration)
  485. {
  486. // See http://stackoverflow.com/questions/4724980/making-the-iphone-vibrate
  487. // should vibrate no matter it is silient or not
  488. if([[UIDevice currentDevice].model isEqualToString:@"iPhone"])
  489. {
  490. AudioServicesPlaySystemSound (1352); //works ALWAYS as of this post
  491. }
  492. else
  493. {
  494. // Not an iPhone, so doesn't have vibrate
  495. // play the less annoying tick noise or one of your own
  496. AudioServicesPlayAlertSound (kSystemSoundID_Vibrate);
  497. }
  498. }
  499. NS_CC_END
  500. #endif // CC_PLATFORM_IOS