Friday, June 29, 2012

APDU


APDU message command-response pair

There are two categories of APDUs: command APDUs and response APDUs. A command APDU is sent by the reader to the card – it contains a mandatory 4-byte header (CLA, INS, P1, P2) and from 0 to 255 bytes of data. A response APDU is sent by the card to the reader – it contains a mandatory 2-byte status word and from 0 to 256 bytes of data.
Command APDU
Field nameLength (bytes)Description
CLA1Instruction class - indicates the type of command, e.g. interindustry or proprietary
INS1Instruction code - indicates the specific command, e.g. "write data"
P1-P22Instruction parameters for the command, e.g. offset into file at which to write the data
Lc0, 1 or 3Encodes the number (Nc) of bytes of command data to follow
Command dataNcNc bytes of data
Le0, 1, 2 or 3Encodes the maximum number (Ne) of response bytes expected
Response APDU
Response dataNr (at most Ne)Response data
SW1-SW2
(Response trailer)
2Command processing status, e.g. 90 00 (hexadecimal) indicates success

Abbreviations and Notation

For the purposes of this part of the ISO/IEC 7816, the following abbreviations apply :
APDUApplication protocol data unit
ATRAnswer to reset
BERBasic encoding rules of ASN.1 (see annex D)
CLAClass byte
DIRDirectory
DFDedicated file
EFElementary file
FCIFile control information
FCPFile control parameter
FMDFile management data
INSInstruction byte
MFInstruction byte
P1-P2Parameter bytes
PTSProtocol type selection
RFUReserved for future use
SMSecure messaging
SW1-SW2Status bytes
TLVTag length value
TPDUTransmission protocol data unit

For the purposes of this part of ISO/IEC 7816, the following notation applies :
< TR>
'0'-'9' and 'A'-'F'The sixteen hexadecimal digits
(B1)Value of byte B1
B1||B2Concatenation of bytes B1 (the most significant byte) and B2 (the least significant byte)
#Number

Friday, June 15, 2012

setup your new account for xcode build

We always need to setup an account for the ant build for xcode. It is not complex compare to other mobile builds like Android or Blackberry. Here are the simple steps you need to do


  • Enable your remote login. (go Preference --> Sharing -->Remote Login enabled)
  • Add build account if needed. (Add new account from Preference-->User&Group)
  • Setup your source control account, like svn or git to check out code
  • Setup your Xcode, get the AD-HOC provision profile you are going to use.
  • Setup your distribution account on the build machine (generate the key pair kind of work, or inport existing p12)
  • Setup Keychain, move the Distribution private key pair from login to the System This is a key step for ssh client, else you will get error complaining permission.

release your iPhone app over air

I have been testing the way to release ipa OTA. Saw several problems till finally work, here are things I have experienced.

I saw sometimes the http://domanname was added in front of "itms-services://", broke the link and got 404 error. Put "_blank" target in front if you saw this.

 <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”  
     “http://www.w3.org/TR/html4/loose.dtd”>  
 <html>  
 <head>  
 <title>My Cool app</title>  
 </head>  
 <body>  
 <ul>  
   <!--li><a href=”http://mycoolapp/build/distribution.mobileprovision”>  
         Install Example Provisioning File</a></li-->  
   <li><a target="_blank" href="itms-services://?action=download-manifest&url=http://horizonstonetech.com/git/test.plist">  
         Install Example Application</a></li>  
 </ul>  
 </body>  
 </html>  


A good guide to follow with screen shots.

http://blog.markhorgan.com/?p=322


  1. Problem: After executing Build and Archive, Organizer does not automatically open

    Solution: Make sure your application identifier matches the id linked to your Ad Hoc provision file

    This may not be a pertinent step to a successful distribution, but I include here because the behavior of XCode was affected. Each Ad Hoc build is configured to use an Ad Hoc provision file which in turn is linked to an Application Identifier configured in the program portal. These identifiers are usually reverse domain in the form of "com.yourcompany.*". When creating a new XCode project, the default application id is something like "com.yourcompany.${PRODUCT_NAME:rfc1034identifier}". Modify the identifier to match the configuration set in your program portal. After the "Build and Archive" process completes, Organizer should open automatically with your new "Archived Application" listed below.
  2. Problem: Download Application link does not work

    Solution: Make sure your web server has the correct MIME type set for both .plist and .ipa files

    Property List (.plist) and iPhone Application Archive (.ipa) files are served to the iPhone OS devices from your web server. Most web servers, in my case IIS, do not have a MIME type mapping for these file types. When tapping the "download application" link from the HTML page, the page did not initiate a download. The download does not work. It just sat there as if I did not tap at all. In IIS, when the MIME type is not recognized the web server delivers a 404 Page not Found error. The download will not start because the web server thinks the file does not exist, even though we know it does. Since the "download application link" uses the itms-services protocol, the server error does not get relayed to the user interface. Adding the MIME type to the web server's list corrects this problem and can be verified using a web browser. The MIME types for these files are:

    .plist - text/xml
    .ipa - application/octet-stream
  3. Problem: Download Application link still does not work

    Solution: Remove any spaces from your absolute URL's file name and web folder structure

    I beat my head against the wall on this for a while. It seems logical that a project file or web folder could have spaces in the name since we have a function of URL Encoding, but URL Encoded resources appeared to be the make it or break your head on the wall factor. I had %20 URL Encoded spaces in my web folder hosting the .ipa and .plist files and also had spaces in the file names. Removing the spaces made that "download application link" WORK. I can't explain it nor did I submit a bug report. Could be by design or an oversight. Just check it out for your own sanity.

Thursday, June 14, 2012

The macro to support ARC with no code changes.


If you are converting to ARC, why don't you just modify the macro to #define ReleaseAndSetToNil(x) x = nil;?
In your existing code, after switching to ARC, this will be essentially the same.