Basic iOS Application Animation Tutorial

Basic iOS Application Animation Tutorial

Using animations in iOS Application can make it more impressive. A user always loves to use something new innovative things. There are few basic animations available in both Objective C & Swift by using that we can covert a normal user experience to something special.

It’s not necessary that it will make a vast difference in the application. Some of the users even do not notice such things. But at least that will make your application stand differently than the other similar application with just a few lines of codes.

Here are some basic animation techniques available which you can utilize into your application to make it different.

View Transition animations :

This will allow page curl animation while presenting new view controller.

For Presenting :

NextView *ivc = [mainstoryboard instantiateViewControllerWithIdentifier:@”nextview”];

[UIView transitionWithView:APP_DEL.window duration:0.5 options:UIViewAnimationOptionTransitionCurlUp animations:^{

}completion:nil];

[self presentViewController:ivc animated:NO completion:nil];

 

For Dismissing :

[UIView transitionWithView:APP_DEL.window duration:0.5 options:UIViewAnimationOptionTransitionCurlDown animations:^{

}completion:nil];

[self dismissViewControllerAnimated:NO completion:nil];

 

Here are the more transition animations available which you can use in place of curl animations :

UIViewAnimationOptionTransitionFlipFromLeft    = 1 << 20,

UIViewAnimationOptionTransitionFlipFromRight   = 2 << 20,

UIViewAnimationOptionTransitionCurlUp          = 3 << 20,

UIViewAnimationOptionTransitionCurlDown        = 4 << 20,

UIViewAnimationOptionTransitionCrossDissolve   = 5 << 20,

UIViewAnimationOptionTransitionFlipFromTop     = 6 << 20,

UIViewAnimationOptionTransitionFlipFromBottom  = 7 << 20,

 

View animations with completion :

This is simple view frame animation which allows you to move view through out the animation. It will used to open view with moving animation.

view.frame = CGRectMake(0, 0, 0, 0);

[UIView animateWithDuration:0.7 animations:^{

view.frame = CGRectMake(0, 0, 375, 667);

} completion:^(BOOL finished) {

// On completion show objects on view

}];

 

This is simple view frame animation which allows you to show view with blink effect.

view.alpha = 0.0;

[UIView animateWithDuration:0.7 animations:^{

view.alpha = 1.0;

} completion:^(BOOL finished) {

// On completion show objects on view

}];

More animation methods can be used with few more features :

  • (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
  • (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0,
  • (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);
Share
SQLite Useful Functions for Beginners

SQLite Useful Functions for Beginners

SQLite database provides advanced functions for adding, removing, updating records into a database. It also allows performing some of the advanced levels of operations like database migration, Inner join, a grouping of tables etc.

Its normally used to store large records into the application such as managing user list, or offline records of web-based data to make sure it supports an offline load of the data in case of no internet connection.

Running with SQL functions is as faster as any other database storage options & its more convenient options too. The reason is it provides advance inserting & deleting features & clauses which allows developers to perform complex operations over a local database.

So here are some basic functions which we normally use in iOS Application for managing local database.

Save record :

– (void) doSaveMyData  {

sqlite3 *database;

[self CheckConnection];

if (sqlite3_open([dbpath UTF8String], &database) == SQLITE_OK)  {

NSString *query = [NSString stringWithFormat:@”insert into myTable values(‘%@’, ‘%@’)”, value1, value2];

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpSqlStmt;

sqlite3_prepare_v2(database, sqlStmt, -1, &cmpSqlStmt, NULL);

sqlite3_step(cmpSqlStmt);

sqlite3_finalize(cmpSqlStmt);

}

sqlite3_close(database);

}

For Check Database Connection (This will commonly used before any database operation)

-(void)CheckConnection {

NSArray *docpath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *docdir = [docpath objectAtIndex:0];

dbpath = [docdir stringByAppendingPathComponent:database];

BOOL success;

NSFileManager *fm = [NSFileManager defaultManager];

success = [fm fileExistsAtPath:dbpath];

if(success) {

return;   }

NSString *dbPathFromApp = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:database];

[fm copyItemAtPath:dbPathFromApp toPath:dbpath error:nil];

}

Get list of records :

-(void)doGetRecords:(NSString*)strCatID {

[self CheckConnection];

if (arrList.count > 0) {

[arrList removeAllObjects];

arrList = nil;

}

arrOutFitsList = [[NSMutableArray alloc] init];

sqlite3 *database;

if (sqlite3_open([dbpath UTF8String], &database)==SQLITE_OK) {

NSString *query = [NSString stringWithFormat:@”select * from myTable where cat_id = ‘%@””,strCatID];

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpsqlstmt;

if (sqlite3_prepare_v2(database, sqlStmt, -1, &cmpsqlstmt, NULL) == SQLITE_OK) {

while (sqlite3_step(cmpsqlstmt) == SQLITE_ROW) {

DetailDict *obj = [DetailDict new];

obj.id = [NSString stringWithFormat:@”%d”,(int)sqlite3_column_int(cmpsqlstmt, 0)];

obj.Tag = [NSString stringWithUTF8String:(char*)sqlite3_column_text(cmpsqlstmt, 1)];

[arrOutFitsList addObject:obj];

}

sqlite3_finalize(cmpsqlstmt);

}

sqlite3_close(database);

}

Update record :

-(void)doUpdaterecord {

[self CheckConnection];

sqlite3 *database;

if (sqlite3_open([dbpath UTF8String], &database)==SQLITE_OK) {

NSString *query = [NSString stringWithFormat:@”update myTable set cat_id=’%@’, Tag=’%@'”, self.objDetailsDict.cat_id, self.objDetailsDict.Tag];

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpSqlStmt;

sqlite3_prepare_v2(database, sqlStmt, -1, &cmpSqlStmt, NULL);

sqlite3_step(cmpSqlStmt);

sqlite3_finalize(cmpSqlStmt);

}

sqlite3_close(database);

}

Remove Record :

-(void)doRemoveRecord:(NSString*)stID {

[self CheckConnection];

sqlite3 *database;

if (sqlite3_open([dbpath UTF8String], &database)==SQLITE_OK) {

NSString *query = [NSString stringWithFormat:@”DELETE FROM myTable WHERE id=’%@'”,stID];

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpSqlStmt;

sqlite3_prepare_v2(database, sqlStmt, -1, &cmpSqlStmt, NULL);

sqlite3_step(cmpSqlStmt);

sqlite3_finalize(cmpSqlStmt);

}

sqlite3_close(database);

}

Count Number of Records :

-(int)doCountToalRecords:(NSString *)ID {

[self CheckConnection];

int totalIS = 0;

sqlite3 *database;

if (sqlite3_open([dbpath UTF8String], &database)==SQLITE_OK) {

NSString *query = [NSString stringWithFormat:@”SELECT Count(*) FROM myTable where cat_id = ‘%@'”,ID];

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpsqlstmt;

if (sqlite3_prepare_v2(database, sqlStmt, -1, &cmpsqlstmt, NULL) == SQLITE_OK) {

while (sqlite3_step(cmpsqlstmt) == SQLITE_ROW) {

totalIS = sqlite3_column_int(cmpsqlstmt, 0);

}

}

sqlite3_finalize(cmpsqlstmt);

sqlite3_close(database);

}

return totalIS;

}

Add new field to existing table :

-(void)doAddNewFieldToTable {

sqlite3 *database;

if (sqlite3_open([dbpath UTF8String], &database)==SQLITE_OK) {

NSString *query = @”ALTER TABLE myTable ADD COLUMN newField Varchar”;

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpsqlstmt;

if (sqlite3_prepare_v2(database, sqlStmt, -1, &cmpsqlstmt, NULL) == SQLITE_OK) {

while (sqlite3_step(cmpsqlstmt) == SQLITE_DONE) {

NSLog(@”Success”);

}

}

sqlite3_finalize(cmpsqlstmt);

sqlite3_close(database);

}

}

So in this blog we have covered up all basic operations performed in sqlite database such as inserting, fetching, updating, removing records & also for counting number of records, adding new field to existing table while working with Objective C in iOS Application.

Share
Convert Your Project to Latest Swift Version

Convert Your Project to Latest Swift Version

Whenever new Xcode version release or any new OS releases apps developed with the swift language are needed to convert to the new swift version. There might be syntax changes or any bugs solving or something done in the swift language which requires apps to be updated with latest stable version.

Now, in this case, developers often try to make compatibility by manually running app & finding the bugs. Now, this process consumes more time & sometimes it takes too long to debug & find the exact solution. Overall it becomes tidy process & not exactly what Apple prefers.

So here are the proper steps to perform the process:

First of all, open your project into latest Xcode version & make sure don’t run it the first time.

Go to Edit -> Convert -> To current swift syntax

This will open hierarchy of files. Make sure there will be all files selected with a check mark which you wants to convert to latest swift syntax. If any files not selected or you don’t want that to a concert than manually uncheck it. Then clicking on done will do the rest of the work.

Note :

In new swift version, latest swift conversion process works perfectly & don’t require actually to manually resolve any errors. But still, there could be the chance of any errors skipped by the compiler or unable to detect the difference will keep remain & can show an error so that requires handling manually.

Share
How to save data to PList files in iOS

How to save data to PList files in iOS

While working with iOS Applications there are various ways to store data locally into an app. Such as NSUserdefaults, SQLite database, Plist file, NSKeyArchiever, Core data etc.

A developer can choose any of the medium suitable for the application. It can be measured by the complexity of the data & length of the data. Usually, plist is used for storing flag values or for in-app purchase settings or for storing some of the key settings of the application. This kind of data doesn’t require any complex data structure of any advanced functions.

Plist file doesn’t require to fire any queries nor any complex process for fetching or updating data. So it loads faster than the other data storage options.

That is the reason why its more often used in the game for storing scores, statistics of the game. Implementation is also very easy as just a few lines of code required to set up 2 main functions for handle plist files records. First for reading records, Second for writing records.

Here are few easy steps with a graphical representation for creating, reading & writing plist file.

Create New plist file :

Right click on projects & click create new file

From Resources select property list & name it as you want (For ex: mySettings.plist).

Set up prefix value into plist :

You can store anything type of variable like Dictionary, Array, Strings to the plist. Note that the root type will remain NSDictionary always. Lets say we have to store string value inside plist file.

So here i am storing string value by setting up prefix value to 0. We can store & manage multiple strings, arrays & dictionary values inside same plist file.

Writing value to plist file:

-(void)doWriteSettingFilePlist {
NSError *error;
NSString *path = [documentsDirectory stringByAppendingPathComponent:@”SettingFile.plist”];
NSFileManager *fileManager = [NSFileManager defaultManager];
// if File not exist at the same path
if (![fileManager fileExistsAtPath: path]) {
NSString *bundle = [[NSBundle mainBundle] pathForResource:@”SettingFile” ofType:@”plist”];
[fileManager copyItemAtPath:bundle toPath: path error:&error];
}
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
[data setObject:self.strProVersion forKey:@”proversion”];
[data writeToFile:path atomically:YES];
}

Reading from plist file :

-(void)doReadSettingFilePlist {
NSError *error;
NSString *path = [documentsDirectory stringByAppendingPathComponent:@”SettingFile.plist”];
NSFileManager *fileManager = [NSFileManager defaultManager];
// if File not exist at the same path
if (![fileManager fileExistsAtPath: path]) {
NSString *bundle = [[NSBundle mainBundle] pathForResource:@”SettingFile” ofType:@”plist”];
[fileManager copyItemAtPath:bundle toPath: path error:&error];
}
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
self.strProVersion = [data valueForKey:@”proversion”];
}

Notes :

Plist is more faster in terms of fetching data & handle small amount of records. Although its no recommended for use in high level database records storage where more complex operations are requires to handle. One more drawback is plist doesn’t provide update functions like SQLite does. Its just simply overwrites the data.

Overall its still useful feature for handling default app settings of the app like flag values sound, inApp purchase properties etc. with less coding & less efforts & minimum compilation time.

Share
Set up UILocalNotification in iOS Swift/Objective C

Set up UILocalNotification in iOS Swift/Objective C

 

UILocalNotification helps to schedule specific notification for the user on specific date & time. As the name suggests that its handled & called from inside the application locally. So it can work without internet connection.

Its used in an application for various purpose like :

  • Keeping user active into application & make sure app usage increases
  • Notify for some reminders in the application
  • Used as a reminder feature inside the application
  • Keep highlighting for the features inside the application
  • Daily usage reminder for the application

So here is the tutorial about how we can create a UILocalNotification & manage it.

Objective C :

 

Create new notification :

-(void)doCreateLocalNotification {

NSDate *now = [NSDate date];

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:now];

[components setHour:18];

[components setMinute:1];

[components setSecond:10];

NSDate *firedate = [calendar dateFromComponents:components];

UILocalNotification *notification = [[UILocalNotification alloc] init];

notification.fireDate = firedate;

notification.alertBody = @”Hey how are you ? Have you used application today ?”;

notification.repeatInterval = NSCalendarUnitDay;

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

}

Destry all local notifications :

-(void)doDestryNotification {

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];

[[UIApplication sharedApplication] cancelAllLocalNotifications];

}

Read more: Healthy iOS Development Tips & Tricks

Swift :

 

Create new notification :

func doCreateReminder() {

let dateToFire = NSDate().addingTimeInterval(60*60*24*7)

let notification = UILocalNotification()

notification.fireDate = dateToFire as Date

notification.alertBody = NSLocalizedString(“localalert”, comment: “”)

let dict:NSDictionary = [“type” : “reminder”]

notification.userInfo = dict as! [String : String]

notification.repeatInterval = NSCalendar.Unit(rawValue: UInt(0))

notification.soundName = UILocalNotificationDefaultSoundName

UIApplication.shared.scheduleLocalNotification(notification)

}

Destry all local notifications :

func doDestryAllNotification() {

UIApplication.shared.applicationIconBadgeNumber = 0

UIApplication.shared.cancelAllLocalNotifications()

}

 


Tags: iOS, iOS app, iOS Application Development Services, iPhone Application Development Company, Mobile Apps Development, Update
Share
Important Tips to Test iPhone Application

Important Tips to Test iPhone Application

This blog will help you out to improve your professional testing ability as a mobile application tester.

Even if you are not a professional tester & working as a developer but you want to make sure the test beta released by you does not come back with bunch of bugs & issues list than you can refer this blog & it will help you out to improve your application testing skills & eventually it will help you out to make bug free & seamless mobile experience.

Usually, this happens when tester reports any bug on application but does not provide required enough information to the developer & as result developers are not been able to detect the bug & that creates a communication gap.

So to overcome this issue here are few points that need to be in consideration while testing iOS Application.

Do always provide crash logs :

  • This is the very basic & initial step that every iOS Application tester should follow is while reporting bugs they must provide it with the crash logs.
  • In iPhone settings, it automatically stores crash logs of the application. Through that crash logs, a developer can easily detect the lines of code which causes the crash
  • To find the crash logs go to Settings -> Privacy -> Diagnostics & Usage -> Diagnostics & Usage Data. You will find a list of logs there & the recent log will be on the top sorted by the application name.
  • You can retrieve this log file by connecting your device with the computer & sync with iTunes

Do test under limited memory availability on a device :

  • To perform such testing you can test on the devices with lowest configurations or you can create such environment by increasing the usage on the device. For that, you can open all of the applications on the device & also use browser of the device & open few tabs with a couple of websites open
  • So that will consume the memory of device & that will create an environment for you to better test application on such environment
  • This will allow you to check how an application performs on lower memory conditions & in case of low memory availability it gives appropriate messages or throws exceptions

Data inputs testing :

  • In application, if you find a form fill up the view that has more chances of bugs, glitches. So try to products the bug on the page
  • Try by adding inputs that are out of bound & doesn’t suit that field. That will discover if any validation missed placing
  • Try out if keyboard return key works correctly while filling up form & also it scroll correctly & text area scrolls to top exactly over keyboard area while adding input

Test under lower internet connectivity :

  • Developers often do testing on simulators where the get the direct internet usage through ethernet connection & that’s why it loads data more faster
  • But using the same application on a device with limited speed is a slightly different scenario
  • Make sure all of the users wouldn’t have high-speed connections. So if application mostly depends on the server data then try to check how much loading time is & proper caching mechanism used in the application or not
  • To test that cache are enables or not you can try loading data again & again by killing the application in the background. You will notice that the time taken for loading the data is less in the second time then it took in the first time. That indicates that application using proper caching protocols.

Offline testing :

  • For the web server based application it requires necessary to do offline testing. Install first application & then drop the internet connectivity & see how the application behaves. Does it provides appropriate messages in case of no data availability or generates any crash issues?
  • Now do a similar process with a reinstall application load the web-based data for the first time & then turn off the internet connection & see if it loads offline stored data or cached data or it loads nothing.

Read More: Healthy iOS Development Tips & Tricks

 

Asynchronous data loading :

  • In iOS, it offers a feature for loading data asynchronous. That means it will not block the main thread & whatever data is loaded will appear & makes the application run smoothly.
  • This requires checking specifically where the data loaded from the web server & also the case where a large number of data loading it should not stuck whole application & wait until all data loads.

 

Memory level warnings :

  • This is the major point & requires to do hard testing of an application more preferably in a debugging mode.
  • For that, you will need to directly run an application to the device in a debugging mode
  • Once its installed try to do hard testing of an application by doing fast navigations to the pages & if any view contains scrolling with large data records than try to scroll up & down continuously for at least 60 seconds. If the application will have proper memory releasing techniques used then it will not get crashed
  • Otherwise, it will start giving memory level 0-1 warnings in just a few seconds of scrolling. That indicates or application CPU usage time & memory usage is very high & application can exit at any stage

 

Always prefer device testing :

  • Its more preferred that you do testing on every available device on which your application is compatible with.
  • Well, it’s not possible though to test on all devices but do at least test on the device you have available.
  • The reason why is few of the issues which not detects on the simulators but it can products a crash on a device.
  • Like if you have an image used in the application wrongly named or capitalized it will work fine on simulators but it will create an issue on a device. There are lots more such points that can only be tested on the device.

 

Test application on 64-bit devices :

  • It’s important to check if your application supports arm 64 supported devices or not. Now as per apple new rules all application is 64 bit compatible only will be allowed to upload to the store otherwise it will give error message while uploading on the store
  • But there are few applications still on the store which is never updated after its deployed on the store. So that not contains a 64-bit support

 

Conclusion :

Bugs & glitches free application easily get acceptance on the app store & it also increases the application engagement.

As every user when downloads the application they expect to application works at least without any bugs. So if a user gets it they will also appreciate it & more usage of the application by them will improve the over all ranking of the application.

This can only be achieved by the coordination between developers & testers.

Share
Share