Wednesday, 14 September 2011

Popper live on AppStore.....

Popper is a fun game developed by iOSDeveloperz. Popper has to pop enemy balloons as well as save its own balloons. Popper can also pop bubbles and get extra points.

Initial version of this game consists of 6 exciting stages.

More exciting stages are coming soon.

To download click here

Saturday, 6 August 2011

FB Friends Quiz now live on AppStore

FB Friends Quiz (version 1.0) for iPhone is now live on AppStore. This app is a fun way of testing your knowledge about Facebook friends. You also get to know various facts about your friends.





FB Friends Quiz is the product of iOSDeveloperz and is available in the Entertainment category of AppStore for only $0.99.



Saturday, 23 July 2011

Friday, 15 July 2011

This post deals with rotating a view with animation with the help of core graphics. Quartz framework provides us with class "CGAffineTransform.h" which contains the function "CGAffineTransform CGAffineTransformRotate ( CGAffineTransform t, CGFloat angle );" that takes the current affine transform matrix and angle in radians as parameters, and returns the resultant affine transform. We will also animate the rotation instead of simply rotating the view by some angle.

Now lets see how it is done.

Suppose we have a view controller class called RotationViewController.

Write the following code in RotationViewController.h" file


#import <UIKit/UIKit.h>

@interface RotationViewController : UIViewController {
 UIImageView *needleview;
 }

@end

Here needleview is the view we are going to rotate.

Now come to RotationViewController.m file and write the following code


- (void)viewDidLoad {
 needleview=[[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"finalneedle.png"]];
 needleview.frame=CGRectMake(100, 100, 36, 221);
 [self.view addSubview:needleview];
    [super viewDidLoad];
}

-(void)viewDidAppear:(BOOL)animated
{
 [UIView animateWithDuration:2.0

  delay: 0.0

 options: UIViewAnimationOptionCurveEaseIn

 animations:^{

 needleview.transform=CGAffineTransformRotate
(needleview.transform, (((60*22)/7)/180));

  }
  completion:nil];

}

In the above code "finalneedle.png" is the image file, in the resources folder, to be used in ImageView. We have implemented "viewDidAppear" to perform rotation with animation after the view appears on screen. The animation block inside the method contains various parameter which has to be set before animating the rotation. The angle of rotation is 60 degree which is converted to radians.

Monday, 11 July 2011

How to record audio using AVAudioRecorder in iPhone application?

This post deals with recording sound in iPhone application using AVAudioRecorder class. AVAudioRecorder is simple to use and provides facilities for pausing/resuming recording and handling audio interruptions.

Suppose we have a view controller file “RecordViewController”

Implement the following code in RecordViewController.h file.


#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface RecordViewController:UIViewController
<AVAudioRecorderDelegate> {
 NSURL *SoundPath;
 IBOutlet UIButton *recordOrStopButton;
 bool recording;
 AVAudioRecorder *soundRecorder;

}
@property(nonatomic,retain) NSURL *SoundPath;
@property(nonatomic,retain) AVAudioRecorder *soundRecorder;
- (IBAction) recordOrStop: (id) sender;
-(IBAction)play;
@end
In the above code

a) We have added AVFoundation framework from the list of existing frameworks and imported AVFoundation.h to RecordViewController.h file.

b) We have also made this class as the delegate for AVAudioRecorder by implementing AVAudioRecorderDelegate.



 

Now come to RecordViewController.m file and write following code as shown.

@synthesize SoundPath,soundRecorder;

- (void)viewDidLoad {
    [super viewDidLoad];
 NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDir =[paths objectAtIndex:0];
    NSString *soundFilePath =[documentsDir stringByAppendingPathComponent:@"mysound.caf"];
 NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
 self.SoundPath=newURL;
 [newURL release];
 recording = NO;
 }

In the above code we are specifying the path for saving the recorded audio. The audio will be saved in Documents folder of this application. Initially we set recoding to NO.

-(IBAction)play
{
 AVAudioPlayer *player =[[AVAudioPlayer alloc] initWithContentsOfURL:SoundPath error: nil];

 [player prepareToPlay];
 [player play];

}

We have implemented this method for playing the recorded audio using AVAudioPlayer.

- (IBAction) recordOrStop: (id) sender {
 if (recording) {
  [soundRecorder stop];
  recording = NO;
  self.soundRecorder = nil;
  [recordOrStopButton setTitle: @"Record" forState:UIControlStateNormal];
  [recordOrStopButton setTitle: @"Record" forState:UIControlStateHighlighted];
  [[AVAudioSession sharedInstance] setActive: NO error: nil];
  [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
  [[AVAudioSession sharedInstance] setActive: YES error: nil];
  } else {
  [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryRecord error: nil];
  [[AVAudioSession sharedInstance] setActive: YES error: nil];
  NSDictionary *recordSettings =[[NSDictionary alloc] initWithObjectsAndKeys:
   [NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
   [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
   [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
   [NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey, nil];
  AVAudioRecorder *newRecorder =[[AVAudioRecorder alloc] initWithURL: SoundPath 
settings: recordSettings error: nil];
  [recordSettings release];
  self.soundRecorder = newRecorder;
  [newRecorder release];
     soundRecorder.delegate = self;
  [soundRecorder prepareToRecord];
  [soundRecorder record];
  [recordOrStopButton setTitle: @"Stop" forState: UIControlStateNormal];
  [recordOrStopButton setTitle: @"Stop" forState: UIControlStateHighlighted];
  recording = YES;
  }
 }

In the above code we set the category of AVAudioSession to"AVAudioSessionCategoryRecord" and activate it. After that in recordSettings dictionary object we store the values for various settings. The AVAudioRecorder object is then allocated with these settings, after that we start recording.

For playing recorded sound we stop the recording and change the category of AVAudioSession to AVAudioSessionCategoryPlayback and activate it. Recorded audio is listened with the help of AVAudioPlayer object.

-(void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{
 NSLog(@"success");
}
-(void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error
{
 NSLog(@"fail");
}

We can also implement the above delegate methods which are called when audio is recorded successfully or when it fails.

Save, Build and run you project

NOTE- For recording of sound we need actual device i.e iPhone, it will not work on Simulator.

Wednesday, 6 July 2011

How to make a custom view in iPhone application?

This post deals with making custom views in iPhone application. You can design your views according to your ideas rather than using plain UIView. You can draw variety of patterns in your custom views using Quartz framework and then use these views in your application.

In this snippet we will add a simple coloured rectangle in a view.

1) Add a new file in your project and select it as a subclass of UIView as shown in figure.


2) Lets name it as “new”, so now you must have got two files “new.h” and “new.m” . new.h inherits UIView.

3) Lets say we have a view controller. Open its xib file, select view in file owner window and change its class from UIView to new in library inspector window as shown in figure.



4) Now come to new.m file, uncomment and ovewrite its “drawRect:” method with code shown below

- (void)drawRect:(CGRect)rect {
    // Drawing code.
 CGContextRef context = UIGraphicsGetCurrentContext();
 CGContextSetRGBStrokeColor(context, 1.0f, 0.3f, 0.5f, 1.0f);
 CGContextStrokeRectWithWidth(context,CGRectMake(20, 20, 280, 420), 10);
}

5) Save, build and run the project.

6) Output is as shown below. Now you can use this view in any view controller in your application.



Sunday, 3 July 2011

How to play sound in iPhone application?

This post deals with playing sound in iPhone applications. You can play sounds in your application using an instance of AVAudioPlayer class. AVAudioPlayer lets you play audio in different formats available in iOS. You can play, pause or stop an audio player using its properties.

1) Add the framework AVFoundation.framework from existing framework.

2) Lets say we have a view controller class “PlayViewController” . In .h file write the following code as shown below.

#import <UIKit/UIKit.h>
#import <AVFoundation/AVAudioPlayer.h>
@interface PlayViewController : UIViewController<avaudioplayerdelegate> {
AVAudioPlayer *player;
IBOutlet UIButton *button;
}

-(IBAction)play;
@end

3) In the above code we have imported “AVAudioPlayer.h” which is inside AVFoundation framework. We have also implemented AVAudioPlayerDelegate protocol in this class.

4) Now come to .m file and write the following code in “viewDidLoad” method.

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: @"snd1" ofType: @"mp3"];
NSURL *fileurl = [[NSURL alloc] initFileURLWithPath: soundFilePath];
player =[[AVAudioPlayer alloc] initWithContentsOfURL: fileurl error: nil];
[fileurl release];
[player prepareToPlay];
[player setDelegate: self];

Here snd1 is the name of the mp3 file present in the resources folder of the Xcode project.

5) Implement the play method as shown below.

-(IBAction)play
{
if (player.playing) {
[button setTitle: @"Play" forState: UIControlStateHighlighted];
[button setTitle: @"Play" forState: UIControlStateNormal];
[player pause];
}
else {
[button setTitle: @"Pause" forState: UIControlStateHighlighted];
[button setTitle: @"Pause" forState: UIControlStateNormal];
[player play];
}
}

Here property playing of player tells whether the player is currently playing or not, based on which we set the title for button.

6) Implement the following delegate method, as shown, in .m file

- (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player successfully: (BOOL) completed {
if (completed == YES) {
[button setTitle: @"Play" forState: UIControlStateNormal];
}
}

This delegate method is called when the player is finished playing. We can change title of the button inside the implementaion of the above method.

7) Now open .xib file, add a UIButton and make connections as shown below.


8) Save, build and run your application.

Wednesday, 29 June 2011

How to take screenshot of the iPhone screen programmatically?

This post deals with taking screenshot of the iPhone screen with the help of coding.

Remember, when we say screen shot of the iPhone screen, we mean screenshot of any view which is visible on the iPhone screen. Also, a view is captured with all its subviews that are visible on screen at the time of capturing.

Add the following code at the place where you want to take screenshot of the view.

UIGraphicsBeginImageContext(view.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

A Context, more accurately known as Graphics Context, is the drawing destination for your objects. A context can be a Bitmap image, a UIView layer, a PDF file or a Printer.

In the above code, view is the UIView object which has to be captured.

UIGraphicsBeginImageContext(view.frame.size) creates a bitmap image context and set it as the current context. It takes size as parameter. The image context made is of the same size as the size passed in as parameter to this function. Since, here we want the image context to be of same size as of view to be captured so we pass the size of view as parameter.

UIGraphicsGetCurrentContext() returns the current context for drawing. Since we already set the bitmap context as the current context so it will return the same bitmap context created above. Had the bitmap context not been set , all the drawings would have taken place on UIView layer context(which is the default current context).

[view.layer renderInContext:context] draws all the objects, on or above the view’s layer, to the context passed in as parameter.

UIGraphicsGetImageFromCurrentImageContext() returns an image based on the contents of the current bitmap-based graphics context.

Sunday, 26 June 2011

What is iCloud?

iCloud is more than a synchronization tool. It is seamlessly integrated into your applications and keeps all your devices up to date with all your informations. iCloud is just like a common hard drive in the sky for all of your devices. It stores your photos, music, calender, email, and wirelessly pushes them to all the devices you own. So, what does this mean? This means that you buy music from itunes on one device and iCloud will automatically push this music to all of your devices.

It also solves storage problem. As you know that storage capacity of your mac is much more than your iPhone or iPad, so when you buy music or videos on iPhone, you have the option to store in in your mac automatically with the help of iCloud. No need to connect your iPhone to mac for transferring data, iCloud does it all for you.

Besides this, when you sign up for iCloud you get 5 GB of storage. Your purchased music, apps and videos don’t come in this storage, so that leaves only your mails, contacts, documents and calender to use this space, and believe me 5 GB is more that a lot of space for them.
As soon as your update your iPhone, iPad operating system to iOS5, iCloud is seamlessly integrated with your applications without your doing anything. Isn’t that great?

iTunes in the Cloud


All your present and past purchases are available on all your devices, so you can download and listen to them whenever you want, wherever you want.

iTunes Match


iTunes match matches your device library with iTunes library and automatically adds the matched songs to your iCloud library so that you can listen them on any device at any time. You have to upload only those songs to your iCloud library from your device library which are not present in the iTunes library.

PhotoStream


Whenever you take photos on your device, iCloud automatically pushes them to all your devices over the wi-fi or 3g network so that you can instantly share your photos with your family and friends. iCloud stores your photos for 30 days, means you have ample amount of time to transfer them to your mac, iPhone, iPad libraries or stream them on Apple TV.


Documents in the Cloud


If you have same application across all your devices, when you edit your documents on one device the changes are automatically stored to all of your devices. So, you don’t have to save and load them to all of your devices again and again, they are just there. It is excellent for office works.


Apps, Books, and Backup

Apps

iCloud makes sure that all of your devices have the same application. Whenever you purchase some app on appstore, iCloud pushes the app on all of your devices at no extra cost. Once you purchase application, you can download them again and again.


iBooks


Once your purchase a book, it is available on all of your devices and whenever you start reading book on one device, iCloud automatically stores bookmarks, highlights text, and pushes them to all of your devices. So start reading from where you left and on any device.




Backup

iCloud automatically backs up all your important stuff on a daily basis over the wi-fi network. iCloud is intelligent enough to back only the changes and not the whole data. This makes it more efficient and time saving.

Contacts, Calender and Mail

Mail

Whenever you set up for iCloud you get free .me mail account. iCloud keeps your mailbox updated on all your devices.


Calender


Mark your schedule at one place and get notifications wherever you go. iCloud also allows you to share calenders with other users so that all of them can simultaneously access the updates.

Contacts


Your entire address book is on all the devices you use. Whenever you add, delete or update your account on one device it gets updated on all your devices.