Tuesday 25 April 2017

NSURLSession & Main difference between NSURLSession and NSURLConnection


NSURLSession
NOTE : (NSURLConneciton is Deprecated in OS X 10.11 and iOS 9.0)
  • NSURLSession is designed around the assumption that you’ll have a lot of requests that need similar configuration (standard sets of headers, etc.), and makes life much easier.
  • NSURLSession also provides support for background downloads,which make it possible to continue downloading resources while your app is not running or when it is in the background on iOS.
  • NSURLSession also provides grouping of related requests,Making is easy to cancel all of the requests associated with a particular work unit, such as canceling all of the requests associated with a particular work unit,such as canceling all loads associated with loading a web page when the user closes the window or tab
  • NSURLSession also provides nicer interfaces for requesting data using blocks,n that it allows you to combine them with delegate methods for doing custom authentication handling, redirect handling, etc.,
NSURLSessionConfiguration 

defaultSessionConfiguration 

Creates a default configuration object that uses the disk-persisted global cache, credential and cookie storage objects.

ephemeralSessionConfiguration 

Similar to the default configuration, except that all session-related data is stored in memory. Think of this as a “private” session.

 backgroundSessionConfiguration 


Lets the session perform upload or download tasks in the background. Transfers continue even when the app itself is suspended or terminated.

Types of NSURLSessionTasks

Data tasks (NSURLSessionDataTask)  

Data tasks are used for requesting data from a server, such as JSON data. These data are usually stored in memory and never touches the File System We can use NSURLSessionDataTask.

Upload Tasks (NSURLSessionUploadTask)

Upload tasks are used to upload data to a remote destination. We can use NSURLSessionUploadTask.

Download Tasks (NSURLSessionDownloadTask) 

Downloading a file and Storing in a temporary location. We can use NSURLSessionDownloadTask.

Main difference between NSURLSession and NSURLConnection
  • NSURLConnection: if we have an open connection with NSURLConnection and the system interrupt our App, when our App goes to background mode, everything we have received or sent were lost.
  • NSURLSession: solve this problem and also give us out of process downloads. It manage the connection process even when we don’t have access. You will need to use application:handleEventsForBackgroundURLSession:completionHandler in your AppDelegate


Wednesday 14 December 2016

Andriod Application Component





Activities
They dictate the UI and handle the user interaction to the smart phone screen.

public class MainActivity extends Activity {
}
 


Services
They handle background processing associated with an application.

public class MyService extends Service {
}

Broadcast Receivers
They handle communication between Android OS and applications.

public class MyReceiver  extends  BroadcastReceiver {
   public void onReceive(context,intent){}
}

Content Providers
They handle data and database management issues.

public class MyContentProvider extends  ContentProvider {
   public void onCreate(){}
}
 


Fragments
Represents a portion of user interface in an Activity.

Views
UI elements that are drawn on-screen including buttons, lists forms etc.

Layouts
View hierarchies that control screen format and appearance of the views.

Intents
Messages wiring components together.

Resources
External elements, such as strings, constants and drawable pictures.

Manifest
Configuration file for the application.
 
 
 
 
 

Monday 9 November 2015

Array elements Sorting

NSArray *stringsArray = [NSArray arrayWithObjects:
                                 @"string 1",
                                 @"String 21",
                                 @"string 12",
                                 @"String 11",
                                 @"String 02", nil];

static NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch | NSNumericSearch |
        NSWidthInsensitiveSearch | NSForcedOrderingSearch;
NSLocale *currentLocale = [NSLocale currentLocale];

NSComparator finderSortBlock = ^(id string1, id string2) {

    NSRange string1Range = NSMakeRange(0, [string1 length]);
    return [string1 compare:string2 options:comparisonOptions range:string1Range locale:currentLocale];
};

NSArray *finderSortArray = [stringsArray sortedArrayUsingComparator:finderSortBlock];
NSLog(@"finderSortArray: %@", finderSortArray);

SOLID Pribciples


SOLID Principles:



SOLID are five basic principles whichhelp to create good software architecture. SOLID is an acronym where:-
  • S stands for SRP (Single responsibility principle )
  • O stands for OCP (Open closed principle)
  • L stands for LSP (Liskov substitution principle)
  • I stands for ISP ( Interface segregation principle)
  • D stands for DIP ( Dependency inversion principle)


SRP
A class should have only a single responsibility. Only one potential change in the software's specification should be able to affect the specification of the class. 

OCP

Software should be open for extension, but closed for modification. 

LSP
Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program 

 ISP
No client should be forced to depend on methods it does not use.
Many client-specific interfaces are better than one general-purpose interface.

 DIP
High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions.

iOS Application iCons sizes