Thursday, July 28, 2011

Process for creating Certificates and Provisioning profiles - iOS APP

1. Create certificate from Keychain Access Application in Mac OS X 
To request an iOS Development Certificate, you first need to generate a Certificate Signing Request (CSR) utilizing the Keychai Access application in Mac OS X Leopard. The creation of a CSR will prompt Keychain Access to simultaneously generate your public and private key pair establishing your iOS Developer identity. 
Your private key is stored in the login Keychain by default and can be viewed in the Keychain Access application under the ‘Keys’ category. To generate a CSR:
  1. In your Applications folder, open the Utilities folder and launch Keychain Access.
  2. In the Preferences menu, set Online Certificate Status Protocol (OSCP) and Certificate Revocation List (CRL) to “Off”.
  3. Choose Keychain Access -> Certificate Assistant -> Request a Certificate from a Certificate Authority. Note: If you have a noncompliant private key highlighted in the Keychain during this process, the resulting Certificate Request will not be accepted by the Provisioning Portal. Confirm that you are selecting “Request a Certificate From a Certificate Authority...” and not selecting “Request a Certificate From a Certificate Authority with <Private Key>…”

  1. In the User Email Address field, enter your email address. Please ensure that the email address entered matches the information that was submitted when you registered as an iOS Developer.
  2. In the Common Name field enter your name. Please ensure that the name entered matches the information that was submitted when you registered as an iOS Developer.
  3. No CA (Certificate Authority) Email Address is required. The ‘Required’ message will be removed after completing the following step.
  4. Select the ‘Saved to Disk’ radio button and if prompted, select ‘Let me specify key pair information’ and click ‘Continue’.

  1. If ‘Let me specify key pair’ was selected, specify a file name and click ‘Save’. In the following screen select ‘2048 bits’ for the Key Size and ‘RSA’ for the Algorithm. Click ‘Continue’.

  1. The Certificate Assistant will create a CSR file on your desktop.

2. After creating certificate upload it for approval
  1. After creating a CSR, log in to the iOS Provisioning Portal and navigate to ‘Certificates’ > ‘Development’ and click ‘Add Certificate’.
  2. Click the ‘Choose file’ button, select your CSR and click ‘Submit’. If the Key Size was not set to 2048 bits during the CSR creation process, the Portal will reject the CSR.
  3. Upon submission, Team Admins will be notified via email of the certificate request.
  4. Once your CSR is approved or rejected by a Team Admin, you will be notified via email of the change in your certificate status.

3. Waiting for approval
Team Agents and Team Admins have the authority and responsibility to approve or reject all iOS Development Certificate requests. In order to approve/reject Team Members’ requests, all Team Admins should first submit their own CSR for approval.
  1. After submitting a CSR for approval, Team Admins will be directed to the ‘Development’ tab of the ‘Certificates’ section. Here, CSRs can be approved or rejected by clicking the corresponding action next to each request.
  2. Once a CSR is approved or rejected, the requesting Team Member is notified via email of the change in their certificate status. Each iOS Development Certificate is available to both the Team Member who submitted the CSR for approval and to the Team Admin(s).

4. Downloading approved certificate

  1. In the ‘Certificates’ > ’Distribution’ section of the Portal, control-click the WWDR Intermediate Certificate link and select “Saved Linked File to Downloads” to initiate download of the certificate.
  2. On your local machine, double-click the WWDR Intermediate certificate to launch Keychain Access and install.
  3. Upon CSR approval, Team Members and Team Admins can download their certificates via the ‘Certificates’ section of the Provisioning Portal. Click ‘Download’ next to the certificate name to download your iOS Development Certificate to your local machine.
  4. On your local machine, double-click the downloaded .cer file to launch Keychain Access and install your certificate.
  5. Team Members can only download their own iOS Development Certificates. Team Admins have the authority to download the public certificates of all of their Team Members. Apple never receives the private key for a CSR. The private keys are not available to anyone except the original key pair creator and are stored in the system keychain of that Team Member.


1. Create a provisioning profile

  1. In the ‘Provisioning’ section of the Portal, Team Admins should click 'Add' on the Development tab.
  2. Enter a name for the provisioning profile.
  3. Specify which devices will be associated with the provisioning profile. You must specify a device in order for that device to utilize the provisioning profile. If a device's UDID is not included in the provisioning profile the profile and your application cannot be installed on that device.
  4. Specify which iOS Development Certificates will be associated with the provisioning profile. You must specify an iOS Development Certificate in order for the application code signed with that same certificate to run on the device.

  1. Specify a single App ID for the Development Provisioning Profile. Each Development Provisioning Profile can specify only ONE App ID, therefore, if you have applications requiring different Keychain access, you will need to create a separate Development Provisioning Profile for each of those applications. If you are installing a suite of applications with the same required Keychain access or have a set of applications not requiring access to the Keychain, use an App ID containing the wild-card asterisk character to build all of your applications.
  2. Click ‘Submit’ to generate your Development Provisioning Profile.

2. Download the provisioning profile and drag into Xcode


Revoke your current certificate, wait a few seconds and refresh the page and you should see a button "Request Certificate". You'll have to follow the Certificate Signing Request instructions again, and upload the .csr file. You'll then have to wait for your Team Administrator (could well be you) to Accept the new certificate before downloading it and installing in your KeyChain.
You'll have to create a new provisioning profile for the App, using the new certificate.


Right click on .xcodeproj, basically its a directory and inside xcodeproj open .pbxproj extension file with any text editor
Search for String  "PROVISIONING_PROFILE" or "PROVISIONING_PROFILE[sdk=iphoneos*]"  
Replace Old Provisioning Identifier with new one.
Its happend because Sometimes our xcode project file gets messed up, especially if we have an old project and first created it with an older version of xcode/iphone sdk.

"PROVISIONING_PROFILE[sdk=iphoneos*]" = "487F3EAC-05FB-4A2A-9EA0-31F1F35760EB";

Wednesday, July 27, 2011

MD5 with JSON KIT in iOS

// Header File NSString+MD5.h
#import "NSString+MD5.h"

@interface NSString(MD5)
- (NSString *)MD5;

// Implementation File NSString+MD5.m#import <CommonCrypto/CommonDigest.h>
@implementation NSString(MD5)

- (NSString*)MD5
        // Create pointer to the string as UTF8
  const char *ptr = [self UTF8String];

        // Create byte array of unsigned chars
  unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];

        // Create 16 bytes MD5 hash value, store in buffer
  CC_MD5(ptr, strlen(ptr), md5Buffer);

        // Convert unsigned char buffer to NSString of hex values
  NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
  for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
                [output appendFormat:@"%02x",md5Buffer[i]];

  return output;



Download JSON KIT from here JSON KIT

Example :

//Import necessary header
#import "NSString+MD5.h" 

#import <CommonCrypto/CommonDigest.h>
#import "JSONKit.h"//Code example
NSMutableDictionary *jsonEncode = [NSMutableDictionary dictionary];
    [jsonEncode setValue:emailField.text forKey:@"email"];
    [jsonEncode setValue:[passwordField.text MD5] forKey:@"password"];
NSString *jsonString = [jsonEncode JSONString];

Custom UIPickerView with Done, Cancel and TransparentBlackView above picker

- (UIView *)returnCustomePickerView:(UIViewController *)viewController {
    UIView *pickerBackView = [[[UIView alloc] initWithFrame:CGRectMake(0200320260)] autorelease];
    UIToolbar *toolBar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0032044)] autorelease];
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
    UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace  
    UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithTitle:@"Clear"
    [toolBar setItems:[NSArray arrayWithObjects:cancelButton, clearButton, flexible, doneButton, nil]];
    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0f, 44.0f, 320.0f, 216.0f)];
    pickerView.showsSelectionIndicator = YES;
    [pickerBackView addSubview:pickerView];
    [pickerBackView addSubview:toolBar];
    [pickerView release];
    [doneButton release];
    [cancelButton release];
    [clearButton release];
    [flexible release];
    return pickerBackView;

Monday, July 25, 2011

iPhone SDK Sample Code Reference

Sample code is one of the most useful tools for learning about programming. There seem to be many sources on the web for iPhone sample code, but some are harder to find than others. Here's a collection of links I've found so far. Does anyone know of some other sources for iPhone sample code?

BYU Cocoaheads
Big Nerd Ranch
Cocoa with love
Will Shipley
These are just sample code:
Google Code:
iPhone Cool Projects
iPhone Game Projects
Learn Objective-C on the Mac
iCode Blog
Raywenderlich Tutorials