Saturday, October 5, 2013

Passbook App Development for iOS

Passbook is a new technology introduced in iOS6 and be quite tricky technology at first to master.
But here are few link to tutorials and helps that I hope will ease your pain.

Server API Sevices :
http://www.passdock.com/passbook-coupon/walmart-sales-coupon
http://passkit.com/

Tutorials :
http://www.raywenderlich.com/20734/beginning-passbook-part-1
http://www.raywenderlich.com/20785/beginning-passbook-in-ios-6-part-22
http://blogs.captechconsulting.com/blog/jonathan-tang/ios-6-tutorial-integrating-passbook-your-applications

Github Open source Codes :
https://github.com/passslot/passslot-ios-sdk

Design Passbook :
https://create.passkit.com/

Apple Developer Site Links:

iOS: Using Passbook
http://support.apple.com/kb/HT5483?viewlocale=en_US&locale=en_US

Passbook FAQ
https://developer.apple.com/library/ios/technotes/tn2302/_index.html

App Store Review Guidelines
23. Passbook
  • 23.1
    Passbook Passes can be used to make or receive payments, transmit offers or offer identification (such as movie tickets, airline tickets, coupons and reward offers). Other uses may result in the rejection of the App and the revocation of Passbook credentials
  • 23.2
    Passes must include valid contact information from the issuer of the pass or the App will be rejected and Passbook credentials may be revoked
  • 23.3
    Passes must be signed by the entity that will be distributing the pass under its own name, trademark, or brand or the App will be rejected and Passbook credentials may be revoked
PDFs:
Add to Passbook Badge
https://developer.apple.com/passbook/AddToPassbookBadgeGuidelines.pdf
Getting Started with Passbook on iOS 6
https://developer.apple.com/passbook/Getting_Started_with_Passbook.pdf

WWDC Videos:
https://developer.apple.com/wwdc/videos/?id=302
https://developer.apple.com/wwdc/videos/?id=303
https://developer.apple.com/videos/wwdc/2012/?id=301
https://developer.apple.com/videos/wwdc/2012/?id=309

Ebooks :
http://www.packtpub.com/passbook-applications-development-for-ios/book

Example Pass



Saturday, September 28, 2013

C++ beginers code for Objective-C Developers using XCode

Problem 1: Using CPP code show the use of If…Then…Else statement-using user input values.

Code

//
//  main.cpp
//  Hello World CPP
//
//  Created by Bishal Ghimire on 9/19/13.
//  Copyright (c) 2013 Bishal Ghimire. All rights reserved.
//

#include <iostream>

using namespace std;


/**
   IF then else function for using user input values
*/

int main(int argc, const char * argv[]) {

    int inputAge;
    std::cout << "Input You Age, !\n";
    cin >> inputAge;
   
   
    if (inputAge >= 18) {
        cout << "You can Vote ! \n";
    }
    else if (inputAge < 18) {
        cout << "You can NOT vote ! \n";
    }
    return 0;
}

Output

$ g++ main.cpp
$ ./a.out
Input You Age, !
 29
You can Vote !

Problem 2: Using functions show how you can swipe variables using call by reference.

Code

/**
    Function to swipe two variables using third temp value
 */
void swap(int *u, int *v) {
    int temp;
    temp = *u;
    *u = *v;
    *v = temp;
    return;
}

int main(int argc, const char * argv[]) {
       
    int firstValue;
    cout<<"Input First Value \n";
    cin >> firstValue;
   
    int secondValue;
    cout<<"Input Second Value \n";
    cin >> secondValue;
   
    swap(firstValue, secondValue);
   
    cout<<"First Value and Second Value after they are Swaped \n";
    cout << "1st = " << firstValue << "\n2nd = " << secondValue;
    cout<<"\n";
    return 0;
}

Output

$ g++ main.cpp
$ ./a.out
Input First Value
12
Input Second Value
34
First Value and Second Value after they are Swaped
1st = 34
2nd = 12

Problem 3: Demonstrate the use of functional overloading in CPP (C++)

 Code

/**
  functionOverLoading.cpp
*/

#include "functionOverLoading.h"

using namespace std;

#define pi 3.141

/**
 Function overloading
 */
class fxn {
public:
    void area(int);              // circle
    void area(int, int);         // rectangle
    void area(int, int, int);    // triangle
};

void fxn::area(int a) {
    cout<<"Area of Circle: "<<pi*a*a;
    cout<<"\n";
}

void fxn::area(int a, int b) {
    cout<<"Area of rectangle: "<<a*b;
    cout<<"\n";
}

void fxn::area(int a, int b, int c) {
    // cout<<"Area of triangle: "<<a*b*c;
    cout<<"\n";
}

typedef enum ChoiceType
{
    choiceCircle    = 1,
    choiceRectangle,
    choiceTriangle,
    choiceExit
} ChoiceType;


int main(int argc, const char * argv[]) {
   
    int choice;
    int radius;
    int length;
    int breath;
    int sideA, sideB, sideC;
    fxn object;
   
    cout<<"\n\t\tFunction Overloading";
    cout<<"\n 1. Area of Circle \n 2. Area of Rectangle \n 3. Area of Triangle \n 4. Exit \n ";
    cout<<"Enter your Choice:";
    cin>>choice;
   
    switch (choice) {

        case choiceCircle:
            cout<<"Enter Radious of the Circle:";
            cin>>radius;
            object.area(radius);
            break;

        case choiceRectangle:
            cout<<"Enter Sides of Rectangle:";
            cin>>length>>breath;
            object.area(length, breath);
            break;

        case choiceTriangle:
            cout<<"Enter Sides of triangle:";
            cin>>sideA>>sideB>>sideC;
            object.area(sideA, sideB, sideC);
            break;

        case choiceExit:
            exit(0);
            break;

        default:
            break;
    }
    return 0;
}

Output 

$g++ functionOverLoading.cpp –o functionOverLoading
$ ./functionOverLoading

Function Overloading
 1. Area of Circle
 2. Area of Rectangle
 3. Area of Triangle
 4. Exit
 Enter your Choice:1
Enter Radious of the Circle:10
Area of Circle: 314.1


$ ./functionOverLoading
            Function Overloading
 1. Area of Circle
 2. Area of Rectangle
 3. Area of Triangle
 4. Exit
 Enter your Choice:2
Enter Sides of Rectangle:10 12
Area of rectangle: 120


Wednesday, September 25, 2013

Avoid Keyboard in UITableView Cell

The best solution to avoid keyboard in iOS in table view are to use framework called TPKeyboardAvoid https://github.com/michaeltyson/TPKeyboardAvoiding

But, if you need some manual solution here are few codes

-(void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];

}

-(void) viewDidDisappear:(BOOL)animated  {
    [super viewDidDisappear:YES];
    blogParser.delegate = nil;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

-(CGFloat)getLabelHeightForIndex:(NSInteger)index
{
    CGSize maximumSize = CGSizeMake(230, 10000);
    Blog_Comment *comment = comments[index];
    
    CGSize labelHeighSize = [comment.comment sizeWithFont: [UIFont fontWithName:@"Helvetica" size:12.0f]
                                     constrainedToSize:maximumSize
                                         lineBreakMode:NSLineBreakByCharWrapping];
    return labelHeighSize.height;
    
}

#pragma mark - Notification 

-(void) moveTableViewBottomRowUp:(NSNotification *)note {
    NSDictionary *userInfo = [note userInfo];
    CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    kKeyboardHeight = kbSize.height;
    
    NSTimeInterval duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    [UIView animateWithDuration:duration animations:^{
        UIEdgeInsets edgeInsets = UIEdgeInsetsMake(0, 0, kbSize.height, 0);
        [_tableView setContentInset:edgeInsets];
        [_tableView setScrollIndicatorInsets:edgeInsets];
//        [_tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[_tableView numberOfRowsInSection:0]-1 inSection:0]
//                          atScrollPosition:UITableViewScrollPositionTop
//                                  animated:YES];
    }];
}

-(void) moveTableViewBottom2Normal:(NSNotification *)note {
    NSDictionary *userInfo = [note userInfo];
    NSTimeInterval duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    [UIView animateWithDuration:duration animations:^{
        UIEdgeInsets edgeInsets = UIEdgeInsetsZero;
        [_tableView setContentInset:edgeInsets];
        [_tableView setScrollIndicatorInsets:edgeInsets];
    }];
}

-(void) assignKeyBoardHeigh:(NSNotification *) note {
    NSDictionary *userInfo = [note userInfo];
//    NSTimeInterval duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    kKeyboardHeight = kbSize.height;
}

-(void) keyboardWillShow:(NSNotification *)note {
    [self assignKeyBoardHeigh:note];
    [self moveTableViewBottomRowUp:note];
    [self moveTextFieldUp];
}

-(void) keyboardWillHide:(NSNotification *)note {
//    [self moveTableViewBottom2Normal:note];
    [self moveTexyFieldDown];
}


-(void) moveTextFieldUp {
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:0.2];
    CGRect frame = viewComment.frame;
    frame.origin.y = self.view.bounds.size.height - kKeyboardHeight - frame.size.height;
    viewComment.frame = frame;
    // DLog(@"%f", viewComment.frame.origin.y);
    [UIView commitAnimations];
}

-(void) moveTexyFieldDown {
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:0.2];
    CGRect frame = viewComment.frame;
    frame.origin.y = self.view.bounds.size.height - frame.size.height;
    viewComment.frame = frame;
    
    // DLog(@"%f", viewComment.frame.origin.y);
    [UIView commitAnimations];
}



http://iphoneimei.info/