Monday, 30 July 2012

#12 XCode Project Properties

  • -info.plist (Example : MyGreetings-info.plist)
  • Icon image files = icon1.png (iphone < version 4) size 57 x 57
  • Icon image files = icon@2x.png (iphone >= 4) size 114 x 114

#11 Building Application in XCode

  • Build = Compile (to iOS understandable format) + Link (with necessary frameworks)
  • Command Reference
  • At development stage choose, Active Configuration = "Debug"
  • At release stage choose, Active Configuration = "Release" 


#10 Objective C Method Pattern

  • Example:
- (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions:(NSDictionary *) launchOptions {
     
}
  • Description:
    • -  (Minus sign) : represents instance method, use + for class method
    • (BOOL) : Method return type
    • application: Method name first part
    • (UIApplication *) : parameter type first part
    • application : parameter variable name
    • didFinishLaunchingWithOptionsMethod name second part
    • (NSDictionary *)  : parameter type first second part
    • launchOptions : parameter variable name second part


#9 Understanding New XCode Project Structure for iOS

--------------------------------------------------------------------------------------------------------------
Learn Japanese with Sound of Kanji (FREE !!!)

Level 5: https://itunes.apple.com/vn/app/sound-of-kanji-5/id930545991?mt=8
Level 4: https://itunes.apple.com/vn/app/sound-of-kanji-4/id931983628?mt=8
--------------------------------------------------------------------------------------------------------------

Thursday, 26 July 2012

# P1: Investment Calculator on iOS

Project Background
Develop an Application to calculate Future Values (Simple Future Value and Compound Future Value) for the given Principal amount, Period in years and rate of interest.
Reference Formulas:
    Simple Future Value = principal + (principal * interest * period);
    Compound Future Value = principal * [ (interest + 1) ^ period ]

Project Setup
  • Create View Based Project
  • XCode will create necessary ViewController header (.h), implementation (.m) and View (.xib) files.

  • Update above .h and .m files with below code 
ViewController.h
-----------------------
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITextFieldDelegate> {
    IBOutlet UILabel *i;
    UISlider *slider;
    IBOutlet UILabel *futureValueSimple;
    IBOutlet UILabel *futureValueCompound;
    IBOutlet UITextField *months;
    IBOutlet UITextField *principal;
}

@property (nonatomic, retain) UILabel *i;
@property (nonatomic, retain) UILabel *futureValueSimple;
@property (nonatomic, retain) UILabel *futureValueCompound;
@property (nonatomic, retain) UITextField *months;
@property (nonatomic, retain) UITextField *principal;

-(IBAction)valueChange:(id)sender;
-(IBAction)iChange:(id)sender;
-(void)updateFutureValue;

@end

ViewController.m
-----------------------
#import "ViewController.h"

@implementation ViewController

@synthesize i;
@synthesize futureValueSimple;
@synthesize futureValueCompound;
@synthesize months;
@synthesize principal;

-(IBAction)valueChange:(UIStepper *)sender {
    int m = [sender value];
    
    [months setText : [NSString stringWithFormat:@"%d",m]];
    
    [self updateFutureValue];
}

-(IBAction)iChange:(UISlider*) sender {
    
    double interest = [sender value];
    
    [i setText:[NSString stringWithFormat:@"%.2f", interest]];
    
    [self updateFutureValue];
    
}

//Delegate Method from <UITextFieldDelegate>
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    //dismiss keyboard    
    [theTextField resignFirstResponder];
    [self updateFutureValue];
    return YES;
}

- (void)updateFutureValue {
    
    float interest =  [[i text] floatValue] / 100.0
    int n =  [[months text] intValue];
    float p =  [[principal text] floatValue];
    
    float fs = p + (p * interest * n);
    float fc = p * pow((interest + 1), n);
    
    //fv = pv(i + 1)^m
    [futureValueSimple setText:[NSString stringWithFormat:@"%.2f", fs]];
    [futureValueCompound setText:[NSString stringWithFormat:@"%.2f", fc]];
    
    return;
}

- (void)dealloc {
    [i release];
    [futureValueSimple release];
    [futureValueCompound release];
    [months release];
    [principal release];
    [super dealloc];
}

ViewController.xib

Connections
  • All Relevant Connections between Code and View
  • Method Connections

































  • Similarly do other UI connections
Output

Monday, 23 July 2012

# UIStepper

------------------------------------------------------------------------------
  • ViewController.h
------------------------------------------------------------------------------
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
    IBOutlet UITextField *i;
}

@property (nonatomic, retain) UITextField *i;

-(IBAction)valueChange:(id)sender;

@end
------------------------------------------------------------------------------
  • ViewController.m
------------------------------------------------------------------------------
#import "ViewController.h"

@implementation ViewController

@synthesize i;

-(IBAction)valueChange:(UIStepper *)sender {
 
    double value = [sender value];
 
    [i setText : [NSString stringWithFormat:@"%f",value]];
 
}
------------------------------------------------------------------------------

  • ViewController.xib
------------------------------------------------------------------------------




------------------------------------------------------------------------------

  • Output
------------------------------------------------------------------------------



Sunday, 22 July 2012

#8 iOS Development Environment

  • XCode IDE (Integrated Development Environment)
    • Powerful development environment for creating apps. for Mac, iPhone, and iPad
    • It includes 
      • SDK for Mac OS X and iOS
      • Analysis Tool (Instruments)
      • iOS simulator
      • Interface Builder (IB) is for creating User Interfaces visually and connecting those to underlying implementation. IB exposes UI elements as object, so that their attributes and properties can be modified using visual interfaces. 
  • Download XCode from Apple's developer website https://developer.apple.com/xcode/

Saturday, 21 July 2012

#7 Generating and Installing Development Provisioning Profile for IPhone

  • Prepare necessary IDs which will be required by Provisioning Assistant later
    1. Create Application ID : Unique identifier that IPhone OS can grant access to its keychain (Secure information store area). This ID belongs to one or group of applications.
    2. Get UDDI for your device by connecting it to the Mac and then use XCode menu
        • XCode -> Window -> Organizer
    3. Generate a CSR (Certificate Signing Request) using below steps on Mac,
        • Start -> [/Applications/Utilities/Keychain Access]

        • Use below menu [Request Certificate From a Certificate Authority] to request a certificate


        • Save CSR requests to your Hard Disk
                                       CSR File : MyDevCertificateSigningRequest.certSigningRequest


  • Start provisioning assistant from iOS Developer Center website
    • Click [Launch Assistant] button to start the provisioning process. 

      • Create Application ID

    • Follow steps as per Apple's Provisioning Assistant to finally get below two files
        • mobile provisioning certificate (DevelopmentProvisioningProfile_CapitalQuizApp.mobileprovision)
        • development certificate (ios_development.cer)
    • Exit the process after downloading above two files.
  • Install Development Provisional Profile (.mobileprovision) and development certificate (.cer) will below steps:
      • Install mobile provisioning certificate to XCode
        1. Double Click (.mobileprovision) file
        2. XCode will launch and silently install the profile
        3. Double check with, Xcode -> Window -> Organizer
      • Install development certificate (.cer) in to Key Chain
        1. Double Click (. cer) file
        2. Key chain utility will start and guide to install the .cer file

#6 Deploying IPhone Application to real handset

Below are the steps to deploy IPhone application to real handset
  1. Enroll into Apple's Developer Paid Program https://developer.apple.com/programs/
  2. Download and Install iOS development tools 
  3. Create Development provisioning profile
  4. For Distribution to App. Store create separate Distribution Profile
  • The purpose of Development provisioning profile is to identify and keep record of below attributes 
    • Developer ID; Who is the developer ?
    • Application ID to track the particular application being developed
    • Device ID i.e. Unique Device Identifier (UDID), such as : 45666f0704d13782e17395f594094b8dsds6
    • Further Reference:

         #7 Generating and Installing Development Provisioning Profile for IPhone

#5 Developer Registration

  • Two types
    • Free
      • Can download SDK (API + IDE Tools)
      • Can test application using Simulator
      • Can not deploy to real Handset due to no provisioning profile in free mode
      • Can not distribute to App. Store due to no provisioning profile in free mode
    • Paid
      • Can deploy to real Handset
      • Can distribute to App. Store 
      • Standard Membership (Individual and Company)
        • USD $ 99 yearly
      • Enterprise Membership
        • USD $ 299 yearly

#4 Available Hardware

  1. Accelerometer for Motion detection
  2. Gyroscope for Tilt detection
  3. GPS for location detection
  4. Digital compass for direction detection, such as North East West South
  5. Proximity and Light sensors for usage detection

#3 IPhone Specifications

  • Processor Speed 
    • ~ 400 MHz ARM in early models
    • ~ 600 MHz in 3Gs IPhone
    • 1 GHz A4 in Iphone 4
  • RAM (No Virtual RAM)
    • Virtual RAM allows to use Storage Memory as a RAM
    • 128 MB : 3G
    • 256 MB : 3Gs
    • 512 MB : 4
  • Connectivity
    • Bluetooth, mainly use to connect peripheral devices 
    • WIFI

#2 Display and Graphics

  • IPhone Screen : 320 x 480 points
  • IPhone 4 has scaling factor of 2 (to get real resolution of IPhone 4 device in pixels, multiply above points with the scaling factor, 320 x 2 and 480 x 2 pixels)
  • iOS Automatically scale your application to highest resolution using scaling factor for the device 
  • What is Pixel ?
    1. Abbreviation of "Picture Element"
    2. Color image pixel composed of RGB (Red[0-255], Green[0-255], Blue[0-255])
    3. Smallest controllable element on screen
    4. Smallest component of the digital image
    5. More pixels more closer to real image
    6. For example, 640 (width) x 480 (height) Pixels = 307,200 pixels (0.3 megapixels)
  • What is Resolution ?
    1. Pixel or Dots per image and bits of pixels (more bits more colors)
    2. VGA 640 x 480 = 0.3 megapixels
    3. SVGA 800 x 600 = 0.48 megapixels
    4. True Color use 24 bits per pixel to allow 16 million different colors


#1 Introduction of IPhone and IPad

  • In 2010 Apple introduced IPad and IPhone 4 platform with faster and high resolution hand sets
  • iPhone and iOS Versions
    • iPhone         : iOS 1.0
    • iPhone 3G   : iOS 2.0
    • iPhone 3GS : iOS 3.0
    • iPhone 4      : iOS 4.0
    • iPhone 4S    : iOS 5.0