Tuesday, April 8, 2014

Dismiss keypad or keyboard in iphone

use

    [self.view endEditing:YES];

it will dismiss keypad

Moving from portrait view to Landscape view / Potrait UI orientation to landscape Ui orienttion in Phone iOS / Ui Orientation according to device Orientation / manually forcing orientation / change orientation manually


When u are switching from one view to another view .
First view is Portrait mode and next mode is in Landscape mode . 
Even u have implemented
-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration;



USe 
+ (void)attemptRotationToDeviceOrientation

Attempts to rotate all windows to the orientation of the device.


-(void) viewDidAppear:(BOOL)animated
{
    [UIViewController attemptRotationToDeviceOrientation];
    [super viewDidAppear:animated];
}

-iPhone backboardd[52] : failed to resume in time

Some times u are getting this error
Feb 27 13:18:45 -iPhone backboardd[52] <Warning>: com.xyz.abc failed to resume in time

Main cause for this is the load on main thread. 
Try to avoid calling blocking calls for long time on main thread.
Create separate threads for such things.

If u know steps to reproduce follow steps find load on main thread also 
find performSelectorOnMainThread function used and get called at the same time.

try to avoid call many performSelectorOnMainThread functions.
Which crates extra burden on main thread.



iOS Architecture [ iPhone ]

reference:-http://www.techotopia.com/
iOS  Architecture




Application runs above the Cocoa Touch layer. Application can call any of layer to perform task.
Abstraction increments as layer goes away from hardware.

1. COCOA touch layer:-

Its upper layer written in objective C and derived (modified and extended ) standard Mac OS X Cocoa API. It consists of following frameworks.
 UIKit.framework - IT's UIkit framework. It contains application lifecycle management, event handling, UI creation and management, multitasking, cut copy paste functionality,Data protection,  Push Notification Service, Local notifications (a mechanism whereby an application running in the background can gain the user’s attention), gesture recognition., file sharing, Accelerometer, battery, proximity sensor, camera and photo library interaction. 
iAd.framework - to display advertising in the application. All advertisements are served by Apple’s own ad service.
MessageUI.framework- used in application to compose and send mail.
MapKit.framework:- used in app to use map related services.
AddressUI.framework:-used for to access, display, edit and enter contact information.
GameKit.framework:-provides framework for multiplayer game.
Push Notification Service :- for allow application to notify the user when application is not running.
Event Kit UI Framework:-to access and edit calendar event.

2. Media Services Layer


This layer provides audio, video , animation and graphics services to application developer.

CoreVideo.framework:- for video purpose, even with  streaming video support (network)
CoreText.framework:-for text layout and font
ImageIO.framework:- for importing and exxporting of image data and image metadata
AssetsLibrary.framework:- For finding and accesing photo and video files. adding new photo and videos to album.
CoreGraphics.framework( Quartz 2D API):-provide 2D rendering engine, support creation and presentation of pdf , vector based drawing , transparent layer,image rendering and gradient
QuartzCore.framework:-For animation and visual effects.
OpenGLES.framework:-for high performance 2D and 3D drawing
iOS Audio Support:- audio in AAC, Apple Lossless (ALAC), A-law, IMA/ADPCM, Linear PCM, µ-law, DVI/Intel IMA ADPCM, Microsoft GSM 6.10 and AES3-2003 formats
AVFoundation.framework:-playback, recording and management of audio content. this is objective C based
Core Audio Frameworks (CoreAudio.framework, AudioToolbox.framework and AudioUnit.framework):-playback and recording of audio files and streams and also provide access to the device’s built-in audio processing units.
OpenAL:- provide high-quality, 3D audio effects, typically using to provide sound effects in games.
MediaPlayer.framework:-is able to play video in .mov, .mp4, .m4v, and .3gp formats
CoreMIDI.framework:-to interact with MIDI compliant devices such as synthesizers and keyboards 

3.iOS Core Services Layer

this layer provides the foundation on which the above layer built.
AddressBook.framework:- access to addressbok contact database . add , modify, delete contactCFNetwork.framework:-provides a C-based interface to the TCP/IP networking protocol stack and low level access to BSD sockets. This enables application code to be written that works with HTTP, FTP and Domain Name servers and to establish secure and encrypted connections using Secure Sockets Layer (SSL) or Transport Layer Security (TLS).
CoreData.framework:-to ease the creation of data modeling and storage in Model-View-Controller
CoreFoundation.framework:- C-based Framework. provides basic functionality such as data types, string manipulation, raw block data management, URL manipulation, threads and run loops, date and times, basic XML manipulation and port and socket communication.
CoreMedia.framework:- lower level foundation upon which the AV Foundation layer is built
CoreTelephony.framework:- to access data related to telephony part.

EventKit.framework:-access to the calendar and alarms on the device.
Foundation.framework:-consists of Objective-C wrappers around much of the C-based Core Foundation Framework.
CoreLocation.framework:-to obtain the current geographical location of the device  and compass readings This will either be based on GPS readings, Wi-Fi network data or cell tower triangulation (or some combination of the three).
MobileCoreServices.framework:-identifying data types as text, RTF, HTML, JavaScript, PowerPoint .ppt files, PhotoShop images and MP3 files.
StoreKit.framework:- to facilitate commerce transactions between your application and the Apple App Store.  user can be given the option make additional payments from within the application.
SQLite library:-or a lightweight, SQL based database to be created and manipulated from within your iPhone application.
SystemConfiguration.framework:-allows applications to access the network configuration settings of the device to establish information about the “reachability” of the device (for example whether Wi-Fi or cell connectivity is active and whether and how traffic can be routed to a server).
QuickLook.framework:-provides a useful mechanism for displaying previews of the contents of files types loaded onto the device (typically via an internet or network connection) for which the application does not already provide support. File format types supported by this framework include iWork, Microsoft Office document, Rich Text Format, Adobe PDF, Image files, public.text files and comma separated (CSV).


4.iOS Core OS layer

sits directly on top of the device hardware.provides a variety of services including low level networking, access to external accessories and the usual fundamental operating system services such as memory management, file system handling and threads.

Accelerate.framework:-C-based API for performing complex and large number math, vector, digital signal processing (DSP) and image processing tasks and calculations.
ExternalAccessory.framework:-to interrogate and communicate with external accessories connected physically to the iPhone via the 30-pin dock connector or wirelessly via Bluetooth
Security.framework:-provides all type  of security interfaces including connect to external networks including certificates, public and private keys, trust policies, keychains, encryption, digests and Hash-based Message Authentication Code (HMAC)
LibSystem(System):-iOS is built upon a UNIX-like foundation. component of the Core OS Layer provides much the same functionality as any other UNIX like operating system.This layer includes the operating system kernel  and device drivers. provides the low level interface to the underlying hardware. kernel is responsible for memory allocation, process lifecycle management, input/output, inter-process communication, thread management, low level networking, file system access and thread management.As an app developer your access to the System interfaces is restricted for security and stability reasons. 






different type of Application template [ iPhone ] [ xcode ]

Different types of templates in XCode

There are different types of application template in XCode.
Navigation-based Application :- creation application which will having navigation from one view to other.
Open GL ES Application:-creates a basic application containing an Open GL ES view upon which to draw and manipulate graphics.
Split View Application :- An iPad only application template with a user interface containing two views in a master-detail configuration whereby a one view provides a list and second displays detailed information corresponding to the current list selection.
Tab Bar Application:-Creates a template application with a tab bar. tab bar typically appears across the bottom.
Utility Application:- Creates a template consisting of a two sided view.
View-based Application – Creates a basic template for an application containing a single view.
Window-based Application – The most basic of templates and creates only a window and a delegate.


The company identifier is typically the reversed URL of your company’s website, for example “com.mycompany”. This will be used when creating provisioning profiles and certificates to enable applications to be tested on a physical iPhone device.

Objective C source files have .m extension and  header or interface files .h extension.
.xib files have User interface created .
 .plist file extension are Property List files that contain key/value pair information , contains such as the language, icon file, executable name and app identifier..

Summary screen, tabs are provided to view and modify additional settings consisting of Info, Build Settings, Build Phases and Build Rules.

Frequently used Design pattern used in iPhone Programming [ iPhone ] [ iOS ]

Model View Controller 

Model encapsulates the data for the application, the View presents and manages the user interface and the Controller provides the basic logic for the application and acts as the go-between, providing instructions to the Model based on user interactions with the View and updating the View to reflect responses from the Model. 
the Model knows absolutely nothing about the presentation of the application. View knows nothing about the data and logic model of the application.
App can consist of multiple view objects, controller objects and model objects.
view controller object interacts with a Model is through the methods and properties exposed by that model object.

Target-Action pattern

In the Target-action design pattern the object contains the necessary information to send a message to another object when an event occurs.  where a computer program is divided up into objects which dynamically establish relationships by telling each other which object they should target and what action or message to send to that target when an event occurs. This is especially useful when implementing graphical user interfaces, which are by nature event-driven.
Action methods are declared using the IBAction keyword. and targets are declared using 
IBOutlets.  Here IB is for interface builder.

Subclassing


Subclassing allows us to create a new class by deriving from an existing class and then extending the functionality. we get all the functionality of the parent class combined with the ability to extend the new class with additional methods and properties.

Delegation



Delegation allows an object to pass the responsibility for performing one or more tasks on to another object. This allows the behavior of an object to be modified without having to go through the process of subclassing it.

Handling AddressBook in iphone [ iOS ]


ABAddressBookRef is class in iOS used to access the address book (a centralized database used by multiple application). with this class we can add, modify, delete the contact.

Create new address book object  from address book database.:-

ABAddressBookRef pAddressBook = ABAddressBookCreateWithOptions(NULL, &error);

Each record in the Address Book database hase a unique ID , which you can retrive by ABRecordGetRecordID function.

 ABRecordRef class holds one record inside.
You can access records as follows

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);
CFArrayRef allSources = ABAddressBookCopyArrayOfAllSources(addressBook);

for (CFIndex i = 0; i < CFArrayGetCount(allSources); i++) 

        {
ABRecordRef source = (ABRecordRef)CFArrayGetValueAtIndex(allSources, i);
      }

Display loading indicator / Activity Indicator / daisy wheel in top status bar [ iPhone ]


In UIApplication:
To start indicator:-
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
To stop indicator

UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO;



About ViewController / view Controller in iPhone [ iOS ]

View Controllers are the link between data and view(visual appearance). Whenever iOS displays anything on screen it is managed by the ViewController or group of ViewControllers coordinating with each other ViewController provides the skeletal framework on which we can build our application.

iOS provides many built-in view controller classes to support standard user interface pieces, such as navigation and tab bars. You can write ur own custom view-controller.

Below image and article reference (apple website source:-http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html)



ViewController manages set of views. It provides view that can be displayed or interacted with it. Normally viewcontrollers have one root view which consists of multiple view like button, editbox etc.

Container View Controllers Manage Other View Controllers. One viewcontroller may consists of multiple view controller by forming parent-child relationship with single root viewcontroller..

We can switch to another viewcontroller from current one. Navigation controller is used for switching one view to another. Navigation controller keeps all viewcontroller in stack ways. So if displayed view is poped u will go to previous view.

A key part of any view controller’s implementation is to manage the views used to display its content. 

View-Controller manages views also they are coordinate with each other.

How View Controllers Present Other View Controllers

The view controller that did the presenting updates its presentedViewControllerproperty to point to its presented view controller. Similarly, the presented view controller updates its presentingViewControllerproperty to point back to the view controller that presented it.

 you can chain presented view controllers together, presenting new view controllers on top of other view controllers as needed.
Each view controller in a chain of presented view controllers has pointers to the other objects surrounding it in the chain. In other words, a presented view controller that presents another view controller has valid objects in both its presentingViewController andpresentedViewController properties. You can use these relationships to trace through the chain of view controllers as needed. Ex:you can remove all objects in the chain by dismissing the first presented view controller. 

When presenting a navigation controller, you always present the UINavigationController object itself, rather than presenting any of the view controllers on its navigation stack. However, individual view controllers on the navigation stack may present other view controllers, including other navigation controllers. 

Figure 10-3  Presenting navigation controllers modally

As you can see, the people picker is not presented by the photo library navigation controller but by one of the content view controllers on its navigation stack.

Listing 10-1  Presenting a view controller programmatically
/ Create the root view controller for the navigation controller
   // The new view controller configures a Cancel and Done button for the
   // navigation bar.
   RecipeAddViewController *addController = [[RecipeAddViewController alloc]
                       init];
 
   // Configure the RecipeAddViewController. In this case, it reports any
   // changes to a custom delegate object.
   addController.delegate = self;
 
   // Create the navigation controller and present it.
   UINavigationController *navigationController = [[UINavigationController alloc]
                             initWithRootViewController:addController];
   [self presentViewController:navigationController animated:YES completion: nil];






Lazy Instantiation in Objective-C [ iphone ] [ iOS ] [ Objective C ]

Lazy Instantiation (initialisation ) , this technique is good if you have an object that only needs to be configured once and has some configuration involved that you don't want to clutter your init method.

Means in init method does not initialising the object. Initialise  object somewhere else in other method of the same class  may be accessor etc.


So you want an NSMutableArray property. You could alloc init it in some method before you use it, but then you have to worry about "does that method get called before I need my array?" or "am I going to call it again accidentally and re-initalize it."
So a failsafe place to do it is in the property's getter. It gets called every time you access the property.

Example

.h

@property (nonatomic, strong) NSMutableArray* myArray;.m@synthesize myArray = _myArray;- (NSMutableArray*) myArray{
if (!_myArray){ _myArray = [[NSMutableArray alloc] initWithCapacity:2];}
return _myArray;}
Every time you access that property, it says, "Does myArray exist? If not, create it. If it does, just return what I have."




About

Powered by Blogger.