Swift

How to Create World in Box2D in iOS Game Development(iPhone,iPad)

Here Lets have a look creating world in box2D.
Every Box2D program begins with the creation of a b2World object. b2World is the physics hub that
manages memory, objects, and simulation. You can allocate the physics world on the stack, heap, or
data section.
in Header file Create an object for World like this,

b2World *myWorld;
in .mm file create the world

first we have to create gravity.

b2Vec2 gravity = new b2Vec2(0.0f,-10.0f);

and set the sleep parameter for world
bool doSleep = true;

Now , lets create world object

myWorld = new b2World(gravity,doSleep);

Delete World:
when your app exits you have to destroy the world what you have created

delete myWorld;
In next ,lets add some stuff into world

Box2D physics engine for iOS Game Development

Here Devs, When we are about to create a game with real world effects like physics action ,we need to put some extra effort to accomplish this task, To reduce this Work, Box2D is an excellent Open Source Physics engine to simulate real world effects,we  can easily integrate this with our projects and make our game as wonderful physics simulated projects ,Here is the link for Box2D Sites http://www.box2d.org/  .So Here are the Basic Concepts for you to start using  Box2D.

 
Shape
          A 2D geometrical object, such as a circle or polygon
Rigid body
             A chunk of matter that is so strong that the distance between any two bits of matter on the chunk is
constant. They are hard like a diamond. In the following discussion we use body interchangeably with
rigid body.
Fixture
                A fixture binds a shape to a body and adds material properties such as density, friction, and restitution.
Constraint
                A constraint is a physical connection that removes degrees of freedom from bodies. In 2D a body has 3
degrees of freedom (two translation coordinates and one rotation coordinate). If we take a body and pin
it to the wall (like a pendulum) we have constrained the body to the wall. At this point the body can only
rotate about the pin, so the constraint has removed 2 degrees of freedom.
Contact constraint
            A special constraint designed to prevent penetration of rigid bodies and to simulate friction and
restitution. You do not create contact constraints; they are created automatically by Box2D.
Joint
                 This is a constraint used to hold two or more bodies together. Box2D supports several Joint types:
               revolute, prismatic, distance, and more. Some joints may have limits and motors.
Joint limit
             A joint limit restricts the range of motion of a joint. For example, the human elbow only allows a certain
range of angles.
Joint motor
           A joint motor drives the motion of the connected bodies according to the joint’s degrees of freedom. For
example, you can use a motor to drive the rotation of an elbow.
World
             A physics world is a collection of bodies, fixtures, and constraints that interact together. Box2D supports
the creation of multiple worlds, but this is usually not necessary or desirable.
Solver
            The physics world has a solver that is used to advance time and to resolve contact and joint constraints.
The Box2D solver is a high performance iterative solver that operates in order N time, where N is the
number of constraints.
Continuous Collision
                      The solver advances bodies in time using discrete time steps. Without intervention this can lead to
tunneling.

ERROR: Unable to load VM from snapshot. The snapshot has been saved for a different hardware configuration.

the problem is not in your project do these steps,it will be solved
  1. Edit the AVD to disable the Snapshot. or
  2. When you next start the AVD, uncheck the Launch with snapshot, but keep Save snapshot checked. This way the snapshot will be ignored at start-up, but overwritten when you exit. You will then be able to use snapshot for subsequent runs as before.
hope that it might be useful to you
 

What is activity in Android? Activity Life Cycle

If you are beginner to android development and you are about to learn android development, you should know about ACTIVITY  ,

Activity presents the presentation layer of  an android application, so without an activity you can not develop android application,and an application can have several activities.
main activity gets created automatically for you ,when you create a new android project,

An activity has life cycle :
OnCreate():
OnStart():

OnResume():
OnPause():
OnDestroy():
OnStop():

How to add Badge number (number on icon in home screen) in iphone development

Adding Badge number over the icon useful to you as  a developer, sometimes you may need to alert users of your app when they are not launching your app(Alerting users ).

set this single line code in ApplicationDidFinishLaunching
[UIApplication sharedApplication] setApplicationIconBadgeNumber:1] // it sets 1 over the icon in your app at home screen

to remove this set this line with number 0:

[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]// once the app has been launched or you got satisfied that your msg has been reached users

How To get Current Time,Date,Month and Year in iPhone Development

Here we go to get current date,month,year and hour using NSCalendar .Apple provides us NSCalendar class to perform this action.

So here we are going to get current day,Year,Month.

1.Get Current date using NSDate:

NSDate *ToDay = [NSDate date]; /// it gives current date with time components.

2.Create NSCalendar Object;

NSCalendar  *Calendar =[ [NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

//we created calendar , it contains components like hour,year,month,day. then lets extract these components from Calendar using NSDateComponents.

3.Step 3:

NSDateComponents *Components = [Calendar components:(NSDayCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSHourCalendarUnit) fromDate:ToDay];



4.Step4:

We did it,now lets log it using NSLog;

you have to remember that all these values return NSInteger type values

NSLog(@”Year %i”,[Components year]);
NSLog(@”Month%i”,[Components month]);
NSLog(@”Day%i”,[Components day]);
NSLog(@”Hour%i”,[Components hour]);
.

i hope that this might be useful to you , and thanks in advance for your feedbacks.

Reading and Storing Values in Key Chain in iPhone Development

As we are ios developers we should know about Apple’s Key Chain method , Apple provides this method to us for storing data securely in ios development, if you use NSDictionary method to store data you can not be accessed the data what you have been stored once your application deleted from the device and another important difference is ,the data what you stored by using NSDictionary can not be accessible from other applications, So to Overcome this problem,Apple provides an efficient method, to storing and retrieving from another app we can us Key Chain method,Here Lets see a simple way of accessing Key Chain,
1.Storing,
2.Deleting from Key Chain,
3. Retrieving from Key Chain,

for this i have created simple class which works fine for me…

in Header file(.h file)

#import <Foundation/Foundation.h>

@interface KeyChainAccess : NSObject

+ (void)saveData:(NSString *)KeyVal data:(id)data;
+ (id)getData:(NSString *)KeyVal ;
+ (void)deleteData:(NSString *)KeyVal ;

@end

in Implementation file(.m file)

#import “KeyChainAccess .h”

@implementation KeyChainAccess

+ (NSMutableDictionary *)getKeychainQuery:(NSString *)KeyVal {
return [NSMutableDictionary dictionaryWithObjectsAndKeys:
(id)kSecClassGenericPassword, (id)kSecClass,
KeyVal , (id)kSecAttrService,
KeyVal , (id)kSecAttrAccount,
(id)kSecAttrAccessibleAfterFirstUnlock, (id)kSecAttrAccessible,
nil];
}

+ (void)saveData:(NSString *)KeyVal data:(id)data {
NSMutableDictionary *keychainQuery = [self getKeychainQuery:KeyVal ];
SecItemDelete((CFDictionaryRef)keychainQuery);
[keychainQuery setObject:[NSKeyedArchiver archivedDataWithRootObject:data] forKey:(id)kSecValueData];
SecItemAdd((CFDictionaryRef)keychainQuery, NULL);
}

+ (id)getData:(NSString *)KeyVal {
id ret = nil;
NSMutableDictionary *keychainQuery = [self getKeychainQuery:KeyVal ];
[keychainQuery setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData];
[keychainQuery setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit];
CFDataRef keyData = NULL;
if (SecItemCopyMatching((CFDictionaryRef)keychainQuery, (CFTypeRef *)&keyData) == noErr) {
@try {
ret = [NSKeyedUnarchiver unarchiveObjectWithData:(NSData *)keyData];
}
@catch (NSException *e) {
NSLog(@”Unarchive of %@ failed: %@”, service, e);
}
@finally {}
}
if (keyData) CFRelease(keyData);
return ret;
}

+ (void)deleteData:(NSString *)KeyVal {
NSMutableDictionary *keychainQuery = [self getKeychainQuery:KeyVal ];
SecItemDelete((CFDictionaryRef)keychainQuery);
}

@end

there are Four important methods in Key Chain Access

1. SecItemAdd:
        this method allows to add data to Key Chain.
2.SecItemDelete:
this one allows to delete data from that.
3.SecItemCopyMatching:
       this allows us to read data from key chain and stored as CFDataRef
4. SecItemUpdate:
       this one useful allows us updating the data in key chain.

In getKeyChainQuery method i used  (id)kSecAttrAccessibleAfterFirstUnlock, (id)kSecAttrAccessible, this property is available only in iOS4.0 and later,,if you want use that method prior to iOS4.0 you can comment that property….

i hope that this one might be useful to you,Expecting your feedbacks..

How to write data in plist file in iphone development

NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:2];NSString *name;

NSDictionary *innerDict;

NSDate *dob;

NSArray *scores;

scores = [NSArray arrayWithObjects:[NSNumber numberWithInt:6],

[NSNumber numberWithFloat:4.6], [NSNumber numberWithLong:6.0000034], nil];

name = @”George Washington”;

dob = [NSDate dateWithString:@”1732-02-17 04:32:00 +0300″];

innerDict = [NSDictionary dictionaryWithObjects:

[NSArray arrayWithObjects: name, dob, scores, nil]

forKeys:[NSArray arrayWithObjects:@”Name”, @”DOB”, @”Scores”]];

[rootObj setObject:innerDict forKey:@”Washington”];

scores = [NSArray arrayWithObjects:[NSNumber numberWithInt:8],
[NSNumber numberWithFloat:4.9],
[NSNumber numberWithLong:9.003433], nil];
name = @”Abraham Lincoln”;
dob = [NSDate dateWithString:@”1809-02-12 13:18:00 +0400″];

innerDict = [NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects: name, dob, scores, nil]
forKeys:[NSArray arrayWithObjects:@”Name”, @”DOB”, @”Scores”]];
[rootObj setObject:innerDict forKey:@”Lincoln”];
id plist = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj
format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];

Go through this Link to APPLE’s Documentation  For More Info https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/PropertyLists/CreatePropListProgram/CreatePropListProgram.html

GameCenter Leaderboards Not Updating in iphone Development

Being an ios game developer and you are integrating game center with your game. You may face this problem, when your application at sandbox environment your scores at Leaderboard not updating. Apple separates sandbox from Live server database, Because your Friends might see what game you are playing, to eradicate this kind of problem apple provides separate servers for sandbox,this data would be periodically erased,so i think that you may not get that Leaderboard problem,once your application enters in Live,

Reading Bundle Name from info.plist file in iphone development

Now we are going to read Bundle Name from info.plist file,first we need to read plist file and store it in NSDictionary.

NSDictionary *infoDictionary=[ [NSBundle mainBundle]infoDictionary];

to read Bundle Name,

NSString *BundleName = [infoDictionary objectForKey:@”CFBundleName”]; // short Display of the name

NSString *BundleName = [infoDictionary objectForKey:@”CFBundleDisplayName”]; // Actual name of the app,,,,is it Useful?