On my work, technology and related stuff....

About me

Hi, I am Priya Rajagopal- a technologist, software architect and developer. I have worked on a wide range of technologies in my career. My current passion is mobile development. The notion of a customizable and powerful computing platform in the palm of your hand (literally) is very exciting.
Read more..

What else?

17 comments

This post describes how to invoke a SOAP based web service from your iOS app. The post is not going to dwell into the discussion of SOAP based versus a RESTful service and neither is it intended to be a tutorial on SOAP. For more information on the latter,there are plenty of online resources including the W3C (http://www.w3.org/TR/soap/). This post assumes that your needs require invocation of SOAP based web services from your iOS app.

We will use a free online web service http://www.webservicex.net/CurrencyConvertor.asmx?WSDL for our example. This is a very simple web service handles currency conversions (surprise!).

I recommend a free utility called "wsdl2objc" which generates client-side Objective-C code from a SOAP Web Services Definition File (WSDL) file. You can always construct the SOAP request messages and parse the SOAP responses on your own without the tool, however, the tool does a lot of the heavy lifting and is convenient.

1. Download the wsdl2objc tool from http://code.google.com/p/wsdl2objc/

2. Run the wsdl2objc tool . Enter the source URL for the WSDL and the destination folder for the generated ObjC files and select "Parse WSDL" button. A screenshot of the same is shown below

3. Once the "Parse WSDL" process completes, you should see a number of ObjC files in the destination folder.

4. Follow the following steps to integrate the ObjC files into your app.
4a) Copy the ObjC files that were generated in the previous step to your app project. Make sure you select the "Copy Files Into Destination Folder" option.
Description: Macintosh HD 2 Mountain Lion:Users:mactester:Downloads:post:screenshot-copyfiles.png

4b) If you are using ARC in your project, you will have to disable ARC for the generated ObjC files. To do this, go to the "Compile Sources" section of "Build Phases" of your project and specify the "-fno-objc-arc" compiler flag for all the generated files.
Description: Macintosh HD 2 Mountain Lion:Users:mactester:Downloads:post:screenshot-disableARC.png

4c) If you already have libxml2 installed on your system (look for libxml2.dylib in /usr/lib folder), then skip this step. Otherwise, follow the steps in (4c) to install libxml2 library
4c-1)  Install the macports package installer from http://www.macports.org/install.php (if you don't have it already)
4c-2) Install libxml2 library by executing the following command in a terminal window
        sudo port install libxml2

(*Tip* For the build to work for libxml2, make sure you have the command line tools installed for Xcode )

4d) In the target "Build settings", include "-lxml2" in the "Other Linker Flags"  property
Description: Macintosh HD 2 Mountain Lion:Users:mactester:Downloads:post:screenshot-linkerflags.png

4e) In the target "Build settings", include "/usr/include/libxml2" in the "Header Search Paths"  property

Description: Macintosh HD 2 Mountain Lion:Users:mactester:Downloads:post:screenshot-headerfiles.png

4f) Import "CurrencyConvertorSvc.h" file into your implementation file and use the methods provided by this interface to make the appropriate web services calls.

The following code snippet demonstrate its usage


-(void)processRequest

{

    CurrencyConvertorSoapBinding* binding = [CurrencyConvertorSvcCurrencyConvertorSoapBinding];

    CurrencyConvertorSoapBindingResponse* response;

    CurrencyConvertorSvc_ConversionRate* request = [[CurrencyConvertorSvc_ConversionRatealloc]init];

    request.FromCurrencyCurrencyConvertorSvc_Currency_enumFromString(self.fromCurrencyTextField.text);

    request.ToCurrency = CurrencyConvertorSvc_Currency_enumFromString(self.toCurrencyTextField.text );

    response = [binding ConversionRateUsingParameters:request];

 

    dispatch_async(dispatch_get_main_queue(), ^{

        [self processResponse:response];

    });

}

 

 


-(void) processResponse: (CurrencyConvertorSoapBindingResponse*)soapResponse

{

    NSArray *responseBodyParts = soapResponse.bodyParts;

    id bodyPart;

    [self.activitystopAnimating];

    [self.activityremoveFromSuperview];

    @try{

        bodyPart = [responseBodyParts objectAtIndex:0]; // Assuming just 1 part in response which is fine

 

    }

    @catch (NSException* exception)

    {

        UIAlertView* alert = [[UIAlertViewalloc]initWithTitle:@"Server Error"message:@"Error while trying to process request"delegate:selfcancelButtonTitle:@"OK"otherButtonTitles: nil];

        [alert show];

        return;

    }

 

    if ([bodyPart isKindOfClass:[SOAPFault class]]) {

 

        NSString* errorMesg = ((SOAPFault *)bodyPart).simpleFaultString;

        UIAlertView* alert = [[UIAlertViewalloc]initWithTitle:@"Server Error"message:errorMesg delegate:selfcancelButtonTitle:@"OK"otherButtonTitles: nil];

        [alert show];

    }

    elseif([bodyPart isKindOfClass:[CurrencyConvertorSvc_ConversionRateResponseclass]]) {

        CurrencyConvertorSvc_ConversionRateResponse* rateResponse = bodyPart;

        UIAlertView* alert = [[UIAlertViewalloc]initWithTitle:@"Success!"message:[NSStringstringWithFormat:@"Currency Conversion Rate is %@",rateResponse.ConversionRateResult] delegate:selfcancelButtonTitle:@"OK"otherButtonTitles: nil];

        [alert show];

 

    }

 

}

 

An example project can be downloaded from the following link-  SOAP Test. The project has been built using Xcode 4.5.

5 comments

If you have an iPhone app or are developing one, with the launch of iPhone5 , you  need to ensure that your images scale to support the new taller retina display (640X1136).

In case of the launch image, naming the new launch with the suffix "-568h@2x" (e.g.. Default-568h@2x) will ensure that the system picks up the right launch image for the iPhone5.

However, just adding the "-568h@2x" to the new images is not sufficient to have the system pick the right images for the tall retina display. Here is a very simple category on UIImage that can be used to return the right image. Note that in the category implementation, I assume that all the iPhone5 specific images are named with a suffix of "-568h@2x".

 

The "UIImage+iPhone5extension.h" Interface definition

#import <UIKit/UIKit.h>

@interface UIImage (iPhone5extension)

+ (UIImage*)imageNamedForDevice:(NSString*)name;

@end

 

 

 

The "UIImage+iPhone5extension.m" file implementation

#import "UIImage+iPhone5extension.h"

@implementation UIImage (iPhone5extension)

+ (UIImage*)imageNamedForDevice:(NSString*)name {

 UIImage *returnImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@", name]];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
 {
if (([UIScreenmainScreen].bounds.size.height * [UIScreenmainScreen].scale) >=1136)
 {
 return [UIImage imageNamed:[NSString stringWithFormat:@"%@-568h@2x", name]];
 }
 }

 return returnImage;
}

@end

 

 

Just include the above files in your project and replace relevant occurrences of [UIImage imageNamed:] call with [UIImage imageNamedForDevice:]. This would ensure that right image is picked up for non-retina,retina and tall retina versions of the resolution.

 

Mobile Video Streaming

Feb 07, 2012

10 comments

Consumption of mobile streaming video is on an upward trend. Supporting video streaming on mobile platforms presents a lot of challenges, primarily due to the diversity of devices. The decisions include encodings , file formats, streaming protocol etc. Content Distribution Networks (CDNs) and video delivery platforms exist today to alleviate the process so you don't have to worry about the video delivery aspect and can focus on the mobile app that consumes the video.
However, in order to make an informed choice about the CDNs and their offerings and the video delivery platforms, a background on mobile streaming technologies is imperative.
I recently gave a presentation at the local Mobile Monday meeting that provides an overview of mobile streaming technologies, mobile platform specific requirements and the challenges. Click Here to download the presentation.

2 comments

If you are developing for/on a jailbroken iPhone or iPad you are more than likely going to have to SSH into your iDevice a number of times. This includes transferring files to/from the device via SCP. Entering a password every time you have to SSH into the device is very tedious.  Moreover, this becomes imperative if you need automation scripts to SSH/SCP into the device
 
This post explains how you can enable public-key authentication with SSH in order to bypass the password entry process. Note that enabling password-less entry into your iDevice is a potential security risk because anyone with access to your system can now access/control your device without any authentication. So if you enable this, be sure to secure access to your systems!

The steps to enable public-key authentication with the iPhone/iPad are no different than with any UNIX system.
 
The following commands need to be executed on the system from which you would be SSHing into your iPhone/iPad.
If you are using a Mac or a Linux system, the commands are executed from the terminal window.  If you are using a Windows PC, you would have to run these commands within Cygwin

  • Go to the .ssh folder

MyMacBook-Pro-2:~.mactester$ cd ~/.ssh

  • Generate public/private key-pair by running the ssh-keygen command. You will be prompted for some information. You can leave the file to save the key as default. Enter a passphrase . You will be prompted for the passphrase when you try to access your key.

MyMacBook-Pro-2:.ssh mactester$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/Users/mactester/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/mactester/.ssh/id_dsa.
Your public key has been saved in /Users/mactester/.ssh/id_dsa.pub.

  • A public/private key pair would have been generated in the .ssh folder. The .pub file corresponds to the public key.

MyMacBook-Pro-2:.ssh mactester$ ls
id_dsa             id_dsa.pub

  • Copy the PUBLIC KEY over to the ~/.ssh folder of your iPhone/iPad (in this example, the IPAddress of my device is 192.168.1.10)

MyMacBook-Pro-2:.ssh mactester$ scp id_dsa.pub root@192.168.1.10:~/.ssh

The following commands need to be executed on your iPhone/iPad.
For this, you can SSH into the iDevice  (You would still be prompted for a password at this stage) or  you can type in the following commands directly in the terminal application window of your jailbroken iDevice

  • Save the public key as “authorized_keys”. If you already have public keys associated with other systems stored on your device, be sure to append the public key to “authorized_keys2” as shown in the example below. Make sure you set the right access permissions on the key.

MyiPhone:~root# cd ~/.ssh
MyiPhone:~/.ssh root# cat id_dsa.pub >> authorized_keys2
MyiPhone:~/.ssh root#chmod 0600 authorized_keys2

That’s it. The next time you SSH into your iDevice, you will not be prompted for a password.
 

19 comments

iOS devices support the delivery of multimedia content via HTTP progressive download or HTTP Live streaming . As per Apple's guidelines to App developers, "If your app delivers video over cellular networks, and the video exceeds either 10 minutes duration or 5 MB of data in a five minute period, you are required to use HTTP Live Streaming. (Progressive download may be used for smaller clips.)". 

This article discusses a method for generating HTTP live streaming content using freely available tools. If your needs are large scale, then you may need to explore commercial encoders such as the Sorenson Squeeze 7 or other commercial video platforms. This article does not describe commercial video platforms. 

HTTP Live Streaming – A (Very) Brief Overview:

 In HTTP Live streaming, the multimedia stream is segmented into continuous media segments wherein each media chunk/segment holds enough information that would enable decoding of the segment. A playlist file is a list of media URIs, with each URI pointing to a media segment. The media URI’s are specified in the order of playback and the duration of the playlist file is the sum of the durations of the segments. Media playlist files have an “.m3u8” extension. The servers host the media segments and the playlist file. In order to playback content, the media streaming app on the device fetches the playlist file and the media segments based on the media URIs specified in the playlist . The transport protocol is HTTP.
Now, you can have multiple encodings/renditions of the same multimedia content. In this case, you can specify a variant playlist file that will contain URIs to the playlist files corresponding to each rendition of content. In this case, the iDevice can switch between the various encodings thereby adapting to changing network bandwidth conditions. HTTP Live Streaming is essentially a form of adaptive streaming. You can get more details from the IETF I-D available here. Other well-known adaptive streaming protocols include that of Microsoft’s Smooth Streaming , Adobe’s Dynamic Streaming  and the DASH standards specification .

Encoding the content using Handbrake:

  1. Among the free tools, I’ve found Handbrake to be the best in terms of performance and supported formats. Versions are available for Windows and the Mac. In my experience, the Mac version stalled a few times during encoding and at times hogging all the CPU cores on my Macbook Pro. The Windows version worked flawlessly.

  2.  Use the following encoding guidelines provided by Apple to encode your content. If you expect your app users to be able to access the content under a variety of network conditions (wifi, cellular etc), you would want to support multiple encodings of the content .

 
 
 

The Tools for generating content for HTTP Live Streaming :

Once you have encoded your content, you would have to prepare it for delivery via HTTP live streaming. There are a command line utilities available for the Mac that can be downloaded for free from  http://connect.apple.com/ (You would need an Apple developer Id for installing the tools, which again is free). You would need the following tools –

  • mediafilesegmenter

  • variantplaylistcreator

Once installed, they would be available in/usr/bin directory of your Mac.

 Segmenting your encoded content:

Use the mediafilesegmenter tool to segment the encoded media files.  You would need to be “root” user in order to run the tool.
 
/usr/bin/mediafilesegmenter [-b | -base-url <url>]
                        [-t | -target-duration duration]
                        [-f | -file-base path] [-i | -index-file fileName]
                        [-I | -generate-variant-plist]
                        [-B | -base-media-file-name name] [-v | -version]
                        [-k | -encrypt-key file-or-path]
                        [-K | -encrypt-key-url <url>]
                        [-J | -encrypt-iv [random | sequence]]
                        [-key-rotation-period period]
                        [-n | -base-encrypt-key-name name]
                        [-encrypt-rotate-iv-mbytes numberMBytes]
                        [-l | -log-file file] [-F | -meta-file file]
                        [-y | -meta-type [picture | text | id3]]
                        [-M | -meta-macro-file file]
                        [-x | -floating-point-duration] [-q | -quiet]
                        [-a | -audio-only] [-V | -validate-files] [file]
 

 

  • Open a terminal window on your Mac.
  • Type “man mediafilesegmenter”at the command link prompt to get a full description of the usage of the tool.

          <command prompt>$ man mediafilesegmenter
 

  • An example of using the tool to segment a media file named “mymedia_hi.mp4”  is as follows-

        <command prompt>$ sudo /usr/bin/mediafilesegmenter -I -f mymedia_hi -f mymedia_hi.mp4
You will be prompted for the root password (which you must provide)
 
In the example, the media file “mymedia_hi.mp4” is assumed to be present in the current directory from which the command is executed. Otherwise, be sure to specify the path to the media file. The segments will be generated in a subfolder named “mymedia_hi” within the current directory.
 
<command prompt>$ cd mymedia_hi
<command prompt>$ ls
<command prompt>$
fileSequence0.ts           fileSequence14.ts         fileSequence6.ts
fileSequence1.ts           fileSequence15.ts         fileSequence7.ts
fileSequence10.ts         fileSequence2.ts           fileSequence8.ts
fileSequence11.ts         fileSequence3.ts           fileSequence9.ts
fileSequence12.ts         fileSequence4.ts           prog_index.m3u8
fileSequence13.ts         fileSequence5.ts

 
The fileSequence*.ts files correspond to the media segments which are MEPG2 transport streams. The prog_index.m3u8 is the playlist file corresponding to the segmented media file and specifies the media URIs to the segments.
 

  • The “-I” option that I specified in the example command will generate a variant plist file.  The variant plist file would be subsequently required to generate the variant play list file  as described in the next step. You don’t need this option if you don’t plan on streaming multiple encodings of your content.

         Assuming you are in the “mymedia_hi” folder, type the following to get the list of generated variant plist files.
 
<command prompt>$ cd ..
<command prompt>$ ls *.plist
<command prompt>$
mymedia_hi.plist

 

Generating variant playlist file :


If you do not intend to stream multiple renditions of the content , you can skip this step and proceed to the “Streaming the Content” section.

  • Follow the procedures specified in “Segmenting your encoded content” section to segment every encoding of the media content that you wish to stream.  For example, if you plan on supporting three renditions of your media content for high, medium and low network bandwidth conditions respectively, you will have to use the “mediafilesegmenter” tool to segment each of those renditions.

  • Use the tool variantplaylistcreator for generating the variant playlist file.

    /usr/bin/ variantplaylistcreator [-c | -codecs-tags] [-o | -output-file fileName]
    [-v | -version] [<url> <variant.plist> ...]

 

  • Type “man variantplaylistcreator” at the command link prompt to get a full description of the usage of the tool.

    <command prompt>$ man variantplaylistcreator
 

  • An example of using the tool to generate a variant playlist file named “mymedia_all.m3u8”  is as follows-

<command prompt>$ sudo /usr/bin/variantplaylistcreator -o mymedia_all.m3u8 http://mywebserver/mymedia_lo/prog_index.m3u8 mymedia_lo.plist http://mywebserver/mymedia_med/prog_index.m3u8 mymedia_med.plist http://mywebserver/mymedia_hi/prog_index.m3u8 mymedia_hi.plist
 

You will be prompted for the root password (which you must provide)
 
The URL that is associated with the prog_index.m3u8 files for each encoding corresponds to the URL of the webserver that will be used for hosting/streaming the media content.
 

  • The generated variant play list file “mymedia_all.m3u8” will specify the URIs to playlist files (prog_index.m3u8) corresponding to each encoding of the media file. The contents of the file (viewable using your favorite text editor) should be something like this 

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=87872
http://mywebserver/mymedia_lo/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=100330
http://mywebserver/mymedia_med/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1033895
http://mywebserver/mymedia_hi/prog_index.m3u8

 

Streaming the Content:

  1. Upload the variant playlist file (mymedia_all.m3u8 in our example) and ALL the sub-folders that contain the generated segments for every rendition of the media file to the web server that will stream the content. You do not have to copy the media files (eg .mp4 files) from which the segments were generated. You could host it on any regular web server such as the Apache Webserver or Microsoft's IIS. For instance, on an Apache server on Windows, you would copy all this to the “htdocs” folder. This would be something like this-  c:\Program Files(x86)\Apache Software Foundation\Apache2.2\htdocs.

  2. Typically you would need to make no changes to the web server in order to stream the content. In some cases, you may need to update the  webserver configuration file to add support for the .m3u8 MIME type . I had to do this for my IIS web server where I associated the .m3u8 extension with “application/octet-stream” MIME type. 

Note: If your needs are large scale, you would employ the services of a Content Distribution Network (CDN) such as Akamai to publish and distribute your content.

Accessing the Content from your iDevice:

  1. In order to access the streaming content on your iDevice, the media URL must point to the appropriate playlist (.m3u8) file. This would correspond to either the Variant playlist file if you support multiple encodings of the content (mymedia_all.m3u8 in our example) or the prog_index.m3u8 playlist file for the specific encoding of the content.

Example: http://<webserver>/<path to the .m3u8 playlist file>
 
If you do not have a streaming app, you can open the URL in the Safari browser on your device. If everything goes well, the stream should start playing on your device.
 

3 comments

Like the million plus who pre-ordered their iPhone4S, I anxiously waited for my shiny new phone.  And like most of them, I was most curious about  Siri- The smart new voice recognition system unique to the iPhone4S. I’ve not had much luck with voice recognition/voice activation systems in the past- Even the rudimentary voice-control systems like a voice-activated dialer have been quite frustrating to say the least. I was interested in how well Siri would fare with my accent (quite frankly, I don’t know what accent I have- It’s a blend) and how fast Siri would respond to my commands.   Also, if Siri cares about bad (English) grammar (not that I have it!).
Voice and Natural Language processing is highly resource-intensive and the voice recognition features found on resource constrained devices rely on servers in the cloud to do the processing. This means that there is network latency to be factored into the response times. So I was curious to see if Siri works in offline mode for if it did, that would be stupendous!!
 
So when my phone arrived today, the Siri was pretty much the first feature I checked out.
OK- So not surprisingly, Siri requires an Internet connection. It sends your commands to servers in the cloud (iCloud?) to do the processing. That said, depending on the speed of the connection, the response times can vary.
 
And it responds in a woman's voice. I'm not sure why thats the case, but most voice command systems , including my GPS do. (Update: I recently found this article that might have some answers on this topic- http://edition.cnn.com/2011/10/21/tech/innovation/female-computer-voices/)

 
First, I started off with the “typical” questions. Here are a few of them  -
 
Me: “I am thinking of lunch at 12:00 today
Siri: I found 16 restaurants whose reviews mention lunch. …14 of them are fairly close to you.
 
Me: “I have to remember to pick up my daughter at 5:30PM today”
Siri: What time shall I remind you?
Me: 5:30 PM
Siri: Shall I set the reminder for 5:30 today?

Me: What are new movie releases in the US?
Siri:  I found a number of movie theaters in Washington
 
And it provided me with a list of movie theaters. But why Washington??That’s no where  close to where I live!
 
Overall, it did a decent job of understanding my accent. In fact, it did something which most of my American friends never do- pronounce my husband's last name (17 letters long) correctly!! It won brownie points right there!
 
It was not perfect- it didn’t accurately recognize words a couple of times but still understood the intent which is probably the more important part.
The Artificial Intelligence system relies on certain keywords to accomplish its tasks- For instance, “Remind” or “Remember” for setting up reminders . So a command like “Ihave to pick up my daughter at 5:30 today” does not evoke a response to set up the reminder. Instead, it responds “I don’t know want you mean by “pick up my daughter at 5:30 today’”.  Since it leverages the information about your contacts, location , address books etc to do the processing and customize the results, the accuracy of responses may vary.
 
Then as any normal person would do, for the fun of it, I decided test a slew of ambiguous or weird questions –
Me: Are you my friend?
Siri: No comment!
 
Me: I am bored. What should I do?
Siri: I’ll see what I can do to entertain you.
 
I then eagerly waited expecting it to for instance, provide me a list of movies or something- It didn’t do anything.
 
Me: I am sleepy
Siri:  I hope you are not driving!
 
Siri is funny too!
 
My initial reaction is that I am quite impressed with Siri. It handles the routine commands very well. Unlike previous voice command systems, I will be using it often. Over time, I’ll find out if it learns and responds better. Not sure if it’s a good thing, but long term, I can see this becoming a companion to a loner or a sounding board of sorts. When the APIs to Siri go public, this can open up a whole range of new possibilities to the developer community. For example, an app that takes images of you in your new dress and responds to the question- “Does this dress make me look fat?” and pat response is  “Yes Siree!!

31 comments

Earlier this week, I jailbroke my iPhone4 iOS4.3.5 device. The jailbreak solution that is currently available for iOS4.3.5 is tethered jailbreak. If you are not familiar with “Tethered Jailbreak”, it essentially means that rebooting the jailbroken device would require it to be connected /tethered to the PC/MAC. This is of course not ideal but under the circumstances, this was my only option (And no-I couldn’t downgrade to iOS 4.3.3 for various reasons which are not directly relevant to this post).
 

Installing the jailbreak Software

I used Redsn0w V0.9.8b3 jailbreak tool. Follow the instructions provided here. The process is very straightforward.
 

Cydia Crashing Issue

Although the jailbreak completed successfully, the Cydia icon was white and it crashed as soon as I clicked on it. To get around it, I rebooted the device by running Redsn0w in tethered mode. Be sure to check the “Just boot tethered right now” option on Redsn0w . Once the device rebooted, the Cydia app started working. No more crashes. I was able to download and install apps.  Unfortunately, some of them required a reboot and I had to go through the tethered reboot process again
The  MobileTerminal, OpenSSH and Aptupdate for SBSettings were among the packages that I installed. These packages will come in handy as you will see below.
 

Installing third party apps directly

Next, I wanted to install a third party app directly to the phone. The third party app was not available through Cydia sources or the AppStore.
For this, I copied the .app file corresponding to my app into the /Applications folder on the iPhone , created the /var/mobile/Documents folder and updated the file permissions by running the commands listed below from a terminal window on my MAC. Ofcourse,  I substituted "IPhoneIPAddress" with the IPAddress of my jailbroken phone while executing the commands

scp -r MyApp.app root@<iPhoneIPAddress>:/Applications/
ssh root@<iPhoneIPAddress>:/'chmod -R 755 /Applications/MyApp.app'
ssh root@<iPhoneIPAddress>:/ 'mkdir /var/mobile/Documents;chmod -R 777 /var/mobile/Documents'

Note: Creation of the Documents folder is required only the first time (unless you delete it between installations)
I rebooted the device in tethered mode. When the device rebooted, the app was ready. I could launch it and run it.
So far, so good until..

I tried to launch Cydia app, it crashed. All the other apps on the phone worked as normal.
 

Cydia Crashing Issue..Again.

So I rebooted the phone again in tethered mode.  This time the reboot had no effect. The other option was to re-jailbreak but I did not want to do that just yet.
Instead, I uninstalled and re-install the Cydia app by running the following commands from the terminal window of my MAC.  I substituted "IPhoneIPAddress" with the IPAddress of my jailbroken phone while executing the commands
 

ssh root@<IPhoneIPAddress>
apt-get remove Cydia
killall –HUP SpringBoard
apt-get install Cydia
killall –HUP SpringBoard

 
Note: The AptUpdate for SBSettings that I installed earlier automatically installed the apt tools .
Once I did that, cydia was back up and running again. I currently have version 1.1.1 of Cydia on the phone. Everything else continues to work as expected.
Now, its appears that installing the third party app caused Cydia to crash but it is unclear to me why that was the case because Cydia started working again after re-installation and the third party app continues to work as well. In any case, now I know what I should do to resolve the problem should it resurface but its less than ideal.
 

In Conclusion..

With the number of reboots that I had to do, the tethering is especially tedious. If you are considering jailbreaking your iOS device, I would recommend that you refrain from updating it to 3.4.5. for now and wait for an untethered release of jailbreaking software if possible.
 
 
 

No comments

The SQLite engine is a lightweight library optimized for managing relational databases in embedded environments. It is supported on the iOS platform. Described below is a set of basic SQLite queries that will come in handy if you need /choose to use the C-style SQLite APIs to directly manipulate your database tables. It is intended for folks who are noobs to the database world. Direct manipulation using SQLite APIs is an alternative to using the high-level Object Oriented Core Data wrapper framework.

Note: The sample code snippets are intended for reference purposes. You should include appropriate error handling and any relevant synchronization support depending on the needs of your application. If you are interested in the details of the routines, please refer to the sqlite3.h header file.

Adding SQLite Support

SQLite libraries is available as part of the iOS SDK.  Include the libsqlite3.0.dylib to your project using the usual procedure, and add
#import <sqlite3.h>  to the relevant header files.
Note: The following code snippets assume an ivar named “dbHandle” corresponding to the database Handle defined in your header file as follows-
sqlite3* dbHandle;

Opening the connection to the database

The following code snippet creates a database file named “AddressBook.sqlite” within the Documents folder of the application. If the database exists, it opens a connection to the database.

    NSString* const  dbFileName = @"AddressBook.sqlite";
    NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString* dbFile = [documentsDirectory stringByAppendingPathComponent:dbFileName];

    sqlite3_config(SQLITE_CONFIG_SERIALIZED);

    int result = sqlite3_open([dbFile UTF8String], &dbHandle);
    if (result != SQLITE_OK) {
	NSLog(@"Failure in connecting to the database with result %d",result);
    }
    else {
        NSLog(@ "Succesfully opened connection to DB") ;
    }

Creating a table

The following code snippet creates a table named “Contacts” in the “AddressBook.sqlite” database. Every row in the table corresponds to a “Contact” and has the following columns-

FirstName

VARCHAR (non-null)

LastName

VARCHAR (null)

Email

VARCHAR (null)

Telephone

VARCHAR (null)

 

    char* error;
    const char *sqlQuery = "CREATE TABLE Contacts (FirstName TEXT NOT NULL, LastName TEXT, Email TEXT, Telephone TEXT,PRIMARY KEY (FirstName))";
    int result = sqlite3_exec(dbHandle, sqlQuery, NULL, NULL, &error);
    if (result != SQLITE_OK) {
        NSLog(@ "Failure in creating the table with result %d",result) ;
    }
    else {
        NSLog(@ "Succesfully created table ") ;
    }

Common queries on a table

Query execution follows the following basic sequence –

  • Prepare” the SQL query for executing using the sqlite3_prepare_v2() call. A SQL query can be comprised of multiple SQL statements, That said, the “preparation” routines only compile the first SQL statement in the query so I typically specify only one statement within a query.
  • Optionally,“Bind” SQL query arguments with values using the sqlite3_bind_*() commands. Binding would be required only if there are arguments specified in the SQL query statement.
  • Evaluate” the compiled SQL query (that was output from the sqlite3_prepare_v2() command ) using the sqlite3_step() command.
  • Optionally, “Retrieve” the results of the SQL query evaluation using the sqlite3_column_*() commands.You can access the value of every column of the resulting row using these routines. The leftmost column begins at index 0.
  • Reset” the compiled SQL query so it can be evaluated again. You can execute the query again using the sqlite3_bind() and sqlite3_step() commands
  • Destroy” the query object once you are done with the query using the sqlite3_finalize() command

Fetch total number of entries in the table

The code snippet returns the number of rows in the Contacts table

    int count = 0;
    int retVal;
    const char *sqlQuery = "SELECT COUNT(*) FROM Contacts";
    sqlite3_stmt *query = nil;

    if ((retVal =sqlite3_prepare_v2(dbHandle, sqlQuery, -1, &query, NULL)) == SQLITE_OK) {
	int queryResult = sqlite3_step(query);
	if (queryResult == SQLITE_ROW) {
	    count = sqlite3_column_int(query, 0);
            NSLog(@"Succesfully selected row count %d  ",count) ;
        }
        else {
            NSLog(@"Failed to selected row count ") ;
        }
        sqlite3_reset(query);
        sqlite3_finalize(query);

    }
    else {
        NSLog(@"Failure in preparing SELECT statement with result %d",retVal) ;
    }

Add a row entry to the table

The code snippet adds a new Contact entry to the Contacts table

    NSString* contactFirstName = @"Foo";
    NSString* contactLastName = @"Bar";
    NSString* contactEmail = @"foo@bar.com";
    NSString* contactTel = @"555-1234";
    const char *sqlQuery = "INSERT into Contacts (FirstName, LastName, Email, Telephone) Values(?, ?, ?, ?)";
    sqlite3_stmt *query = nil;
    int retVal;
    if ((retVal = sqlite3_prepare_v2(dbHandle, sqlQuery, -1, &query, NULL)) == SQLITE_OK) {

        // The contactFirstName is a primary key. So cannot be NULL. Do the relevant checks for null values before you get here
        sqlite3_bind_text(query, 1, [contactFirstName UTF8String], -1, SQLITE_TRANSIENT);
        if (contactLastName) {
            sqlite3_bind_text(query, 2, [contactLastName UTF8String], -1, SQLITE_TRANSIENT);
        }
        else {
            sqlite3_bind_null(query, 2);
        }
        if (contactEmail != nil) {
            sqlite3_bind_text(query, 3, [contactEmail UTF8String], -1, SQLITE_TRANSIENT);
        }
        else {
            sqlite3_bind_null(query, 3);
        }
        if (contactTel != nil) {
            sqlite3_bind_text(query, 4, [contactTel UTF8String], -1, SQLITE_TRANSIENT);
        }
        else {
            sqlite3_bind_null(query, 4);
        }

        int result = sqlite3_step(query);

        if (result != SQLITE_DONE) {
            NSLog(@ "Failure in adding row to table. Result is %d",result) ;
        }
        else {
            NSLog(@ "Succesfully added row  ") ;
        }

        sqlite3_reset(query);
        sqlite3_finalize(query);
    }
    else {
        NSLog(@ "Error in preparing INSERT statement %d",retVal);
    }

Select a row entry from the table

The code snippet selects an entry in the Contacts table with FirstName = “Foo” . It also retrieves the rowId corresponding to the entry.

    NSString* searchName = @"Foo";
    NSInteger rowId;
    NSString* lastName;
    NSString* email;
    NSString* tel;
    const char *sqlQuery = "SELECT rowid, FirstName, LastName, Email, Telephone FROM Contacts WHERE FirstName == ?";
    sqlite3_stmt *query = nil;
    int retVal;
    if ((retVal = sqlite3_prepare_v2(dbHandle, sqlQuery, -1, &query, NULL)) == SQLITE_OK) {
        sqlite3_bind_text(query, 1, [searchName UTF8String], -1, SQLITE_TRANSIENT );
        int result;
        if( (result = sqlite3_step(query)) == SQLITE_ROW) {
            rowId = sqlite3_column_int(query, 0);
            lastName = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(query, 2)];
            email = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(query, 3)];
            tel = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(query, 4)];

            NSLog(@"Retrieved the row with Id %d for FirstName %@ :LastName :%@, Email:%@, Telephone:%@", rowId,searchName,lastName,email,tel);

        }
        else {
            NSLog(@ "Failure in select row from table. Result is %d",result) ;
        }

        sqlite3_reset(query);
        sqlite3_finalize(query);
    }
    else {
        NSLog(@ "Failure in preparing SELECT statement with result %d",retVal)
    }

 

Update a row entry in the table

The code snippet updates the Telephone number associated with an entry in the Contacts table with FirstName = “Foo” to “555-7777”

    NSString* searchStr = @"Foo";
    NSString* updateStr = @"555-7777";
    const char *sqlQuery = "UPDATE Contacts SET Telephone = ? WHERE FirstName == ?";
    sqlite3_stmt *query = nil;

    int retVal;
    if ((retVal = sqlite3_prepare_v2(dbHandle, sqlQuery, -1, &query, NULL)) == SQLITE_OK) {
         sqlite3_bind_text(query, 1, [updateStr UTF8String], -1, SQLITE_TRANSIENT );
         sqlite3_bind_text(query, 2, [searchStr UTF8String], -1, SQLITE_TRANSIENT );

        int result;
        if ((result =sqlite3_step(query)) != SQLITE_DONE) {
            NSLog(@"Failed to execute the query %d",result);
        }
        else {
            NSLog(@"Succesfully updated row !");
        }
        sqlite3_reset(query);
        sqlite3_finalize(query);
    }
    else {
        NSLog(@ "Error in preparing UPDATE statement %d",retVal);
    }

Delete a row entry from the table

The code snippet deletes an entry in the Contacts table with FirstName = “Foo” .

    NSString* searchStr = @"Foo";
    const char *sqlQuery = "DELETE FROM Contacts WHERE FirstName == ?";
    sqlite3_stmt *query = nil;

    int retVal;
    if ((retVal = sqlite3_prepare_v2(dbHandle, sqlQuery, -1, &query, NULL)) == SQLITE_OK) {
        sqlite3_bind_text(query, 1, [searchStr UTF8String], -1, SQLITE_TRANSIENT );

        int result;
        if ((result = sqlite3_step(query)) != SQLITE_DONE) {
            NSLog(@ "Failure in delete row from table. Result is %d",result) ;
        }
        else {
            NSLog(@ "Succesfully deleted row ") ;
        }
        sqlite3_reset(query);
        sqlite3_finalize(query);
    }
    else {
        NSLog(@ "Failure in preparing DELETE statement with result %d",retVal) ;
    }

Closing connection to the database

The following code snippet closes the connection to the database. All resources must have been “finalized” before you invoke this routine.

    int result = sqlite3_close(dbHandle);
    if (result != SQLITE_OK){
        NSLog(@"Failure in closing connection to database. Result %d",result);
    }
    else {
        NSLog(@ "Successfully closed DB connection ") ;
    }

Testing

You can use the freely available plugin “SQLite Manager” (https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/) for Mozilla Firefox to examine/verify the contents of your sqlite database.

2 comments

Let me start out by saying that the weekend at the first Cocoaconf  was thoroughly inspiring and very well worth my time. It lived up to its reputation as a technical conference – hands-on tutorials, code walkthrough of various concepts and even the keynote address by Daniel Steinberg   was a very entertaining spin on Objective-C.  It was a community where people were eager to share their knowledge and to learn from each other.  Bill Dudney spent time reviewing a pesky bug that I was facing and gave me some useful pointers – how great is that!

And now to the curious subject of this blog:-

In this congregation of approximately 80 techies, I noticed that there were only four women (including myself) attending the conference.  Of course this wouldn’t be the first time that there was a stark disparity in the number of women and men at a technical conference.  Attendees of the recent Apple WWDC 2011 mentioned to me that there were probably a dozen or so women among several thousand attendees!  Conferences aside, the number of men in development related roles have significantly outnumbered women in all the companies that I’ve worked for.  I’m generally the lone woman in a technical meeting. To be clear, I’m talking specifically about roles that involve programing and building software. I’m not talking about management related roles in technology organizations where there are many women making significant inroads. I’m not including the designers (web, graphics etc) , technical writers either. I’m talking about folks who develop. So why is there a significant shortage of women in this area? It definitely isn’t true that women can’t program, and I don’t believe that it something to do with our genetic makeup, so what is the reason.

I’ve pondered over this topic many times in the past but it was rekindled over the weekend at Cocoaconf when I noticed that nothing much has changed over the years in this regard.  I chatted about this with some of the men who attended the conference and it was interesting to get their perspective on this as well.  This is a summary of  my thoughts-

It is no secret that the number of women pursuing a Computer Science /Engineering degree is still very small (and some reports indicate that its dwindling).   So why aren’t women inclined to pursue this degree in the first place? Is it because (judging by the fact that there aren’t many women in this area), they perceive this as a “guy thing” and automatically assume that this would be something they wouldn’t enjoy? Or does this start much earlier during elementary and middle school, where summer camps related to topics like “ Building Robots” and “programing” are mostly attended by boys which dissuades even the girls who are interested in such topics (or over-protective parents of girls) from participating in  such camps?

Even the women who enter the industry as a developer tend to switch to non-development or non-technical roles/jobs within a few years. Is it because women inherently prefer to work in roles which involve more “socializing” such as management, marketing,  sales? As a developer, one does not have to interact a whole lot with others- you are pretty much in your office/cube for most part (well- there is “pair programing” but that’s not for everyone).  Some women have indicated that they switched careers because “it was hard to keep up”.  Like many other jobs these days, programing is not a traditional “9 to 5 job”. Technology changes at a rapid phase and in order to do well, one needs to constantly upgrade their skills.  There is continuous learning required. This may require spending evenings and weekends learning the new skill. Depending on the demands of the family, that is not always feasible, especially for women.  Some women have indicated that switching to management related roles was essential to climb up the corporate ladder within their company. I disagree with that.  Most companies offer separate management and technical tracks. One can be in a position of significant influence even while serving a purely technical role.  

A very interesting point that was raised by some one and with which I agree, is the men in development roles tend to possess traits which may not appeal to many women.  They are generally “arrogant” ,”brash” or “over confident” . Hold on- let me explain this a bit.  As developers, we can’t just “give up” on bugs. We are adamant about fighting them and proving that our code works.  Developers are not necessarily the most social people and many tend to lack “people skills”- we are not shy about "calling a spade a spade". Very often, developers tend to trivialize a complex task.  For instance, even if fixing a problem took a lot of time /effort, men tend to downplay the effort and claim that “Oh that was so easy. Figured it out in no time ”.  This may be intimidating to women who may have lower self-confidence in their programing abilities to begin with.

 Being in a development job may need women to be willing to primarily interact with men.  For many women, this would mean stepping out of ones comfort zone . While this is not a requirement to do well as a developer, it certainly helps to be able to network with fellow developers at the workplace and at conferences- one learns a lot in the process.  On the flip side, many male developers do not openly welcome women into their discussions for fear of being misunderstood. Of course if there were sufficient women in these roles to begin with, there wouldn’t be this issue!

Women tend to discuss family matters more often than for instance, the latest gadget or the cool stuff that they discovered while hacking into their new gadget.  Sure- men probably discuss sports a lot as well but they also talk a lot more about technology, even if they are not directly working in that space. There is nothing wrong in discussing family, but my point here being that we are influenced a lot by our company.

 I’ve not covered all the factors in this blog and that was not my intent. I’m sure that there are many more reasons and it is probably a complex combination of all of the above factors.

One of the pioneering programmers was Lady Ada Lovelace. It is sad not to see more women following her legacy.

 

 

 

 

18 comments

The list of mobile-specific security exploits that were discussed at this week’s BlackHat Technical Security conference got me a paranoid again. I did a bit of security related work a while ago.  I didn’t attend the conference, so no- this isn’t a blog about the conference- sorry!

Security has always been an afterthought. Back in the day when I did some Internet related standards work, the section on “Security Considerations” was typically the most sparse chapter in the specification.

With the proliferation of connected devices ranging from smart phones, tablets, TVs, STBs, game consoles to cars, toasters, washing machines, refrigerators, we are susceptible to security threats more than ever.  But are we taking it seriously enough?

There is no denying that mobile computing is the present and the future, so I’d like to specifically discuss mobile devices and in particular, smart phones and tablets in this context. 

The Network:

Wireless networks are ubiquitous –homes, the coffee shops, airports, airplanes, trains, maybe your entire city.  Of course, this was true even in the “pre-smartphone, laptop era”. But now, there is a huge difference in terms of the number of actively connected devices. Anything you want to do, “there’s is an app for that”. A lot more people are performing a whole lot more of sensitive transactions (banking, ticketing, shopping) from their mobile devices.  

It’s not an unknown fact that wireless networks are not very secure. Sure, with 802.11n we have come a long way from the vulnerable WEP and WPA security of 802.11a /b/g days, but there is no guarantee that all the wireless networks we traverse are upgraded to the latest and greatest and besides, many folks who setup their home wireless networks may not take the necessary precautions to secure their network.  In places where there is no sufficient monitoring of the wireless networks, it wouldn’t be hard for someone to set up a rogue Access Point that unsuspecting users would connect to or for an attacker to launch a Denial of Service attack by exploiting RF interference.

The Device:

If you are thinking that the issues I mentioned thus far are old-school, then you may be interested in the more sophisticated form of “baseband attacks” . In this case, an attacker could potentially gain control of the device memory through malicious code installed on the device’s radio signal transmitter/receiver by posing as a legitimate cell tower!

I’d like to draw some comparisons between the iOS and Android platforms.

Both the Android and the iOS platforms have a sandbox model for running applications, which limits the extent of damage by a malware-app. 

Apple to its credit has a rigorous code signing process that ensures that certificates issued by Apple are used to sign apps.  Android on the other hand allows for self-signed certificates and so there is no guarantee of the identity of the signer of the app.

The approval process by Apple, while in no means intended to scrutinize app code for security breaches, at least provides some level of assurance about the quality of the application.  There is no Android Marketplace approval process.

Apple disallows installation of any app that is not downloaded through its App Store (and consequently signed by Apple) and in order to allow that, one would have to jailbreak the device. On the Android, it’s very easy to install apps that are not available on the Android marketplace- just check the “Unknown Sources” box under settings to allow installation of any app and you are done.

Of course, there are security holes in both the iOS and Android kernels that can be exploited quite easily on jailbroken phones with root-level access. Attackers can then use many freely available tools to disable kernel-level security patches on jailbroken phones in order to launch their attacks.

Another point to note is that mobile devices are often connected to laptops ( and desktops?) for purposes of backup/restore/sync services. This makes the mobile devices as vulnerable as the platform that they are hooked up to.

The Services:

 The mobile device is increasingly becoming the platform of choice for activities such as browsing, emails, social networking etc.  This implies that mobile devices are now the target of the kinds of attacks s like phishing , pharming and Internet fraud  which traditionally plagued laptops/desktops. The problem is exacerbated with the growing popularity of social networks.

Furthermore,  the growing relevance of cloud based services for mobile devices poses significant security risks.  What prevents an attacker from harnessing the “infinite” resources on the cloud for launching DDoS attacks? 

Final Thoughts

There is significant variation in the demographic of mobile device users ranging from the tech-savvy geek to the grandmother who has never used a computer to the teenager who is always online. Educating such a diverse population of the security risks involved is a daunting task. This implies that security has to be integrated into the platform -the device, the infrastructure/networks and the services. The end-user is an integral part of the solution but the hardest to manage.   In addition to the consumer space, many businesses allow access to corporate services from (personal) mobile devices, making the corporate resources susceptible to security attacks by compromised devices. Security is an expensive investment for both individuals and enterprises. It’s similar to insurance- You never realize how absolutely important it is until your systems are compromised.  Now that I’ve shared my thoughts, I think I will relax a little!