Friday, 22 May 2015

Test Flight for iOS 8 users

There are 2 types of invitations a user can get from the iTunes Connect

1. Internal Tester - only 25 beta testers for an account can be used.
2. External Tester - capping of 1000 external users.

The process to install the Application is similar in both the cases , the only difference is the internal user can install the application with the designated email id but for external tester you just need to have a email to install the application.

The validity for the application is 30 days , it comes with a red dot prefixed in the name of the app .

Process Starts

1. Invitation Email from iTunes - (if you are not a iTunes connect user , kindly create an email id)




2. Click on the Open in TestFlight



3. Install the TestFlight App in your iPhone


4. Once that is installed you need to Accept the agreement 




5. Hit Install and you are Done !!! :).





Please let me know if you are stuck some where.




Thursday, 22 January 2015

WhatsAPP Web version !!

HI Guys,

You all might be wondering how to install WhatsApp web version into your android phones as there is no WhatsApp web in the current installed version of the application.

WhatsApp Web: Its not an alternative to use WhatsApp from web rather using your mobile interface you can use browser for communication.  Just open the http://web.whatsapp.com in your chrome (only chrome and for android users ) and make your mobile connected to internet (preferably via WiFi) and you can see all your chats in browser and you can opt to have notifications in your mac  and can communicate from there it self. Sounds super awesome to me :).

So to start with- have a good internet connection !!

1. BackUp your conversations if you are already using it (i hope you are!!) !!

Open WhatsApp-->Go to settings --> Chat Settings --> BackUp Conversations

(or else you will loose your today morning conversation as daily backup happens at 4:00 AM in the morning)

2.  UnInstall the current version of WhatsApp in your android phone.

Don't worry WhatsApp gives you option to restore all the chats in your phone.

3. Please do not run any app like Clean Master to clean the cache or temp files as they may damage your old chat backup.

4. Install the new version of the WhatsApp from play store, verify your number and then Please Click on Restore conversation .

It will take a while to restore all your chats

And you are good to go !




After this go to menu option of WhatsApp


(Change your media setting from auto download to manual download if required)

It will ask you to open the URL:  https://web.whatsapp.com/ 

You need to update the Chrome of your Desktop . I am using Mac OS X 10.10.1 and Chrome Version : 39.0.2171.99 (64-bit).

For the users who didn't like this feature and who are trying to remove their whatsapp session from the browser you can log out from all computers from the mobile application itself !

Open WhatsApp --> Click Menu --> WhatsApp Web --> Log Out from all computers !!



Leave your comments below!


Disclaimer: I personally tried it and it worked for me like a charm . I shall not be responsible for anything  with your data , so try at your own risk !!

Saturday, 29 November 2014

Some Interesting Questions in iOS

1. Why we use auto layout in place of autoresize ?
Ans.  The main reason for this is that in auto layout we can have parent child relationship between views .

2. Categories over sub classing ?
Ans. If we use subclassing then we need to implement all the methods and then we can add methods to the child class but in Categories there is no overhead of implementing all the methods you can only add methods to the class .

3. If we add a protocol to a class and didn't implemented in .m file what will happen ?
Ans. Once added to the interface of a class the class will always confirm to the protocol , to check weather the class has the particular method we can use a method performSelector on the object.

4. When we use delegations and notifications ?
Ans. If we have related objects only then we use delegations for unrelated objects we use notifications

5. Keyword Assign
Ans. The assign will point to the object and we have take care to make it nil or it will become dangling pointer , if we use strong keyword then when the object is released the value is set to nil once the object is deallocated.

6. Operation queue VS GCD ?
Ans. In GCD we can't add or join operations . And dispatch queues are First In First Out.

7. Why we should use AFNetworking Framework ?

Ans. While NSURLConnection provides +sendAsynchronousRequest:queue:completionHandler: and+sendSynchronousRequest:returningResponse:error:, there are many benefits to using AFNetworking:
  • AFURLConnectionOperation and its subclasses inherit from NSOperation, which allows requests to be cancelled, > suspended / resumed, and managed by an NSOperationQueue.
  • AFURLConnectionOperation also allows you to easily stream uploads and downloads, handle authentication challenges, > monitor upload and download progress, and control the caching behavior or requests.
  • AFHTTPRequestOperation and its subclasses distinguish between successful and unsuccessful requests based on HTTP > status codes and content type.
  • AFNetworking includes media-specific request operations that transform NSData into more useable formats, like JSON, > XML, images, and property lists.
  • AFHTTPClient provides a convenient interface to interact with web services, including default headers, authentication, > network reachability monitoring, batched operations, query string parameter serialization, and multipart form requests.
  • UIImageView+AFNetworking adds a convenient way to asynchronously loads images.
8. Dispatch Queue vs Threads.
Ans.
1. The major advantage of using dispatch queues is that you can focus on the work that need to be performed as compared to the thread where you need to focus on both work and thread creation. 
2.The system can scale it dynamically based on the current condition of resources .
3.




Wednesday, 12 November 2014

Memory Management in Objective C

Stack
The stack is a region of memory which contains storage for local variables, as well as internal temporary values and housekeeping. On a modern system, there is one stack per thread of execution. When a function is called, a stack frame is pushed onto the stack, and function-local data is stored there. When the function returns, its stack frame is destroyed. All of this happens automatically, without the programmer taking any explicit action other than calling a function.

Heap
The heap is, essentially, everything else in memory. (Yes, there are things other than the stack and heap, but let's ignore that for this discussion.) Memory can be allocated on the heap at any time, and destroyed at any time. You have to explicitly request for memory to be allocated from the heap, and if you aren't using garbage collection, explicitly free it as well. This is where you store things that need to outlive the current function call. The heap is what you access when you call malloc and free

Copy
The copy in objective C is used to save a state of an object . It's generally used when an object have multiple owners and you are willing to save its current value. (Used for Mutable Objects)

Assign
The assign will generate a setter with assigns the value to the instance variable  directly, rather then copying or retaining it. This is best for primitive type like NSInteger and CGFloats or objects you don't own like delegates . 

The assign basically creates a weak pointer to the object and you need to make it nil or else it may become dangling pointer. 

Friday, 7 November 2014

Blocks in Objective C.

Blocks are Objective-C’s anonymous functions. They let you pass arbitrary statements between objects as you would data, which is often more intuitive than referencing functions defined elsewhere.

Note: "Blocks are created on stack and hence they will be released as the function call gets over. You need to copy block if you wish to sustain its data."

Blocks are similar to the functions in objective C.

In 3 simple Steps:


1. Declaration
// Declaration a Block
    int (^calculate)(int a, int b);

2. Definition

// Define
    calculate= ^int(int a, int b)
    {
        return a+b;
    };

3. Calling

    NSLog(@"sum is %d",calculate(5,6));

The '^' caret symbol is used to notify the complier that the calculate is a block .
So a block will have

1. Return type
2. Name
3. Variable

If we don't want that our block will have return type or params then we need to replace it with void.

// with return type and params
     int (^sum)(int a);

// without params
     int (^sum)(void);

// without params and return type

     void (^sum)(void);

Now we will work in details with block return type and params. 

//    Either This 
    void (^sum1)(int a)= ^void(int a){
         //  Some Code ....
    };
//   Or This both will differ is syntax only

    void (^sum1)(int a);

    sum1= ^void(int a)
    {
         // Some Code ...
    };
Specifying the return type of a block is always optional .

    int (^sum2)(void)= ^int(void)
    {
        
        NSLog(@"I am in block 2");
        return 4;
    };
    
    void (^sum4)(void)=^ {
        
        NSLog(@"I am in sum 4");
    };



In the above 2 examples if we don't produce the return type then it won't affect anything. It's also known as PARAMETER LESS blocks.
==
Blocks are implemented as closures which means they can have access of local and non local variables. 

For e.g. 

NSString *make = @"Honda";
NSString *(^getFullCarName)(NSString *) = ^(NSString *model) {
    return [make stringByAppendingFormat:@" %@", model];
};
NSLog(@"%@", getFullCarName(@"Accord"));    // Honda Accord

In the above example the "getFullCarName" is the block name and it has NSString as param and return type.
In the definition of the block we skipped the return type as it's purely optional and our param i.e. (NSString * model ) will be a local variable for block.
In the above example the "make" is non local variable and model is local and we are using both.

By default the variables are copied to the block and they are readonly. 

If you are willing to change the value of non local variables in the block you have to mentioned this in the variable declaration explicitly.

_ _ block NSString * myString =@"car";

Passing blocks as an argument of a function.

let us suppose a scenario .

There is a model class named Person and its has attributes age and height.

We have defined a block which will take an integer as a param and returns nothing


typedef void (^testBlock)(int b);

There is a instance function  which take block as a parameter.

-(void)calculateHeightUsingBlock:(testBlock)heightActivity;

In the .M file of this class we have mentioned its details 

 // Here ' heightActivity ' is the name variable for 'testBlock' and if you want to send control back to the calling place you need to call the block as did in the last line 'heightActivity(5)'

-(void)calculateHeightUsingBlock:(testBlock)heightActivity  
{
    NSLog(@"I am in calculate HEIGHT Block Class and height= %d",self.height);
    heightActivity(5); // this will execute the body written in the calling place.
}

Once you write the statement heightActvity(5), The control will go back from where this block is called and the body of block will be executed. 

// Now calling this block from a view controller

- (void)viewDidLoad

{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    Person * newPerson= [[Person alloc]init];
    newPerson.height=7;
    newPerson.age=40;
    
    [newPerson calculateHeightUsingBlock:^(int a) 
   {
        
        NSLog(@"I am in ViewController Block for Height %d",a);
    }];
// If you debug your code the control of a function will go back to the new person class as its a normal function call and once the task code of the Person class is executed then the control will be handover to the ViewController class and the Log statement will be executed. 
}
Here we are having call backs without using delegations. This is the beauty of blocks !!!.

Ref:
1. http://iosdevblog.com/
2. Block memory related: http://www.friday.com/bbum/2009/08/29/blocks-tips-tricks/  

Wednesday, 24 September 2014

Categories in iOS

Basic Definition:

Categories are wonderful feature of the Objective C language by using categories on a class we can expand the functionality of the class without touching it.

Analogy of category:

If you a smart phone (assume it as a base class) and you have some accessories of it like blue tooth earpiece (additional functionality)


                       

                                      Only Class                                  Class + Category.
                                        iPhone                                    iPhone + ear piece


Here we are not touching iPhone Class and adding functionality to the it that you can attend call from your earpiece.

So category will look like:

@interface iPhone (earPiece)
- (iPhone *)receiveCallFromBlueTooth:(BOOL)isEnabled;
@end

In the above syntax iPhone is class on which earPiece category is added.

Another Example:


We need to validate every email enter by the user every time and generally we don't have anything provided form apple and this situation come across several view controller and several projects .


An easy solution for this problem what i generally use create a category on NSString.


NSString+NSString_validateEmail.h
#import <Foundation/Foundation.h>

@interface NSString (NSString_validateEmail)
- (BOOL) isValidEmail:(NSString *)yourString;
@end

NSString+NSString_validateEmail.m
#import "NSString+NSString_validateEmail.h"

@implementation NSString (NSString_validateEmail)

- (BOOL) isValidEmail:(NSString *)yourString
{
    BOOL stricterFilter = YES; 
    NSString *stricterFilterString = @"[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}";
    NSString *laxString = @".+@([A-Za-z0-9]+\\.)+[A-Za-z]{2}[A-Za-z]*";
    NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:checkString];

} 
@end

TO Call this function in your VC , you just need to import the class 

#import "NSString+NSString_validateEmail.h"
and while comparing 

 if(! [self isValidEmail: abc@xyz.com])
{
   // Alert the user if validation fails.
}

Here are some of the common concepts for categories that generally confuses us.

1. Why can't we add instance variable to the categories ?

Ans: The methods that are available in any category are added to any class at RUN Time only .

2. Difference between categories and class extension ?

Ans: Class extension is basically used to expand the public interface of the class with some private methods and properties

  • Its scope is local to a single class 
  • It added on the compile time only
  • Method added in the extension of a class should be implemented in the class

Ref:  http://just-works.blogspot.in/2013/11/subclass-category-and-extensions-in.html


Thursday, 31 July 2014

UDID for iOS 7

Form iOS 7 UDID is not available for public API so it can't be extracted from any of the applications available in the market.


If you are using iOS 6 then it can easily be found by downloading this application :
UDID + by eMonster

But for iOS 7 we need to connect the device from iTunes and from there we can extract the UDID of device. (If we still use the application then we will get UDID Starting from FFFFFF means a Fake UDID. )

Here is the process explained.

1. Connect the device and open the iTunes navigate to iPhone 




2. Then Click on the serial Number



3 . Right Click to Copy the UDID.