Archive for the ‘iPhone’ Category

31
Jan
+(BOOL)isOS4{
	NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"4.0" options: NSNumericSearch];
	if (order == NSOrderedSame || order == NSOrderedDescending) {
		return YES;
	} else {
		return NO;
	}
}

31
Jan
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

31
Jan
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod')) {
    header('Location: http://yoursite.com/iphone');
    exit();
}

31
Jan

When developing for the iPhone and the iPod Touch, the first thing we have to do is obviously detect it, so we can apply specific code or styles to it. The following code snippets will detect iPhones and iPods using Javascript, and redirect those users to an iPhone specific page.

if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
    if (document.cookie.indexOf("iphone_redirect=false") == -1) {
        window.location = "http://.................";
    }
}

31
Jan
[self performSelector:@selector(method name) withObject:(id) afterDelay:(delay)];

31
Jan

First , pre-load the audio,

[[SimpleAudioEngine sharedEngine]preloadEffect:@"good.mp3"];

To play audio,

[[SimpleAudioEngine sharedEngine] playEffect:@"good.mp3"];

31
Jan
CCParticleSystemQuad *explosionEffect = [CCParticleSystemQuad particleWithFile:@"explosion.plist"];
explosionEffect.life = 0.8;
explosionEffect.duration = 0.8;
explosionEffect.scaleX=0.8;
explosionEffect.scaleY=0.45;
[self addChild:explosionEffect ];
explosionEffect.autoRemoveOnFinish = YES;

31
Jan

First, download CCRadioMenu.h and CCRadioMenu.mĀ and drag them to the Classes directory of your project. Then add the following import to the top of HelloWorldScene.m:

#import"CCRadioMenu.h"

And the following to your init method:

CCMenuItem *menuItem1 = [CCMenuItemImage itemFromNormalImage:@"Button1.png"
selectedImage:@"Button1Sel.png" target:self selector:@selector(button1Tapped:)];
CCMenuItem *menuItem2 = [CCMenuItemImage itemFromNormalImage:@"Button2.png"
selectedImage:@"Button2Sel.png" target:self selector:@selector(button2Tapped:)];
CCMenuItem *menuItem3 = [CCMenuItemImage itemFromNormalImage:@"Button3.png"
selectedImage:@"Button3Sel.png" target:self selector:@selector(button3Tapped:)];
CCRadioMenu *radioMenu = [CCRadioMenu menuWithItems:menuItem1, menuItem2, menuItem3, nil];
radioMenu.position = ccp(120, 180);
[radioMenu alignItemsHorizontally];
radioMenu.selectedItem = menuItem1;
[menuItem1 selected];
[self addChild:radioMenu];

The CCMenuItemImages are created as usual, but instead of adding them to a CCMenu they are added to the new CCRadioMenu class. This class makes sure only one is selected at a time.The first item is also set to be selected by default at start.
Add the callback methods:

- (void)button1Tapped:(id)sender {
[_label setString:@"Last button: 1"];
}

- (void)button2Tapped:(id)sender {
[_label setString:@"Last button: 2"];
}

- (void)button3Tapped:(id)sender {
[_label setString:@"Last button: 3"];
}

31
Jan

Steps

1-Add the CCScroll Layer.h and .m files to your project folder.

2-Import the .h file to your file.

3-If you want to add two items in the Scroller,make two Sublayers

CCLayer *itemLayer1=[[CCLayer alloc] init];

CCLayer *itemLayer2=[[CCLayer alloc] init];

4-Create the two items you want to display

Let it be two sprites – item1 and item2.

5-Now add the items to the Sublayer.

[itemLayer1 addChild:item1];

[itemLayer2 addChild:item2];

6-Now create the scroller and add the layers.

CCScrollLayer *scroller = [[CCScrollLayer alloc] initWithLayers:[NSMutableArray arrayWithObjects:itemLayer1,itemLayer2,nil] widthOffset:200];

So the scroll view is now ready.

There are also other methods to create a scroll view,but this method seems very simple.

31
Jan
UITapGestureRecognizer *twoFingersTwoTaps =

[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersTwoTaps)] autorelease];

[twoFingersTwoTaps setNumberOfTapsRequired:2];

[twoFingersTwoTaps setNumberOfTouchesRequired:2];

[[self view] addGestureRecognizer:twoFingersTwoTaps];