Thursday, 26 February 2015

e-mail

Objective:
               To Configure,compose,send an e-mail.

Approach:
                1.Add the framework.
                2. configure the mail account;
                3.Pre-populate the fields like recipients,subjects,body-text;

Solution:
                 Mail functionality is not build in,so we have to import frameworks from the library.
click project navigator-->Target application-->Build Phases-->link libraries to the section-->click on + button and add UImessage Framework

import class [MessageUI/MessageUI.h] and protocol <MFMailComposeViewController> in the header file;

And create an instance for MFMailComposeViewController;


                
Here you set the default settings for the various fields in your email.

The available settings are:

setSubject:
setToRecipients:
setCcRecipients:
setBccRecipients:
setMessageBody:isHTML:
addAttachmentData:mimeType:fileName:


We need to determine if the user is first capable of sending e-mail, like if they have an email account set up in the mail app[configure]. Luckily for us, there is a class method that shows us just that[CanSendMail].

















if the user has no email account setup,he will get an alert stating that"device not configured to send e-mail".

now set the delegate to self.
we can pre-set the recipients and set a subject,add a text to message body (optional)




Add the delegate method-didFinishWithResult ;

This delegate has only one instance method[MfMailComposerResult] and it is called when the user is ready to dismiss the mail composer.



Conclusion:
                MFMailComposeViewController tutorial is done.It is a very simple view controller, but it lets you get the job done efficiently.


Active Internet Connection

Objective:
             To check whether internet connection exists in the device or not.

Approach:
             Most apps use active internet connection to call and pass the data.so it's always important to check the internet connection availability at the first place.

Solution :
            To do that,import SDK from -//github.com/preetlotey999/Reachability-Class-For-iOS.git
Download the .Zip file and add to our project.

import header file(reachability.h) into the project.

Since third party libraries,frameworks haven't updated to automatic refrence counting,we will encounter memory problems.so to disable arc for single file, do the following:

1.In the project navigator(left panel)click the project header;
2.Click build phases tab;
3.Expand the compiler sources;
4.Double click the source file that you wish to disable ARC.
5.Add-fno-objc-arc in the popup.









Now it's a simple process.
1.create an instance for the reachablity class;
2.check network status;
























Conclusion:
                      It's always important to check the internet connection before hand instead showing at the last .So with this simple lines of codes we can make that possible,i believe this can come in handy at many places.

Tuesday, 24 February 2015

Date Picker.

 DatePicker:
                    Date picker is a control used for selecting date,time or both.It provides a straightforward interface for managing date and time,allowing users to select quickly and efficiently. Appearance of date pickers cannot be customised.


Design and Implementation:

1.Declare an instance variable in .h file;
2.Set a frame;
3.set date picker mode to UIdatepickermodedate;


Output for the above code will be



















Conclusion:
                 If you are interested,you can make an accurate countdown timer app by adding label to display the countdown and a button method that calculates the time left from the selected date.







Friday, 20 February 2015

Objective-c:-Method,IBOutlet,IBAction.

What is a Method?
                              Method is a block of code that runs in response to a message,which performs specific functionality.

In objective C method definitions begin with a dash sign(-)and a plus sign (+);

Dash sign(-)-Indicates that it's an instance level method,An instance method can only be accessed by the instance of the class where method is defined.

Plus sign(+)-Indicates that it's an class level method,which can be accessed anytime just by simply referencing the class.

IBOutlet:
             IBOutlet is used to define a property to the UIComponent in the Xib File.

IBAction:
              IBAction is used to define a method to the UIComponent in the Xib.

Objective c-Access specifiers,property,Synthesize,dynamic

Access Specifiers:

The scope of instance variable are limited by access specifiers.

There are 3 access specifiers in Objective c:
1.Protected-The scope of the instance variable is limited to the declared class and also inherited class.
2.Public-No limitation,can be accessed globally.
3.private-The scope of the instance variable is limited only to the class declaring it.

In objective c,default access specifier  is Protected.

Property:
              Properties are convenient alternatives to write out the access specifiers.To put in simple words-Property is used to define the behaviour of the instance variable.It is used to generate getter & setter methods at run time.properties offer a way to define the information that a class is intended to encapsulate.

We can also add attributes to the property:
1.read,write,readonly,assign,strong,weak,atomic,non-atomic.

Syntax:
@(attributes)Superclass *InstanceVariable;

Synthesize:
                It is used to generate getter & setter methods at run time.If a property has been declared in header file it has to synthesised.

Syntax:
@synthesize PropertyName;

Dynamic:
             It just tells the compiler that the getter and setter methods are implemented not by the class but somewhere else-like super class or provided at run time.

Syntax:
@dynamic Property name;








UIProgress View.

Objective:
                  1.To understand progress view.
                  2.write a simple program that helps understanding progress view better.

What is a Progress View?
                                       Progress View is a UI element that tracks the level of completion of a process.

When it is used?
                        Mostly used to show the progress of a download to the user.

Design:


                 Add a button(Download) to track the progress and a label to display the progress.




That's it.Now write your code and run the program and see how it works.

Conclusion:
                    UIProgress view class depicts the progress of a task over time.








Thursday, 19 February 2015

Collection Objects.

OBJECTIVE:
                    To understand collection objects in objective-c & their usages-Introduction.

APPROACH:
                   1.What is a collection object?-Definition.
                   2.A precise walk through collection objects-Explanation.

SOLUTION:
                   Collection object is a foundation framework class used for storing and managing group of objects.

It's primary role is to store the objects in the form of Array,Dictionary,Set.




This includes both immutable and mutable collection objects:

1.Immutable:-The values stored are static(cannot be changed once created)
-->NsSet,
-->NSArray,
-->NsDictionary.

2.Mutable :-The values stored are dynamic(Values can be altered)
-->NSMutableSet,
-->NsMutableArray,
-->NsMutableDictionary.


NsArray:
             NSArray creates static arrays.they hold the objects in a order.

  And the output of the following code is

As you can see,the order of the objects remains unchanged.


NSSet:
         An NSSet is much same like an NSArray,the only difference is that the objects an NSSet holds are not in order.so when we retrieve them they may come back in any random order,based on how easy it is for the system to retrieve them.

So when is it used?it's used mainly when access speed matters and the order is not much of a concern.

And the output is:
Here,the order of the objects are altered or modified.

while NSSet and NSMutable set store collections of distinct objects and NSCounted Set is used to stores collections of non-distinct objects.(NSCountedSet, a subclass of NSMutableSet, is a mutable set to which you can add a particular object more than once) .

NSDictionary:
                     An NSDictionary stores objects in keys and value pairs.The objects are not ordered but they can be retrieved by addressing them with an arbitrary string value.they allow for a faster insertion and deletion processes.

And the output is: