Posts

IOS How to open pdf file using UIWebView

If you are trying to display a PDF file residing on a server somewhere, you can simple load it to your web view directly UIWebView * webView = [[ UIWebView alloc ] initWithFrame : CGRectMake ( 10 , 10 , 200 , 200 )]; NSURL * targetURL = [ NSURL URLWithString :@ "http://developer.apple.com/iphone/library/ documentation/UIKit/Reference/UIWebView_Class/UIWebView_Class.pdf" ]; NSURLRequest * request = [ NSURLRequest requestWithURL : targetURL ]; [ webView loadRequest : request ]; [ self . view addSubview : webView ]; [ webView release ];  Or if you have a PDF file bundled with your application UIWebView * webView = [[ UIWebView alloc ] initWithFrame : CGRectMake ( 10 , 10 , 200 , 200 )]; NSString * path = [[ NSBundle mainBundle ] pathForResource :@ "document" ofType :@ "pdf" ]; NSURL * targetURL = [ NSURL fileURLWithPath : path ]; NSURLRequest * request = [ NSURLRequest requestWithURL : targetURL ]; [ ...

IOS How to get current timeinterval

NSTimeInterval _timeNowInterval = [[NSDate date] timeIntervalSince1970];

IOS How to convert date to GMT

NSDateFormatter * dateFormatter = [[ NSDateFormatter alloc ] init ]; dateFormatter . dateFormat = @ "yyyy-MM-dd'T'HH:mm" ; NSTimeZone * gmt = [ NSTimeZone timeZoneWithAbbreviation :@ "GMT" ]; [ dateFormatter setTimeZone : gmt ]; NSString * timeStamp = [ dateFormatter stringFromDate :[ NSDate date ]]; [ dateFormatter release ];

IOS How to convert from GMT to Local Time

NSDateFormatter * dateFormatter = [[ NSDateFormatter alloc ] init ]; dateFormatter . dateFormat = @ "yyyy-MM-dd'T'HH:mm" ; NSTimeZone * gmt = [ NSTimeZone timeZoneWithAbbreviation :@ "GMT" ]; [ dateFormatter setTimeZone : gmt ]; NSString * timeStamp = [ dateFormatter stringFromDate :[ NSDate date ]]; [ dateFormatter release ];

IOS How to keep audio of video with VideoComposition

/* Recreate audio  */     NSArray *allAudio = [videoAsset tracksWithMediaType:AVMediaTypeAudio];     for (int i=0; i < [allAudio count]; i++) {               NSError* error = NULL;               AVAssetTrack *audioAsset = (AVAssetTrack*)[allAudio objectAtIndex:i];                AVMutableCompositionTrack *compositionAudioTrack = [videoComposition  addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];                     [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,videoAsset.duration)                  ...

IOS How to make beep sound

+ (void) beep {     AudioServicesPlaySystemSound(1005); }

IOS How to convert resize and quanlity movie

/* Convert resize and quanlity movie */ + (void) resizeVideo:(NSString*)inputVideo output:(NSString*) outputVideo size:(CGSize) size bitsPerPixel:(float) bitsPerPixel {     NSAutoreleasePool *pools = [[NSAutoreleasePool alloc] init];     NSURL *outPath = [NSURL fileURLWithPath:outputVideo];     NSURL *inputPath = [NSURL fileURLWithPath:inputVideo];     NSError *error = nil;        AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:outPath fileType:AVFileTypeQuickTimeMovie error:&error];     NSParameterAssert(videoWriter);     AVAsset *avAsset = [[[AVURLAsset alloc] initWithURL:inputPath options:nil] autorelease];         int numPixels = size.width * size.height;     NSLog(@"bitsPerPixel:%f",bitsPerPixel);     int bitsPerSecond = numPixels * bitsPerPixel;      ...