Monday, July 16, 2012

Face Detection API in iOS 5.

CoreImage framework introduced in iOS 5 API has  classes called CIFaceFeature  and CIDetector.This class has potentially has been added for detecting face feature in the image. Currently, it offers following functionalities:









CIDetector has ability to detect face as a whole.
If you are wondering how to add framework in your project, refer to this post. LINK

How to create provisioning file for distribution build of iphone/ipad application?

Log in into your Provisioning Portal. @http://developer.apple.com/ios/manage/overview/index.action

Press New Profile Button. Note that Under Provisioning(Left Side Menu), Distribution Tab is selected.



Select relevant app ID  you made for a specific app which you are going to sign with this provisioning file.


How to create distribution build with XCode 4 ?

1. Open XCode with your code of the application which you want to upload.

2. Select your project and under configuration press + and duplicate Release Configuration.


3.  Rename the release duplicate to Distribution



 

 4. Set the command-line builds to Distribution from the drop down menu as shown below.


5. In the Build Setting: You need to choose the provisioning.

See HERE for how to create provisioning file  for distribution







6.  You can set the product name of your app as shown below.(The name with which your app will appear on App Store).






7. We need to open the info.plist file and change the bundle name to the bundle ID string to com.reetu.youbudget  which we created on App Store for this application.
See here how to create bundle ID ?








8.  Now you select the target of the application in the XCode. you will be able to see updated Bundle ID in the identifier field as com.reetu.youbudget  in the Summary Tab as shown below.








9.  In the Build Settings Tab, you can change the product name to correct product name.



10. Now click on the dropdown present to the left of Breakpoints to see the pop up as shown below. There you select Edit Scheme.


11.  This will open a new window as shown below, you need to select the archive on the left most menu. Change destination to iOS device.



12.  You need to change build configuration on that same window to Distribution as shown below.


13. Then you have to choose Product > Archive.


14. You will be asked to allow the code signing to happen, you press Allow.



15. After you have the archived successfully, your organizer will open as following screenshot. If it does not open, then you can open it from top menu of XCode Window > Organizer.





16. Next you validate by validate button on the screen above, then you will asked to put in your itunes connect account info.You may actually get an error while authentication if no application is available on App Store with status ready to upload binary. Hence you need to create the app on App Store first. You can check the link of the post given in  next point which describes it.

17.  Then you will have following window appear, where you have your application to be selected from the drop down menu (this will appear only if you have already created your application on App  Store as mentioned by me in THIS POST "How to create app on App Store" )

After application is selected, you need to choose the correct provisioning file from the drop down menu.
Note: It may appear that it is already selected but still you need to drop down and check if its the right one.



18. Then you Press Next. then it asks you the sign the code with the valid key as shown in the screenshot below. Just press Allow.



19. You will see following screen that validation has been successful. Finish it by pressing Finish Button.


20. Now you press the button Submit to submit it on App Store (it is present 1 button below the validate button). Make sure you have right app selected in Application and right Identity( provisioning file ) before your press Submit button.






21. You will see following screen for abour 4-5 mins while its uploading your app on App Store.


22. After it is successfully submitted, you will see following screen. Then just press Finish.


23. Yeppie !! You have submitted the app on App Store !! If you  login into your iTunes Connect account you will see that status has been changed from  waiting for upload to your upload has been received and soon it changes to Waiting for review automatically.

You can see in the screenshot below , the status appears Waiting for review.




Now. After you submitted with your app, you suddenly want to do one change in the app and hence you want to reject the binary . How to reject the binary ? READ HERE


How to check memory leaks in XCode 4 ?

You need to go to Product>Profile on the top menu of XCode 4 as shown in screenshot below.




























Then you will see following window, you can just choose Leaks and Press Profile button, it will start the Instrument and start tracking leaks and allocation.






































As soon as you press Profile, it will start Instrument and the simulator/device(You can change in the settings of the Instrument whether you want to run it on simulator or device) will start running the app.
You scroll through various pages on your app. While doing so,  if you view the red line in Leaks windows of Instrument as shown below then you have memory leak detected ! You can move the dotted line with slider to find out how many bytes leaked at what time in a small yellow pop up.































When you double click the red thick line of memory leak as shown  above , in the lower portion of the Instrument you will be able to see all the leaks and related info. If I want to find detailed info about a particular leak,  in this tutorial as you can see the blue highlighted line of leak, I am going to inspect about that leak hence I will just click the arrow which comes up in its address field.










This will refresh the window and tell you the details with  Responsible Caller column in the end of the table , it gives the specific method  name where the leaks has occurred. If you double click the row, it will open that corresponding .m file where that method has been implemented. 


































Now you can see that the line is highlighted where the leak has occurred in the method of a .m file in the project.










 Hope this helps to someone new in fixing memory leaks !

Friday, June 29, 2012

Appstore submission process


 iPhone app development cycle

Here is the iPhone app development cycle and required communication between you and us.
Stakeholders:
1. iPhone App Developer( “Dev” i.e. us)
2. iPhone app seller (“Client” i.e. you)
Firstly, an iPhone cannot be run on any iphone/ipod if it is not downloaded from itunes app-store and then installed to iphone/ipod by syncing( same as syncing music, pics etc. via iTunes).
Dev is a registered Apple Developer. He also registered his iPhone,iPod to Apple and apple in return gave him a certificate. Using this certificate
he can use his devices as debugger only when the devices are connected to his Mac machine using XCode IDE.
Clients or sellers need to register in any of the ADC programs. For example we have a registered standard program account i.e. we can also sell free/paid from iTunes along with development.
Now, how the Client will test/run the app? For this also, Client need to register http://developer.apple.com/iphone/program/ in a program standard/enterprise.
Then, from the control panel he need create certificate with his device ids( device id can be seen via itunes once connected, we can show you if u need).
After that, he has to send this certificates to the Developer. This is called AdHoc certificate. Using this certificate an app can run on those registered devices.
Now, the Developer will install the certificate on his Mac and make an app executable using this adhoc certificate. Then, he will mail this app/executable to the client.
The client will download the app and drag it on itunes and then sync his iphone/ipod.
But, this executable cannot be submitted to app-store and also wont run any other devices other than the ones registered in the AdHoc certificate.
To submit any app to app-store i.e. to sell/distribute an app using app-store, the executable must be compiled with with a Distribution certificate.
Distribution certificate is to created by the seller i.e. the client. It is similar to creating adhoc certificate. At this moment client must provide an app icon to the developer.
Then the client again send the distribution certificate to the developer. Developer compiles another build with it and sends the app-build to the client.
Then the client will download this build and submit to itunes app-store.
Once you are registered to the ADC standard($100) or enterprise($299) program from here http://developer.apple.com/iphone/program/
you will have a nice control panel. There are nice step by step guideline there.
****
So, in short:
1. Client Gives requirement to Developer
2. Developer develops the app
3. Client gives ad-hoc certificate to the developer.
4. Developer gives ad-hoc build to the client
5. Client Test the ad-hoc build on his iPhone/iPods
6. Client  gives the distribution certificate to the developer
7. Developer give distribution build to the client
8. Client submits this distribution build to app-store
9. App-Store takes around 1 week to review and then make it available on iTunes App-Store
Btw, the Client must also provide AppIcon or size 57px X 57px to the developer.
Client also need to have the same image of the AppIcon of size 512 X 512 to submit the app on app-store.

Creating a custom Table View Cell programmatically


Ohhk, quite a lot of things done but this one is something which I have used most often. Custom cells can sometimes greatly push ahead the usability of your application. In this post I am going to create a test project which will demonstrate how to create custom cells and use them appropriately to provide better usability. The application will finally look like this:

So to start open xcode and create a new project, chose the template as “Navigation Based” and name it as “CustomCellTestProject”. What template you chose does not matter, refer my previous posts to find how you can start working on any template.
First thing we will do is create a customCell. Right click on Classes and add a new UITableViewCell subclass. Name it as “CustomCell”. Now open CustomCell.h and add the following code:
#import
@interface CustomCell : UITableViewCell {
UILabel *primaryLabel;
UILabel *secondaryLabel;
UIImageView *myImageView;
}
@property(nonatomic,retain)UILabel *primaryLabel;
@property(nonatomic,retain)UILabel *secondaryLabel;
@property(nonatomic,retain)UIImageView *myImageView;
@end


We create the three elements and added them to the contentView of our cell.
synthesize all the three elements in CustomCell.m as we are going to access these elements from other classes.
@synthesize primaryLabel,secondaryLabel,myImageView;
Here we have simply added a primary label to display the primary text, a secondary label and an imageView. These elements will be created and added into the content view of our custom cell. So open CustomCell.m and add the following code
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
primaryLabel = [[UILabel alloc]init];
primaryLabel.textAlignment = UITextAlignmentLeft;
primaryLabel.font = [UIFont systemFontOfSize:14];
secondaryLabel = [[UILabel alloc]init];
secondaryLabel.textAlignment = UITextAlignmentLeft;
secondaryLabel.font = [UIFont systemFontOfSize:8];
myImageView = [[UIImageView alloc]init];
[self.contentView addSubview:primaryLabel];
[self.contentView addSubview:secondaryLabel];
[self.contentView addSubview:myImageView];
}
return self;
}


Now, we have already added the UI elements into our cell but you must have noticed, we have not yet defined how these elements will appear inside cell. Go ahead and add the following code for that:
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+10 ,0, 50, 50);
myImageView.frame = frame;
frame= CGRectMake(boundsX+70 ,5, 200, 25);
primaryLabel.frame = frame;
frame= CGRectMake(boundsX+70 ,30, 100, 15);
secondaryLabel.frame = frame;
}

You can do anything in this method to define the lay out of cell. I have simply assigned frames to all the elements.
You can also find a method in CustomCell.m
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
This method can be used to define how your cell should react when it is selected. You can describe what should be the highlight color or may be you want to flash one of the labels anything of your choice. I am leaving this method as it is.
We are done with creating our custom cell and now we have to use it. Open RootViewController.m and import CustomCell.h at the top.

#import “CustomCell.h”
I am going to create 5 cells here, you can just use your own logic of specifying number of cells and data. So change the following method to look like this:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
Now we are going to use our custom cell. If you look at the cellForRow method, you will find that a UItableViewCell has been created and re used. Now all we have to do is to replace this cell with our new cell. Change the code inside this method to look like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @”Cell”;
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell…
switch (indexPath.row) {
case 0:
cell.primaryLabel.text = @"Meeting on iPhone Development";
cell.secondaryLabel.text = @"Sat 10:30";
cell.myImageView.image = [UIImage imageNamed:@"meeting_color.png"];
break;
case 1:
cell.primaryLabel.text = @"Call With Client";
cell.secondaryLabel.text = @"Planned";
cell.myImageView.image = [UIImage imageNamed:@"call_color.png"];
break;
case 2:
cell.primaryLabel.text = @"Appointment with Joey";
cell.secondaryLabel.text = @"2 Hours";
cell.myImageView.image = [UIImage imageNamed:@"calendar_color.png"];
break;
case 3:
cell.primaryLabel.text = @"Call With Client";
cell.secondaryLabel.text = @"Planned";
cell.myImageView.image = [UIImage imageNamed:@"call_color.png"];
break;
case 4:
cell.primaryLabel.text = @"Appointment with Joey";
cell.secondaryLabel.text = @"2 Hours";
cell.myImageView.image = [UIImage imageNamed:@"calendar_color.png"];
break;
default:
break;
}
return cell;
}

I have added some dummy data. You can use your data source to provide data for primaryLabel and secondaryLabel. Please note that I have used three images here. You can use any image of your choice. All you need to to do is copy the images and paste it into your project root folder (which in this case is CustomCellTestProject folder). After pasting the files, in xcode right click on Resources (or any group), select Add >> ExistingFiles and then select all the images you want to add in you project. Once added you can simply use them by their names.
Thats it, go ahead and run the project. You will find something wrong when you compare you simulator screen with mine. If you noticed in the CustomCell.m, I have given some frames to the UI elements. You need to make sure that the height of your cell large enough to accomodate all the elements. So add this following code and you fixed the issue:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}