Thursday, December 12, 2013

Phonegap introduction

In this tutorial we will discuss what is phonegap and what makes it so cool

Phonegap is a mobile development framework it was originally built by Nitobi and later was purchased by Adobe systems. Phonegap helps you to create mobile apps by making use of HTML5, javascript and CSS instead of the device specific language (Objective C, C#, Java).

The apps which are made in phonegap are called as hybrid apps, hybrid apps because the UI rendering is done as part of web and to call the native controllers like the image, camera or sqlite database etc you have access to these device specific API’s (we will talk about it later). If you are planning to use phonegap in your next project then I would suggest you to make sure that your HTML, CSS and javascript skills are clean.

By using phonegap you are at the same time developing apps for multiple platforms, you can take advantage of the concept called as plugins to do device specific work in case if you do not find a device API for the same.

Example: If you just want to show a native alert in a phonegap based app, then you can write your own plugin.

The app, which uses phonegap framework, makes use of the native webview, all the styling and UI rendering is maintained with the help of CSS and javascript. Also note that phonegap is an open source framework.

The various operating system supported by phonegap are as follows:

Apple iOS
LG webOS
Symbian OS
Bada OS
Ubuntu touch

While beginning the learning phase a question raised in my mind like whenever I search phonegap this cordova thing used to come up and it was like so confusing at the first place but finally got the answer to it.

Above I mentioned that now phonegap is owned by adobe, what adobe did later was they donated the phonegap codebase to Apache software foundation (ASF), later phonegap was renamed to Apache callback which the apache community found was not so cool so they renamed it to Cordova, Cordova hmmmm is their  a meaning in this name while yes phonegap was a project that was born in Nitobi company which was located in Cordova Street in Vancouver,well now the name makes sense.

The next question that I had in my mind was like what is the difference between phonegap and Apache Cordova?

After visiting few links I found that you could think of the apache cordova as the engine that powers a car named phonegap. To be more specific Apache cordova has a set of device level API’s with the help of which you can access the device level controllers like the accelerometer, camera, etc with the help of apache cordova you can build native mobile apps using HTML, CSS and Javascript.

Coming to phonegap now, phonegap is a distribution of apache cordova you may think of apache cordova as the heart and phonegap as arteries that supply blood to all the parts of your body. So basically that makes phonegap as the supplier of cordova and its device based API’s.

If the above example did not impress you then here’s a common example that you might have came across, you can think of cordova like the webkit which powers safari or chrome.

If you want to know more then here’s a FAQ guide from phonegap itself.

If you are planning to install cordova then please visit this link that contains simple step by step written for installation. Also you need to download the cordova source from here because to create cordova based app you need to use the command lineterminal.

I hope that i was able to clear few things regarding phonegap in the next post we will see more about it, if you have any question then feel free to mail me or leave it as a comment until then Happy iCoding and have a great day.

Friday, October 4, 2013

View provisioning profile in Xcode 5

Obtaining Signing Identities and Downloading Provisioning Profiles

Request code signing certificates and download provisioning profiles from Member Center.

In the Xcode Preferences window, click Accounts.

Select your team, and click View Details.

The view details dialog appears.

Click the Refresh button in the lower-left corner of the view details dialog under the Provisioning Profiles table.

If you are missing a development or distribution certificate, a dialog appears asking whether Xcode should request it on your behalf. A dialog may appear for each type of certificate you are missing.

Click Request for the signing identities you want.

Your new signing identities appear in the Signing Identities table. Xcode also downloads any missing provisioning profiles and adds them to the Provisioning Profiles table.

If your keychain does not contain your development certificate but your team has the certificate, Xcode downloads it for you but without the private key. In this case, you should export your code signing assets from the Mac where you created the signing identity and import them on this Mac.

If your role is a team member, inform the team agent or admin that there’s a pending certificate request.
If necessary, after the request is approved, follow these steps again to download your development certificate.

If you are the team agent or admin, Xcode may request your team’s distribution certificate, in addition to a development certificate.

Sources : Apples documentation on Xcode.

Happy iCoding and have a great day.

Monday, September 16, 2013

Remove white spaces between NSString

I was coding this app and was stuck with 
removing the spaces from NSString
when i ran into this class called as NSRegularExpression and guess what i helped me a lot, given below is the code which i used to remove white spaces between NSString object hope it helps

Remove white spaces between NSString code :

NSString *whitespaceString = @"This      is     a        string with         white                       spaces ";

NSError *error = nil;

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@" +" options:NSRegularExpressionCaseInsensitive error:&error];

NSString *trimmedString = [regex stringByReplacingMatchesInString:whitespaceString options:0 range:NSMakeRange(0, [whitespaceString length]) withTemplate:@" "];


Final String = This is a string with white spaces

Join us on facebook

Happy iCoding and have a great day....

Monday, August 26, 2013

Ping a particular host using objective c

Ping a host and check for reachability

So heres the code (Make sure you add the SystemConfiguration Framework in your project before you begin with this)

- (BOOL)pinghosttoCheckNetworkStatus
    bool success = false;
    const char *host_name = [@""
    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL,host_name);
    SCNetworkReachabilityFlags flags;
    success = SCNetworkReachabilityGetFlags(reachability, &flags);
    bool isAvailable = success && (flags & kSCNetworkFlagsReachable) &&
    !(flags & kSCNetworkFlagsConnectionRequired);
    if (isAvailable)
        return YES;
        return NO;

Happy iCoding and have a great day.

Join Us on Facebook

Monday, July 8, 2013

Convert NSData into Base 64 string for SOAP services

Currently i was working on a SOAP request and wanted to send a file on the server, i looked at the SOAP request and saw that one of the parameter in the SOAP service accepted base64 as parameter, so i wanted to convert the NSData into base64 so after a long time spending debugging and breaking heads i finally surfed up and came saw a solution on stackoverflow  which i would like to share with you 

+ (NSString*)base64forData:(NSData*)theData {
    const uint8_t* input = (const uint8_t*)[theData bytes];
    NSInteger length = [theData length];
    static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
    uint8_t* output = (uint8_t*)data.mutableBytes;
    NSInteger i;
    for (i=0; i < length; i += 3) {
        NSInteger value = 0;
        NSInteger j;
        for (j = i; j < (i + 3); j++) {
            value <<= 8;
            if (j < length) {
                value |= (0xFF & input[j]);
        NSInteger theIndex = (i / 3) * 4;
        output[theIndex + 0] =                    table[(value >> 18) & 0x3F];
        output[theIndex + 1] =                    table[(value >> 12) & 0x3F];
        output[theIndex + 2] = (i + 1) < length ? table[(value >> 6)  & 0x3F] : '=';
        output[theIndex + 3] = (i + 2) < length ? table[(value >> 0)  & 0x3F] : '=';
    return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];


The above function will convert the NSData into base64 string which you can send in your SOAP service as a parameter. And if you are finding it difficult to work with SOAP services then here's a link to my old tutorial on SOAP service.

Happy iCoding and have a great day.

Join Us on Facebook

Thursday, July 4, 2013

How to jailbreak iOS device

The author of this post is my friend Faisal Mohd, he is one "TECH GEEK" when it comes to Mobile Technologies and he came up with this article on how do you jailbreak the ios device so i would like to thank him for sharing his knowledge with us. 

And yes if you have any questions or queries feel free to post it as a comment or via mail or on our Facebook group.

How to jailbreak an iOS device

The untethered jailbreak, a gateway to a whole new world of apps and tweaks and themes and what not is out there, how to do it?

Follow these simple steps to jailbreak iOS 6 and enjoy all the goodness of Cydia.
1) An iOS device running iOS 6.x
2) A desktop or a laptop running either Windows(XP minimum), Mac OS X(10.5 minimum) or Linux.
3) A USB cable to connect your iDevice to your desktop/laptop. And needless to say, iTunes.
The Procedure
1) If your device is not updated and you were waiting for the jailbreak, now is the time when you update your iOS. Connect your iDevice to iTunes and update it. Once it is updated, eject your iDevice and close iTunes. Work of iTunes is finished now.
2) Once updated, download the jailbreaking software developed by the evad3rs from here .
3) Connect your iPhone to your desktop/laptop again and see to it that iTunes is not open as it can cause unwanted errors.
4) Open the jailbreaking application. You will see a button which says “Jailbreak”. Press that button and let the process begin to jailbreak iOS 6.
5) After some time, you will be asked to unlock your device and once you do that, you will see an icon which for your information will be the icon of the developers, the evad3rs. Tap that icon once and leave it. The process will resume again.
6) Once the process is complete, the place where you saw the “Jailbreak” button, at the very same place you will now see “Exit”. Press that and you are almost done with jailbreaking iOS 6.x.
7) The last and the final step is, you will see the Cydia icon in your iPhone, Open it and let Cydia run its setup. Once that is complete, you are done.
8) Congrats. You now have an untethered jailbreak iOS 6 running on your iDevice. Enjoy.
Do let us know your comments or queries about how to jailbreak iOS 6. Be it a problem during the process or any general query.
1) It is highly recommended for you to take a backup of your device before continuing with the following procedure.
2) If you have a lock pass code, please disable it. This is an advice from the developers before you jailbreak iOS 6.
3) If by some bad luck, though I sincerely hope there is none, but if in the middle of the process something goes wrong or the process is stuck, don’t panic. Just restart the program or if necessary, reboot your device and do it one more time.

Happy iCoding and have a great day while you jailbreak.

Join Us on Facebook

Monday, June 10, 2013

New features of iOS 7

The new features introduced in the iOS 7 are as follows :

1. Control Center : Control Center gives you quick access to the controls and apps you always seem to need right this second. Just swipe up from any screen including the Lock screen  to do things like switch to Airplane mode, turn Wi-Fi on or off, or adjust the brightness of your display. You can even shine a light on things with a new flashlight. Never has one swipe given you so much control.

2. Notification Center : Notification Center lets you know about new mail, missed calls, to-dos that need doing, and more. And a new feature called Today gives you a convenient summary of, well, today. One glance at your iPhone and you’ll know if it’s a certain someone’s birthday, if you’ll need an umbrella, or if traffic will slow down your commute. You’ll even get a heads-up on tomorrow. You can access Notification Center from any screen, including the Lock screen. Just swipe down. And get up to speed.

3. Multitasking :  Multitasking has always been a smart way to switch between apps. Now it’s even smarter. Because iOS 7 learns when you like to use your apps and can update your content before you launch them. So if you tend to check your favorite social app at 9:00 a.m. every day, your feed will be ready and waiting for you. That’s multitasking in iOS 7. It knows what you want to do before you do.

 4. Camera : Camera in iOS 7 puts all your shooting formats — still, video, panorama, and now square — front and center. With a swipe, you can capture what you want the way you want. Fast. And new filters let you do even more with each image. Give it a retro feel. Dial up the contrast.
Or go black and white. Artistic license is all yours.


5. Photos : Now there are faster, easier, and more delightful ways to scroll down memory lane. Introducing Collections, Moments, and Years smart groupings of your photos and videos based on time and place. Tap Years and all your shots fill the screen. Each year holds Collections, like your trip to San Francisco. And in that Collection are distinct Moments  photos from Union Square, videos from AT&T Park. So you can find a shot from whenever, wherever, in no time.

6. Airdrop : Sending a photo or a document to someone via text or email is fine. But if that someone is right next to you, a text or an email suddenly feels like too many steps. Enter AirDrop for iOS. It lets you quickly and easily share photos, videos, contacts  and anything else from any app with a Share button. Just tap Share, then select the person you want to share with. AirDrop does the rest using Wi-Fi and Bluetooth. No setup required. And transfers are encrypted, so what you share is highly secure.


7. iTunes Radio : iTunes Radio features streaming radio stations you’ll love from day one — from the best selection of music. The more you listen, the more personalized it becomes. And it’s available on your iPhone, iPad, iPod touch, Mac, PC, and Apple TV for free. It’s radio re-imagined.


8. Siri : Siri in iOS 7 gets a new look, a new sound, and new capabilities. It features a redesigned interface that fades into view on top of whatever’s on your screen. A more natural speech pattern in a new female or male voice is even easier to understand. Siri is faster at answering questions and checks more sources, such as Bing, Wikipedia, and Twitter. And it takes on extra tasks, like returning calls, playing voicemail, controlling iTunes Radio, and more.


9. App Store : Apps Near Me — a new feature of the App Store in iOS 7 — shows you a collection of popular apps relevant to your current location. And a new Kids category spotlights the best apps for children based on age. iOS 7 also keeps your apps up to date automatically, so you don’t have to bother. Another bonus of automatic updates: no more little red badge begging for your attention.


10. Find my iPhone : Losing your iPhone feels lousy. Thankfully, Find My iPhone can help you get it back. But if it looks like that’s not going to happen, new security features in iOS 7 make it harder for anyone who’s not you to use or sell your device. Now turning off Find My iPhone or erasing your device requires your Apple ID and password. Find My iPhone can also continue to display a custom message, even after your device is erased. And your Apple ID and password are required before anyone can reactivate it. Which means your iPhone is still your iPhone. No matter where it is.


11. iWork for iCloudiWork has always been the best way to be productive on the Mac. And iWork for iOS made it easy to create beautiful documents on iPad and iPhone. With iWork for iCloud we’re bringing Pages, Numbers, and Keynote to the web on Mac and PC. And thanks to iCloud, your work is always up to date on all your devices.

12. Developer API : Apple stated at Monday’s keynote that developers would gain access to over 1500 new developer APIs in iOS 7. Given that most of Macworld’s readers aren’t highly interested in this nitty-gritty, however, here are a few interesting ones.

iBeacons: Apple’s iBeacons, in technical speak, use the Bluetooth Low Energy profile for microlocation. In plain speak, this means your iOS device may be able to use Bluetooth 4.0 devices to collect precise location data—like your location inside of a building—even though those devices don’t have a GPS system installed. That said, I don’t claim to be a Bluetooth or microlocation scholar, and Apple’s APIs are under the confidentiality agreement, so the actual implementation might be slightly different.

Background downloading: We heard mention of this during the keynote: In short, it allows your apps to download information for you at certain times of day, even if they’re not actively running. In practice, this might allow your Twitter feed to download and cache tweets for you to read before you hop on the subway or sit in an airplane, sans Internet access.

Third-party game controllers: There are a few pseudo third-party controllers for iOS games already (the iCade, for one), but it looks like Apple plans to offer more expansive support for those wishing to connect third-party controllers to their iOS devices.

I hope that i have covered few interesting features of the new iOS7 incase if i have missed any feature feel free to mention it as a comment or you may post the link

Happy iCoding and have a great day.

Join Us on Facebook

Tuesday, April 16, 2013

Understanding the concept of JSON

When you were a child you used to request chocolates from your dad and he used to buy it for you, really childhood memories are awesome.

In todays session we are going to look closely at JSON, which happens to be the preferred option that web developers are using as an output response.

Well consider your childhood memories for a second, your iPhone is the child who will request chocolates (i.e. data for a particular request) from the server who’s the dad here and the server (dad) will do the required processing for the requested chocolate (data) and will give the chocolate to the child (iPhone), this is what happens in all the iOS application that have server request involved.

The processing on the iPhone should be fast, your user should not wait long to see his requested data, so it all depends upon how quickly you can parse (read) the response given by the server and display it in the iPhone UI (user interface).

Keeping in mind that we are working with an environment where speed is the key, JSON provides a better solution in parsing the response returned by the server.

JSON (JavaScript Object Notation) it’s a response format, which is composed of key value pairs, you supply a key and get the value from it just like you do with NSDictionary class.

A JSON response may contain a single dictionary with array or a single array with multiple dictionaries or a single dictionary with some keys or all of them, the structure of the response depends upon what you have requested from the server, so you can say that JSON is a container of your requested data from the server but in key value format.

You request your query to the server with the help of NSURLConnection class which later provides you with NSData object from the server in it’s delegate method named “connection did finish”, this NSData object is your actual response which you have received for the request you made, but you cannot read this response since it’s in bytes.

In order to work with JSON we have a class called as NSJSONSerialization which helps us to convert the NSData object into actual readable JSON key-value pair type, earlier we used a third party library called as the SBJSON.

You might have a question here like how can we identify if the JSON format is a array or dictionary, well the answer is very simple if the JSON format contains a “{} “ curly bracket then its clear that it’s a dictionary and if the JSON response has a square bracket “[]” then it’s an array.

Few years ago i worked on a project which had a really nice and a complicated JSON structure which i would like to share with you, hope this will help you in the learning curve.

Image 1 : JSON is a container of your data which you get from the server.

Look at the above image the response format is in curly bracket and hence we can say that it's a dictionary type, and if the response was an array then it contained square bracket [].

Image 2: After expanding the JSON tag i can see that my response contains two set of arrays and one key named status.

Image 3: After expanding the result tag which is an array you can see that it contains a list of twenty dictionaries within itself at various index.

 Let's expand a dictionary from the result tag and see what it contains

Image 4 : The dictionary present at the 0th index of the result tag array again contains multiple objects of various types

By looking at the above structure we can conclude that a JSON is a container of our data which we request from the server and each item present in the container can have multiple items of their own in key-value pair.

I use a link to identify and study the JSON response form the server so that I can code accordingly hope this link will help you to Online JSON Reader.

I hope that after reading this post your concepts of JSON will be more clear and you can now identify the JSON structure and code as per your server response.

You may enter your queries or suggestions via mail or comments and i will revert back to you, until then Happy iCoding and have a great day.

Join Us on Facebook

Wednesday, March 20, 2013

Sqlite Database part 4 : The Final Code

Before starting with this post i request you to read previous post related to sqlite

How to create Sqlite Database.

How to copy database from bundle to document directory

How to insert record in sqlite database

If you have already done that then here's the code for the database demo that we have learned and i hope this helps you out in understanding the sqlite database.

Until then happy iCoding and have a great day.

Join Us on Facebook

Friday, March 1, 2013

Sqlite Database part 3 : Inserting Records in Database

Before beginning this post I hope that you have read my earlier two posts on sqlite, if not then please have a look at them first and then you may come here and if you have already done that then lets begin.

In this post we will learn on how to insert data into sqlite database, assuming that you have read my earlier posts I shall begin with the insertion part.

Step 1: We have created a function named insertEmployeeRecord in the DatabaseHelper.h file and now its time to give body to that function. Give below is the code for the same, the function returns Boolean value indicating whether the data is successfully inserted in the database or not.

// inserts the new employee record
- (BOOL)insertEmployeeRecordWithEmployeeName:(NSString*)empname andEmployeeDepartment:(NSString*)empdept andEmployeeImage:(UIImage*)empImage
    if (empname.length!=0 && empdept.length!=0)
        // checking for any previously open connection which was not closed
        [self closeanyOpenConnection];
        // preparing my sqlite query
       const char *sqliteQuery = "insert into EmployeeRecord(EmpName,EmpDept,EmpImage) values(?,?,?)";
        sqlite3_stmt *sqlstatement = nil;
        if (sqlite3_prepare_v2(databaseReference, sqliteQuery, -1, &sqlstatement, NULL)==SQLITE_OK )
            sqlite3_bind_text(sqlstatement, 1, [empname UTF8String], -1SQLITE_TRANSIENT);
            sqlite3_bind_text(sqlstatement, 2, [empdept UTF8String], -1SQLITE_TRANSIENT);
            // You need to convert the image data into NSData first
            NSData *imgData = [NSData dataWithData:UIImagePNGRepresentation(empImage)];
            // insert the binary representation of the byte data into the database
            sqlite3_bind_blob(sqlstatement, 3, [imgData bytes], [imgData length], SQLITE_TRANSIENT);
            // executes the sql statement with the data you need to insert in the db
            // clearing the sql statement
            //closing the database after the query execution
            return YES;
            return NO;
    return NO;

Code Explanation: Before beginning with any DB operation I always make sure that all my previous db connections are closed which is done with the help of closeanyOpenConnection function.

Next I prepare my sqlite insert query with the help of a const character pointer, the main function for insertion or any particular operation is the sqlite api named sqlite3_prepare_v2 this function returns an integer value  which indicates whether your sql operation will be carried forward or whether it will be stopped, 

You sql operation can stop due to reasons like if you have written some wrong sql query or your database might not have been copied in the document directory, this function returns zero for successful operation i.e. SQLITE_OK and it returns 1 for failure which  is indicated by SQLITE_ERROR

The function sqlite3_prepare_v2 takes few parameters that are given as below

Now its time to insert your data based upon the data type of your columns, my first two columns are of text type so I will be using sqlite3_bind_text function, which takes five parameters:

sqlite3_bind_text(sqlstatement, 1, [empname UTF8String], -1,  SQLITE_TRANSIENT);

1.sqlstatement : This is the pointer of sqlite3_stmt which will carry the statement which we want to execute.

2.Column Number: This is the column number into which you want to insert the data and is the second parameter

3.Actual Value in UTF8 or C style: This is the actual value that you want to insert in the database, if its NSString then you have to convert it into a UTF8 string.

4.Negative Integer one: This value indicates the number of bytes in the value and if its negative then the length of the string is the number of bytes upto the first zero terminator.

5.SQLITE_TRANSIENT: Means that this content will change in the coming future and SQlite should make its own private copy of the content,moreover it’s like a destructor which would delete the value once the insertion process has been done (this is what I understood till now)

If there is integer data, which you want to insert, then you may use the method sqlite3_bind_int

Adding binary data to the column is a piece of cake sqlite has an inbilt method for doing this and its called as the sqlite3_bind_blob, this statement is similar to your sqlite3_bind_text expect that it takes the byte representation of your image with the image length.

// You need to convert the image data into NSData first
            NSData *imgData = [NSData dataWithData:UIImagePNGRepresentation(empImage)];

// insert the binary representation of the byte data into the database
            sqlite3_bind_blob(sqlstatement, 3, [imgData bytes], [imgData length], SQLITE_TRANSIENT);

Once you have set all the values for your database columns then its time to execute your sqlite statement and this is done with the help of a method named sqlite3_step which accepts the pointer of sqlite3_stmt. 

Once your sql statement is executed then you need to finalize it with the help of sqlite3_finalize this step is important because it is used to clear the sqlstatement which you have just created to insert record in the database also the finalize statement is important in case where you want to insert multiple records in a table

After that close the database connection with the help of sqlite3_close

//closing the database after the query execution

With this function you can now insert data into the sqlite database without breaking a sweat, you may modify the function to do stuff as per your business logic and if you are facing any issues then feel free to contact me I will help you out.

I hope that i have cleared points on how to insert data in the sqlite database and if you are having any sort of queries then feel free to ask them via comments or emails

I will attach the copy of the code in the last tutorial of sqlite where you may download the copy and check the app for yourself.

Until then Happy iCoding and have a great day.