Posts

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                                     ...

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...

Lightweight Database Migration in CoreData

Image
Lightweight Migration : This is an automatic feature of Core Data, but is limited to only simple migrations. You can use this technique if the changes are among the following: 1. Adding a new attribute to an entity. 2. Renaming of an entity or an attribute. 3. Changing an attribute to optional or non-optional, whether it requires a value on creation. Schema Changes, Versioning and Migrations When you are developing an application you will almost never get the schema right the first time. So, Core Data has support for schema versioning and data migration. This allows you to define a new version of the Core Data schema by adding a new attribute or entity to the store. Then define how the store has to migrate from one change to another. Creating a new xcdatamodel (Xcode 4.3.2) If you want to do a lightweight migration first step is to create a new xcdatamodel for new schema. 1. Click on your xcdatamodeld file present in bundle. 2. Click on Editor Men...