Thursday 12 December 2013

Bounce the UIView vertically using CABasicAnimation


+(void)bounceTheViewVertically:(UIView*)view
{
    CGPoint origin = view.center;
    CGPoint target = CGPointMake(view.center.x, view.center.y-50);
    CABasicAnimation *bounce = [CABasicAnimation animationWithKeyPath:@"position.y"]; //Animations for y axis
    bounce.duration = 0.5;
    bounce.fromValue = [NSNumber numberWithInt:origin.y];
    bounce.toValue = [NSNumber numberWithInt:target.y];
    bounce.repeatCount = 2;
    bounce.autoreverses = YES// undo changes after Animations.
    [view.layer addAnimation: bounce forKey:@"position"];

}

Thursday 5 December 2013

The unique identifier in iOS App. "UDID" is replaced in ios 7 with "identifierForVendor"!

Sometimes in our app we need the unique key for identifying the device or user.

We can use UDID till iOS 6 and identifierForVendor for iOS 7 onwards.

    -(NSString*)uniqueIDForDevice
    {
        NSString* uniqueIdentifier = nil;
        if( [UIDevice instancesRespondToSelector:@selector(identifierForVendor)] ) {
             // >=iOS 7
            uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        }
        else {  //<=iOS6, Use UDID of Device     
                CFUUIDRef uuid = CFUUIDCreate(NULL);
                //uniqueIdentifier = ( NSString*)CFUUIDCreateString(NULL, uuid);- for non- ARC
                uniqueIdentifier = ( NSString*)CFBridgingRelease(CFUUIDCreateString(NULL, uuid));// for ARC
                CFRelease(uuid);
             }
        }
    return uniqueIdentifier;
    }



Important Note ---

UDID and identifierForVendor are different:---     

  •     1.) On uninstalling  and reinstalling the app identifierForVendor will change.   
  •     2.) The value of identifierForVendor remains the same for all the apps installed from the same vendor on the device.
  •     3.) The value of identifierForVendor also changes for all the apps if any of the app (from same vendor) is reinstalled.