Create Ad Hoc beta to test ongoing iOS Application

Create Ad Hoc beta to test ongoing iOS Application

Within few simple steps we can make adhoc beta test file for iOS Application. It requires when we needs to provide beta release to testers for the ongoing iOS Application. Also at some stages we have to send beta releases to clients for checking the progress of the application.

For the beta release we can use adhoc distribution or development profile. Here we will use wild card development provisioning which is generic provisioning & used for the multiple application by changing suffix values & keeping bundle name as it is.

So here is the video demonstrate how to generate ipa file for beta testing on devices.

Share
Resize Image without Losing Actual Scale and Proportion

Resize Image without Losing Actual Scale and Proportion

In iOS application, memory management is an important aspect of making a seamless & smooth UI experience. Now to make it more challenging part comes when images are loaded. Most of the memory leaks & issues appear due to a large size of images loaded from the web interface.

So to overcome this issue it becomes necessary to resize an image before its used. While resizing we will have to make sure image will be resized to the size where actually used in the application.

Let’s say from web interface image loaded with the size of 1000 pixels. But we need to show an image on UIImageView which has size 400x400 pixels. So at the time before using actual image needs to be resized.

It will not only less the memory usage but will also improve the overall performance of the app by loading app faster.

While doing image resizing operations it becomes important to make sure image doesn’t lose its scale. If it’s ignored than image will get starched & will not look as it should be. That will result in bad programming & bad interface as well.

So here is the example for resizing the image without losing the actual scale & proportion.

Resize with new width :

This particular function requires passing actual image & new width which you wants to resize an image with & it will automatically calculate the height according to the image scale & proportion & will return a new resized image. It will not lose the actual scale of image & still, an image will be resized.

Read more: Free online mockup sites to generate eyecatchy screenshots for mobile apps

Objective C :

-(UIImage *)resizeImageWithNewWidth:(UIImage *)image newWidth:(CGFloat)nwidth {

float scale = nwidth / image.size.width;

float newHeight = image.size.height * scale;

UIGraphicsBeginImageContext(CGSizeMake(nwidth, newHeight));

[image drawInRect:CGRectMake(0, 0, nwidth, newHeight)];

UIImage *nImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return nImage;

}

Swift :

func resizeImage(image: UIImage, newWidth: CGFloat) -> UIImage {

let scale = newWidth / image.size.width

let newHeight = image.size.height * scale

UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))

image.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight))

let newImage = UIGraphicsGetImageFromCurrentImageContext()

UIGraphicsEndImageContext()

return newImage!

}

Resize with new height :

This particular function requires to pass actual image & new height which you wants to resize image with & it will automatically calculate the width according the image scale & proportion & will return new resized image. It will not loose the actual scale of image & still image will be resized.

Objective C :

-(UIImage *)resizeImageWithNewHeight:(UIImage *)image newheight:(CGFloat)nheight {

float scale = nheight / image.size.height;

float newwidth = image.size.width * scale;

UIGraphicsBeginImageContext(CGSizeMake(newwidth, nheight));

[image drawInRect:CGRectMake(0, 0, newwidth, nheight)];

UIImage *nImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return nImage;

}

Swift :

func resizeImage(image: UIImage, newHeight: CGFloat) -> UIImage {

let scale = newHeight / image.size.height

let newWidth = image.size.width * scale

UIGraphicsBeginImageContext(CGSize(width:newWidth, height:newHeight))

image.draw(in: CGRect(x:0, y:0, width:newWidth, height:newHeight))

let newImage = UIGraphicsGetImageFromCurrentImageContext()

UIGraphicsEndImageContext()

return newImage!

}

Share
Storing and Retrieving Data from NSUserDefaults

Storing and Retrieving Data from NSUserDefaults

In this blog, you will find how to manage user default records by storing & retrieving into NSUserDefaults.

By using NSUserDefaults class we can store default settings, preferences or any such default values in string or dictionary or array format. It can be achieved with just a few lines of code & it loads data faster. Its usually used for storing small data where no such complex operations are required to perform.

The main advantage of using NSUserDefaults for storing a small number of values is it loads data faster than other storage options. More importantly, it doesn’t block the main thread. So it’s not slowing down UI operations & make sure app runs smoothly. That’s why NSUserDefaults class is threaded safe.

Here are simple steps for storing, retrieving & removing data from NSUserDefaults.

 

Saving data to NSUserDefaults :

Objective C :

[[NSUserDefaults standardUserDefaults] setObject:strUsername forKey:@”username”];

[[NSUserDefaults standardUserDefaults] synchronize];

Swift :

UserDefaults.standard.set(strUsername, forKey: “username”)

Read more: Top 10 must have WooCommerce Plugins for WordPress site

Retrieving data to NSUserDefaults :

Objective C :

strUsername = [[NSUserDefaults standardUserDefaults] stringForKey:@”username”]

Swift :

let strUsername : String = UserDefaults.standard.value(forKey: “username”) as! String

Removing NSUserDefaults value :

Objective C :

[[NSUserDefaults standardUserDefaults]  removeobjectForKey:@”username”];

Swift :

UserDefaults.standard.removeObject(forKey: “username”)

Share
Use UIGestureRecognizer for Different Touch Events

Use UIGestureRecognizer for Different Touch Events

UIGestureRecognizer class recognizes a sequence of touches & performs on basis of the recognizer. Here is the list of different gesture events.

It’s more useful for adding action events for controls which don’t contain default actions like UIButton.

UITapGestureRecognizer :

Its used for handle single or multiple taps.

UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureTapped:)];

gest.delegate = self;

[view addGestureRecognizer:gest];

-(void) gestureTapped:(UITapGestureRecognizer)sender {

}

UIPinchGestureRecognizer :

Its used for handle two taps simultaneously. This gesture used generally for image scaling & zooming feature.

UIPinchGestureRecognizer * gest = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(gestureTapped:)];

gest.delegate = self;

[view addGestureRecognizer:gest];

-(void)gestureTapped:(UIPinchGestureRecognizer*)sender {

sender.view.transform = CGAffineTransformScale(sender.view.transform, sender.scale, sender.scale);

sender.scale = 1;

}

Read more: How to Create and Setup a Prefix Header File for iOS

UIRotationGestureRecognizer :

Its used for handle rotation feature. When a user moves two fingers opposite each other circular way. It will rotate the view in the corresponding direction.

UIRotationGestureRecognizer * gest = [[ UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)];

gest.delegate = self;

[view addGestureRecognizer:gest];

-(void)rotateImage:(UIRotationGestureRecognizer*)sender {

if ([sender state] == UIGestureRecognizerStateBegan || [sender state] == UIGestureRecognizerStateChanged) {

[sender view].transform = CGAffineTransformRotate([[sender view] transform], [sender rotation]);

[sender setRotation:0];

}

}

UISwipeGestureRecognizer :

Its used for handle actions on swipe. Move views on swiped direction or actions on image with swipe to remove or swipe to load new image.

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwap:)];

switch (self.direction) {

case DirectionFromTop:

swipe.direction = UISwipeGestureRecognizerDirectionDown;

break;

case DirectionFromLeft:

swipe.direction = UISwipeGestureRecognizerDirectionRight;

break;

case DirectionFromBottom:

swipe.direction = UISwipeGestureRecognizerDirectionUp;

break;

case DirectionFromRight:

swipe.direction = UISwipeGestureRecognizerDirectionLeft;

break;

}

[view addGestureRecognizer:swipe];

-(void)didSwap:(UISwipeGestureRecognizer*)gesture {

}

UIPanGestureRecognizer :

Its used for handle dragging actions like moving images into view or moving any other objects on finger movement.

UIPanGestureRecognizer *gest = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanImage:)];

[imgViewStyleOutfit addGestureRecognizer:gest];

– (void)handlePanImage:(UIPanGestureRecognizer *)sender {

static CGPoint originalCenter;

if (sender.state == UIGestureRecognizerStateBegan) {

originalCenter = sender.view.center;

[sender.view.superview bringSubviewToFront:sender.view];

} else if (sender.state == UIGestureRecognizerStateChanged) {

CGPoint translation = [sender translationInView:self.view];

sender.view.center = CGPointMake(originalCenter.x + translation.x, originalCenter.y + translation.y);

}

}

UILongPressGestureRecognizer :

Its used for handle long press events. For that user needs to press for minimum amount of time to call actions.

UILongPressGestureRecognizer *gest = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(hangleLongPress:)];

[view addGestureRecognizer:gest];

-(void)hangleLongPress:(UILongPressGestureRecognizer*)sender {

if (sender.state == UIGestureRecognizerStateBegan) {

}

}

Share
How to Create Single View iOS Application

How to Create Single View iOS Application

Creating single view application with hello word is easy with just a few steps. Below are described steps for starting up native application development in iOS with simple Hello word application.

  • Open Xcode from application folder or find it from finder & open it
  • Directly click create Project or select from file -> New -> Project
  • Now it will ask for to choose a template for the project. Select SingleView App & click next

Read more: How to Create and Setup a Prefix Header File for iOS

  • Next step is to set app name, bundle name & select Language. Check below screenshot.
  • In product name add your application name as you wish. It will be editable later on.
  • Select Team from a drop-down. By default, the team will be your system admin name
  • Type organization name. If you are an individual developer you can add your name or company name
  • Now the most important part is Language selection. Note that once you selected Language than it will not be editable later on. So it becomes more important to think about the future scope of the application & choose the language.
  • You can tick below check marks for Use core data & unit tests depending on required usage during the development. We will keep it unticked as it’s not required in the application right now
  • Once all fields fill up properly then click next.
  • Now it will ask to choose a path. Select location where you would like to save the project source
  • An application is now ready for the development you can start making simple controls on it & run it on a simulator for testing
  • Below the full video for creating simple single view hello word application
Share
Share