Posts

Showing posts from 2012

DropBox integration to iPhone Application

In one of my iPhone application i wanted to integrate DropBox to share things. I just visited the DropBox developer site : https://www.dropbox.com/developers/reference/sdk and downloaded the sdk for iOS and the tutorial for integration. DropBox has really made it very easy to integrate and have provided an awesome documentation. I followed the steps, made some modifications and i was done. You can download the sample code: Download

Parse CSV file in Objective C

Sometimes we have a bulk of data in a .csv file which we need to add or access in our iOS Application. For this we can add that .csv file in application's bundle, fetch data from it and store it in an NSArray for use. Follow the steps: 1. Once list of Country Names so i downloaded the full-country-list.csv from internet and added it in my application's bundle by simply dragging it. 2. Now i just located that file path and stored in 'strPath' variable, then stored its contents and encoding type in 'strFile' variable. 3. Checked if file is present and i am able to read it. 4. Now i allocated & initialized an NSArray object 'arrayCountry'. 5. To parse file use 'strFile componentsSeparatedByString:@"\n"' and store it in arrayCountry. This .csv file is seperated with new line character, if .csv is seperated by comma use ',' instead of '\n'. 6. And we are done with parsing .csv file and we have all country nam

Integrating Facebook and Twitter using Social Framework iOS 6

Image
Lets checkout how to integrate and start sharing using Facebook and Twitter using Social Framework provided in iOS 6 Source code:  Download

Launch iOS Application From Safari Using CustomURLScheme

If you want to take user back from Safari to your iOS Application, you can achieve it using custom url scheme. Follow the steps: 1. Open -info.plist file and add <key> CFBundleURLTypes </key> <array> <dict> <key> CFBundleURLSchemes </key> <array> <string> myapplicationurl </string> </array> </dict> </array> 2. Above code will register a custom url for your application. 3. You can also pass parameters (query string) to it: myapplicationurl:// myapplicationurl://?key1=value1&amp;key2=value2 4. When this url is called from Safari iPhone SDK sends message to UIApplicationDelegate - ( BOOL )application:( UIApplication *)application handleOpenURL:( NSURL *)url {  // You are back to your application.  NSLog ( @"Yeah!!! We are back to Application from Safari" );  return YES ; } 5. Above method in UIApplicationDelegate will be

Integrating Pinterest in iOS Application

Image
Pinterest do not provide api's for integration yet. So in order to achieve it we need to use UIWebView in iOS App. Follow below steps: 1. Take a UIViewController containing two buttons, one UIWebView. 2. Generate HTML programatically and pass it to loadHTMLString in UIWebView. 3. On touchup-inside of first button, load html string which will open Pinterest in UIWebView. 4. Here pass your custom description and image url which you want to pin. 5. On touchup-inside of second button, close/hide the UIWebView. Download Code from here:  PinterestiOSIntegration http://stackoverflow.com/questions/9909511/ios-application-integration-with-pinterest answer provided by ' wzbozon' Above link helped me out.

Open htaccess Password Protected Web-Page in UIWebView

In some cases we want to access a password protected (htaccess) webpage from UIWebView iPhone. So for this we need add username and password between 'http://' and 'page url'.  e.g. @"http://username:password@192.165.1.11/mypage" NSString *url = @"http://username:password@192.165.1.11/mypage"; [webViewForhtaccessPageRendering loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: url]]]; here  webViewForhtaccessPageRendering is UIWebVIew.

UITableView - Add or Remove Rows Dynamically (Objective C & Swift Source codes)

Image
In some situations we need to add or remove rows dynamically from a UITableView. We can achieve it very easily, just got through the tutorial : 1. Create a new project. 2.  In AppDelegate implementation file create an object of UINavigationController (navController here). 3. Add object of UIViewController (viewController here) as rootviewcontroller of UINavigationController. 4. In ViewController.xib nib file take a UITableView. 5. Set delegate and datasource of UITableView to File's Owner. 6. Create an IBOutlet to UITableView (tableViewForScreen here) in ViewControler.h header file. 7. Declare an object of NSMutableArray (arrayForTableContent here) in ViewControler.h header file. 8. In ViewController.m file in viewDidLoad method set edit and add buttons as leftBarButtonItem and rightBarButtonItem respectively. 9. Initialize arrayForTableContent array and add objects to it.

Implementing iAd in iPhone/iPad/iPod Touch Application

Image
Implementing iAds in your iPhone/iPad Application is really very simple. 1. First add "iAd.framework" Framework from Targets -> Build Phases -> Link Binary With Libraries. 2. In ViewController.h #import  <iAd/ADBannerView.h> 3. Take ADBannerViewDelegate. 4. Now take a ADBannerView in ViewController.xib. 5. Set IBOutlet to ADBannerView (as iADBannerView here). 6. Set delegate of ADBannerView to File Owner(self). 7. In ViewController.m set iADBannerView as Hidden in viewDidLoad method. Which will hide the ADBannerView while loading controller screen. 8. Now add delegate methods of ADBannerView mentioned below: - ( void )bannerViewDidLoadAd:( ADBannerView *)banner; - ( void )bannerView:( ADBannerView *)banner didFailToReceiveAdWithError:( NSError *)error; 9. In bannerViewDidLoadAd method unhide the ADBannerView. As method name specifies this method is executed when ADBannerView loads. 10. If there is any is

Validate and Parse NSURL in Objective C

I need to check if Url is valid or not in my iPhone application so i found below snippet from   http://stackoverflow.com We can validate a url by simply using Foundation Framework as follows:           NSURL  *myURL = [ NSURL URLWithString : @"http://google.com" ];          if ( myURL  &&  myURL . scheme &&  myURL . host ) {              NSLog ( @"URL is validated" );         } else {             UIAlertView *alertMsg = [[ UIAlertView alloc ] initWithTitle : @"Error"                                        message : @"URL is invalid" delegate : nil                                        cancelButtonTitle : @"OK" otherButtonTitles : nil , nil ];             [alertMsg show ];             [alertMsg release ];         } Output:  URL is validated Above can be achieved using RegexKit also as follows:     NSString *regexExpression = @"(http|https)://((\\w)*|([0-

Database implementation using SQLite in iOS Applications

Image
SQLite:  I have worked on Core Data and SQLite both, but i personally feel that using SQLite is a good choice. Working on Database directly using SQLite is better than working on Core Data which actually works as a wrapper above SQLite. We can easily fire complex sql queries on Database using SQLite to store, update or fetch data; which is a pathetic job using Core Data.  Below is a simple demo app which will help you understand how to use SQLite to create database, store, update, fetch and delete records from database. For using SQLite database in iPhone, iPad App first you need to link libsqlite3.0.dylib to your build target.  To do this select 'Project' at top left navigation panel -> 'under Targets' select your build target -> then click on 'Build Phases' tab -> then in 'Link Binary With Libraries' click on '+' button and add libsqlite3.0.dylib.   There are number of C functions contained within the libsqlite3.

NSUserDefaults

For storing data in iOS Device we have some options like NSUserDefaults, Plist file, Sqlite, Core Data. Depending on our reqirement we switch on one of the option amongst these. NSUserDefaults   - We store users preferences and settings here. Plist File                - We store data in Plist if we dont have large data to persist. We store data in key-value pair.  Core Data             - We store anything which we want to persist, we can execute predicated, fetch requests to retrieve data. SQLite                   - We store anything which we want to persist, we can execute more complex queries directly to Database to fetch data/ Actually NSUserDefaults is a Plist file. NSUserDefaults will store the users preferences into a Plist file into the Library/Preferences folder. So we can store whatever we can store in a Plist file. There is no restriction on size of a Plist File. But one thing you might not forget is that when you store or read data in a Plist file whole contents