Monday, August 10, 2009

UIToolbar and Autorotate

Wait for it is over...


//==============================================================================
// Declare nCurrentOrientation at application level. Toolbar object also put at application level class
//==============================================================================
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
SampleAppDelegate *appDelegate = (SampleAppDelegate *)[[UIApplication sharedApplication] delegate];
CGRect mainViewBounds = [appDelegate.window bounds];

CGFloat toolbarHeight = 30;
switch (interfaceOrientation)
{
case UIInterfaceOrientationLandscapeLeft:
{
if (appDelegate.nCurrentOrientation != UIInterfaceOrientationPortrait)
return NO;
// size up the toolbar and set its frame

[appDelegate.toolbar setFrame:CGRectMake(CGRectGetWidth(mainViewBounds),
toolbarHeight,
CGRectGetHeight(mainViewBounds),
toolbarHeight)];
//calculate new center point
CGPoint center = CGPointMake(305.0, CGRectGetHeight(mainViewBounds) / 2);

// Set the center point of the view to the center point of the window's content area.
appDelegate.toolbar.center = center;

//Transform the toolbar according to new orientation
appDelegate.toolbar.transform = CGAffineTransformMakeRotation( 3 * M_PI / 2.0);
appDelegate.nCurrentOrientation = UIInterfaceOrientationLandscapeLeft;


}
break;

case UIInterfaceOrientationLandscapeRight:
{
if (appDelegate.nCurrentOrientation != UIInterfaceOrientationPortrait)
return NO;

// size up the toolbar and set its frame

[appDelegate.toolbar setFrame:CGRectMake(0,
CGRectGetHeight(mainViewBounds) - toolbarHeight,
CGRectGetHeight(mainViewBounds),
toolbarHeight)];
//calculate new center point
CGPoint center = CGPointMake(toolbarHeight/2, CGRectGetHeight(mainViewBounds) / 2);
// Set the center point of the view to the center point of the window's content area.
appDelegate.toolbar.center = center;

//Transform the toolbar according to new orientation
appDelegate.toolbar.transform = CGAffineTransformMakeRotation(M_PI / 2.0);
appDelegate.nCurrentOrientation = UIInterfaceOrientationLandscapeRight;


}
break;
case UIInterfaceOrientationPortrait: //EXIF = 3
{
if ( appDelegate.nCurrentOrientation != UIInterfaceOrientationLandscapeRight && appDelegate.nCurrentOrientation != UIInterfaceOrientationLandscapeLeft)
return NO;

// size up the toolbar and set its frame

toolbarHeight = 42;
//calculate new center point
CGPoint center = CGPointMake(CGRectGetWidth(mainViewBounds)/2, toolbarHeight/2);
appDelegate.toolbar.center = center;
//Transform the toolbar according to new orientation
appDelegate.toolbar.transform= CGAffineTransformMakeRotation(2*M_PI );
[appDelegate.toolbar setFrame:CGRectMake(0,
CGRectGetHeight(mainViewBounds)-toolbarHeight,
CGRectGetWidth(mainViewBounds),
toolbarHeight)];

appDelegate.nCurrentOrientation = UIInterfaceOrientationPortrait;


}

default:
break;
}

return ( interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

Wednesday, August 5, 2009

Conversion of date and time to/from number of seconds from the reference date

A) Converting date to seconds


//Create nscomponents object
NSDateComponents *objNsComps = [[NSDateComponents alloc] init];
//set date
[objNsComps setDay:10 ];
[objNsComps setMonth:11];
[objNsComps setYear:2008];

//set time
[objNsComps setHour:10 ];
[objNsComps setMinute:15];
[objNsComps setSecond:20];
///conversion in NSdate object
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *objDate = [gregorian dateFromComponents: objNsComps];
//get number of seconds from refrence date 1 January 1970
///convert into double equibalent// time in secs
double dblSecs4Date = [objDate timeIntervalSince1970];
NSLog(@"dblSecs4DateFrmServer: %f", dblSecs4Date);
[gregorian release];
[objNsComps release];







B) Conversion of seconds into readable date string


double dblDateInSeconds = date in seconds from reference date 1 January 1970;
//Create NSDate Object
NSDate *objDate = [NSDate dateWithTimeIntervalSince1970: dblDateInSeconds];


NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
//Convert in readable string
NSMutableString *strDate = [[[NSMutableString alloc] init] autorelease];
[strDate setString:@""];
[strDate appendString:[dateFormatter stringFromDate:objDate]];
[dateFormatter release];
NSLog(@"dateString: %@ ", strDate);

Tuesday, August 4, 2009

No need to spend time on studying Objective C and cocoa to create iPhone apps.

Hello Friends,

Those who interested in starting developing applications for iPhone may be looking for books of cocoa and objective C as the official iPhone SDK uses these. But there is certainly no need to spend time in studying objective C and cocoa because there are many third party frameworks are available in market which use of code written in languages like good, old-fashioned JavaScript or newfangled Ruby and give the user complete control of the screen, just like a native application.

Few named here, Rhomobile Rhodes, Nitobi PhoneGap, Appcelerator Titanium, and Ansca Corona.
These toolkits also offer cross-device development, your software will run on an iPhone, a BlackBerry, an Android handset, and in some cases even a Symbian phone or a Java ME phone.

So why to wait, enjoy coding...
For more info please read following article..

http://www.infoworld.com/d/mobilize/iphone-development-tools-work-way-you-do-309

Thanks
Amit

Sunday, August 2, 2009

Added iPhone3 OS Push notification support to application successfully

Hello Everybody,
I am glad to say that I am able to add push notification support to our iPhone application and its accepted on appstore. if anybody wants help in hows to implement it then you can write to me.

P.S. - The first thing you need is your Push certificates. These identify you when communicating with APNS over SSL. Configure your application for handling push notification on program portal of your iPhone developer account for development mode ( and production mode in case you want to release your application). Send your messages to gateway.sandbox.push.apple.com:2195 during the beta period.

How push notification works according to Apples documentation :




Thanks
Amit