Posts

Showing posts with the label iOS

iOS Split Video into frames

Dear all, You may have encountered scenarios where you would like to split a video into several frames at different time intervals. This post is for you if you intend to do the splitting at device level. I presume that you have some reasonable experience with Objective C and XCode such as adding a framework and adding a file. There are several steps to do to get this going. 1. Build an XCode project and add a video file to project. I've worked with .mp4 files. Should work with other standard formats. 2. Add AssetsLibrary framework and AVFoundation frameworks to your project 3. Create a AVAsset object with your video. You need to pass the location of the video as a NSURL object. I added the video(myvid.mp4) as an asset to my project. Therefore, I will use the following method to create the asset object. AVAsset *asset=[AVAsset assetWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"myvid" ofType:@"mp4"]]]; NOTE: If you ne...

XCode importing a file to whole project

Hi, Sometimes you may encounter situations where you have a file which is used frequently throughout the XCode project. This may be a configurations file which is used in 80% of your code files. Importing this in each file is a certain possibility(and the very normal way with no issues), but if you are lazy and just want to add it in one place, this is the post for you. If you analyze the project, there is a file named <project-name>.pch. There is a block of code which has the following. #ifdef __OBJC__     #import < UIKit/UIKit.h>     #import < Foundation/Foundation.h> #endif NOTE: As you can see, UIKit is already added and so is the Foundation framework. That is why you can use classes such as "UIView" or "NSArray" without any additional imports in your code file. That's just an extra bit of info for the curious !!!. So, likewise, we can add our commonly used file into that block as well in the following manner. #i...

iOS Convert Seconds into hours,minutes and seconds

Hi all, In building iPhone applications you may have come across situations that you count some time in seconds, but wish to let the user view it in a more readable format such as 1 hour 38 minutes and 44 seconds. Here is a piece of code that I wrote if you need to get this done in your code. - ( NSString *)timeFormatted:( int )totalSeconds {     int seconds = totalSeconds % 60 ;     int minutes = (totalSeconds / 60 ) % 60 ;     int hours = totalSeconds / 3600 ;         NSString *timeString =@"";     NSString *formatString=@"";     if(hours > 0){         formatString=hours==1?@"%d hour":@"%d hours";         timeString = [timeString stringByAppendingString:[NSString stringWithFormat:formatString,hours]];     }     if(minutes > 0 || hours > 0 ){         formatString=minutes==1?@" %d minute...

iPhone manually set Cookies

Hi guys !!! You may have encountered situations where you wish to set some cookies through your app code. There is a very basic procedure to do it. 1. Create a dictionary with all the cookie properties 2. Create a Cookie passing the property dictionary which you created 3. Set the Cookie using the NSHTTPCookieStorage class First create a properties dictionary. NSDictionary *propertiesUsername = [ NSDictionary dictionaryWithObjectsAndKeys :                                         @".yourdomain.com" , NSHTTPCookieDomain ,                                         @"cookie_name" , NSHTTPCookieName ,                                         @"cookie_value" , NSHTTPCo...