Understanding accelerometer with iPhone

When you add a method for (void)acceleratedInX:(float)xx Y:(float)yy Z:(float)zz to any UIApplication, the iPhone sends regular messages to your application giving you values for X, Y, and Z.

X = Roll X corresponds to roll, or rotation around the axis that runs from your home button to your earpiece. Values vary from 0.5 (rolled all the way to the left) to -0.5 (rolled all the way to the right).

Y = Pitch. Place your iPhone on the table and mentally draw a horizontal line about half-way down the screen. That’s the axis around which the Y value rotates. Values go from 0.5 (the headphone jack straight down) to -0.5 (the headphone jack straight up).

Z = Face up/face down. I expected the Z value to correspond to yaw. And it does not. It refers to whether your iPhone is face up (-0.5) or face down (0.5). When placed on it side, either the side with the volume controls and ringer switch, or the side directly opposite, the Z value equates to 0.0.

Cited from: http://www.tuaw.com/2007/09/10/iphone-coding-using-the-accelerometer/

Blogged with the Flock Browser

NSURLConnection Usage

– (void)sendRequestToServer:(NSURL *)url httpBody:(NSString *)methodCallString
{

    NSMutableURLRequest *xmlrpcRequest =[NSMutableURLRequest requestWithURL:url
                                                                cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                                            timeoutInterval:60.0];
    [xmlrpcRequest setHTTPMethod:@”POST”];
    [xmlrpcRequest setValue:@”text/xml” forHTTPHeaderField:@”Content-Type”];
   
    // set the HTTPBody with the method call string as bytes
    const char *utfString = [methodCallString UTF8String];
   
    NSString *utfStringLenString = [NSString stringWithFormat:@”%u”, strlen(utfString)];
   
    [xmlrpcRequest setHTTPBody:[NSData dataWithBytes: utfString length:strlen(utfString)]];
   
    // Set the Content-Length header
    [xmlrpcRequest setValue:utfStringLenString forHTTPHeaderField:@”Content-Length”];
   
    // create the connection with the request and start loading the data
    if (!isConnectionBusy) {
        isConnectionBusy = YES;
        NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:xmlrpcRequest delegate:self];
       
        if (theConnection) {
            responseData = [[NSMutableData data] retain];
        } else {
            NSLog(@”Connection Failed!”);
        }
    }
}

– (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    if (responseData != NULL)
        [responseData setLength:0];
}

– (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [responseData appendData:data];
    //    NSString *responseString = [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] autorelease];
}

– (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    isConnectionBusy = NO;

    // release the connection, and the data object
    [connection release];
    // receivedData is declared as a method instance elsewhere
    [responseData release];
       
    // inform the user
    NSLog(@”Connection failed! Error – %@ %@”,
          [error localizedDescription],
          [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}

– (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    isConnectionBusy = NO;
   
    NSString *responseString = [[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding:NSUTF8StringEncoding];

    [connection release];
    connection = nil;
    [responseData release];

    [self parseData:responseString];
    [responseString release];
    // release the connection, and the data object
}

-(NSURLRequest *)connection:(NSURLConnection*) connection
            willSendRequest:(NSURLRequest*)    request
           redirectResponse:(NSURLResponse*) redirectResponse
{
    //NSLog(@”connection willSendRequest redirectResponse”);

    NSURLRequest *newRequest = request;
    if (redirectResponse)
    {
        newRequest=nil;
    }
    else
    {
    }
    return newRequest;
}

– (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
    return nil;
}

Blogged with the Flock Browser

Creating the SSL Certificate

Creating the SSL Certificate

1. Follow the steps given in the chapter 3 of Apple Push Notification Service Programming Guide to create SSL certificate.

2. Import the aps_developer_identity.cer to the keychain.Then you have to export these new cert and the private key of this cert (not the public key) and saved as .p12 files.

3. Then you use these commands to generate the cert and key in Mac’s Terminal for PEM format (Privacy Enhanced Mail Security Certificate)

  • openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12
  • openssl pkcs12 -nocerts -out key.pem -in key.p12    // key.p12 is the private key

4. The cert.pem and key.pem files will be used by your own program communicating with APNS.

5. Remove the passphase of private key in key.pem, do this

  • openssl rsa -in key.pem -out key.unencrypted.pem

6. Then combine the certificate and key

  • cat cert.pem key.unencrypted.pem > ck.pem

Reference :

Blogged with the Flock Browser