Archive for the ‘iPhone’ Category

28
Aug

Here are some of the build quick keys in XCode.

Command+Return – This builds and launches the application in debug mode.
Shift+Command+Return – Kills the running application in the simulator.
Shift+Command+k – Cleans the build target.
Shift+Command+a – Build and Analyze.
This invokes the static analyzer to help spot memory issues in your code.

, , , , , ,

28
Aug

Some commands don’t have quick keys. XCode (like most OSX applications) allow you to define your own quick keys and here’s how.

  1. Open up the XCode Preference
  2. Click on the Key Bindings tab
  3. Navigate to the command that you want to bind keys for.
  4. Once you have found the command, double click in the Key column
  5. Press the keys that you wish to bind
  6. If there are any conflicts, XCode will let you know. Otherwise, press apply and you’re good to go

, , , ,

26
Aug

For getting touches begin,moved and ended in corona,

--Your touch event listener
 local function TouchListener( event )
        if event.phase == "began" then
            print( "Touched!" )
        elseif event.phase == "moved" then
            print( "Moved!" )
        elseif event.phase == "ended" then
            print( "Ended!" )
        end
    end
--Adding an event listener for touch
Runtime:addEventListener( "touch", TouchListener )

,

26
Aug

For adding a label to an image in corona,

local Group = display.newGroup()

local Image = display.newImageRect('image.png',80,80)
Image.x = 180
Image.y = 280

local Text = display.newText( "Text", 0, 0, "Helvetica", 18 )
Text:setTextColor( 0, 0, 0, 255 )

-- insert items into group, in the order you want them displayed:
Group:insert( Image )
Group:insert( Text )

, , , ,

26
Aug

For getting touch location in corona,

local function TouchListener( event )

        if event.phase == "began" then

        --Touch coordinates can be accessed by event.x/event.y properties of touch event

            print ("Touch X = #"..event.x)

            print ("Touch Y = #"..event.y)

        end

    end

--Adding an event listener for touch

Runtime:addEventListener( "touch", TouchListener )

, ,

25
Aug

Here is how to create an MD5 (Message-Digest Algorithm) of NSData in xcode

Create Interface with fileName as NSData+MD5

@interface NSData(MD5)

- (NSString *)MD5;

@end

Implementing the interface

#import <CommonCrypto/CommonDigest.h>

@implementation NSData(MD5)

- (NSString*)MD5

{

// Creating byte array of unsigned characters

unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];

// Creating 16 byte MD5 hash value and storing it in buffer

CC_MD5(self.bytes, self.length, md5Buffer);

// Converting MD5 value from the buffer to NSString of hex values

NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];

for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)

[output appendFormat:@"%02x",md5Buffer[i]];

//Returning the string hex values

return output;

}

@end

 

How to call the MD5 method

Import NSData+MD5.h into the place where you want to create MD5

Now call the MD5 method using the NSData object as follows

 

NSString *path = [[NSBundle mainBundle] pathForResource:@"sampleFile" ofType:@"txt"];

NSData *theData = [NSData dataWithContentsOfFile:path];

if (theData)

NSLog(@"%@", [theData MD5]);

, , , , , , , , , , , ,

25
Aug

Here is how to create an MD5 (Message-Digest Algorithm) of NSString in xcode

Create Interface with fileName as NSString+MD5

@interface NSString(MD5)

- (NSString *)MD5;

@end

Implementing the interface

#import <CommonCrypto/CommonDigest.h>

@implementation NSString(MD5)

- (NSString*)MD5

{

// Creating the pointer to the string as UTF8String

const char *ptr = [self UTF8String];

// Creating byte array of unsigned characters

unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];

// Creating 16 byte MD5 hash value and storing it in buffer

CC_MD5(ptr, strlen(ptr), md5Buffer);

// Converting MD5 value from the buffer to NSString of hex values

NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];

for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)

[output appendFormat:@"%02x",md5Buffer[i]];

//Returning the string hex values

return output;

}

@end

 

How to call the MD5 method

Import NSString+MD5.h into the place where you want to create MD5

Now call the MD5 method using the NSString object as follows

 

NSString *toConvertString = @”the string to convert to MD5″;

NSLog(@”Converted str -> %@”, [toConvertString MD5]);

, , , , , , , , , , , , ,

25
Aug

Include the following in the project where you need to use this.

#define UIColorFromHEXValue(hexValue) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0 green:((float)((hexValue & 0xFF00) >> 8))/255.0 blue:((float)(hexValue & 0xFF))/255.0 alpha:1.0]

Adding this will make the method UIColorFromHEXValue available throughout the class.

Now you can call this method when you need to convert hexadecimal colorcode to UIColor. If you want to convert hex value FFFFFF to UIColor, then then use it like this.

UIColorFromRGB(0xFFFFFF)  - This will return UIColor corresponding to hex colorcode FFFFFF.

 

 

, , , , , , , , ,

10
Aug

Consider a NSMutableArray object named mutableFixtureArray.

NSValue *bodyVal = [NSValue valueWithPointer:ballFixture]; //Converting the fixture of the body we need to add to the array to NSValue.

[mutableFixtureArray addObject:bodyVal]; //Adding the NSValue corresponding to the fixture to the mutableArray.

 

Getting the body back from the NSMutableArray

NSValue *val = [mutableFixtureArray objectAtIndex:0]; //Copying the value in the array at a particular index(here zero) to a NSValue object.

b2Fixture *currentFixture;

[val getValue:&currentFixture];//Assigning the fixture value from the array to the b2Fixture object. Now the currentFixture contains the fixture stored into the array.

b2Body *theBody;

theBody = currentFixture->GetBody(); //Getting the body from the fixture.

 

, , , , , , , , , , ,

10
Aug

You should enable RetinaDisplay mode ONLY if you want to use HighRes images on an iPhone4. Remember that an iPhone4 also works in “low res” mode.

// Add this code in your Application Delegate, right after initializing the director

// Director Initialization
[director setOpenGLView:glView];

// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
	CCLOG(@"Retina Display Not supported");

then keep both normal and hd images (with extension image-hd.png).

, , , , , , , , ,