Skip to main content

Posts

Showing posts from January, 2011

UIWebView: Stop Hyperlinking

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{      if (navigationType == UIWebViewNavigationTypeLinkClicked) {         //[[UIApplication sharedApplication] openURL:request.URL];         // Return false to indicate to the UIWebView to not navigate to the linked target         return FALSE;     }    return YES; }

Draw Line

- ( void ) touchesMoved: ( NSSet * ) touches withEvent: ( UIEvent * ) event {     mouseSwiped = YES ;         UITouch *touch = [ touches anyObject ] ;        CGPoint currentPoint = [ touch locationInView: self .view ] ;     currentPoint.y -= 20 ;             UIGraphicsBeginImageContext ( self .view.frame.size ) ;     [ drawImage.image drawInRect:CGRectMake ( 0 , 0 , self .view.frame.size.width, self .view.frame.size.height ) ] ;     CGContextSetLineCap ( UIGraphicsGetCurrentContext ( ) , kCGLineCapRound ) ;     CGContextSetLineWidth ( UIGraphicsGetCurrentContext ( ) , 5 . 0 ) ;     CGContextSetRGBStrokeColor ( UIGraphicsGetCurrentContext ( ) , 1 . 0 , 0 . 0 , 0 . 0 , 1 . 0 ) ;     CGContextBeginPath ( UIGraphicsGetCurrentContext ( ) ) ;     CGContextMoveToPoint ( UIGraphicsGetCurrentContext ( ) , lastPoint.x, lastPoint.y ) ; ...

Play Audio File in iPhone application

Add the Framwork: AVFoundation.framework AudioToolbox.framework Import : AudioToolbox/AudioToolbox.h AVFoundation/AVFoundation.h +(void) playSound :(NSString *)soundFileName{     NSString *pathForSilentFile = [[NSBundle mainBundle] pathForResource:soundFileName ofType:@"wav"];     NSURL *soundFile = [[NSURL alloc] initFileURLWithPath:pathForSilentFile];     AVAudioPlayer *sPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:NULL];     [soundFile release];     [sPlayer prepareToPlay];     [sPlayer play];    }

Set caller and Selector

-(void)setDelegate:(id)delegateObj selectorObj:(SEL)selectorObj{     caller = delegateObj;     callBackFunction = selectorObj; } -(void)callToSelector{ if([caller respondsToSelector:callBackFunction])         [caller performSelector:callBackFunction withObject:@"TimerCalled"]; }

Push Notification Enable/Disable

UIRemoteNotificationType types = [[ UIApplication sharedApplication ] enabledRemoteNotificationTypes ]; if ( types == UIRemoteNotificationTypeNone )     Supporting Links : http://efreedom.com/Question/1-3872149/iPhone-Sdk-Possible-Use-UISwitch-Enable-Disable-PNS-Push-Notification-Service

Game Center Integrate

http://vivianaranha.com/integrating-apple-gamecenter-to-your-application/ How to add Achievement and Leaderboard: http://translate.google.com/translate?hl=en&sl=zh-CN&tl=en&u=http%3A%2F%2Fbbs.ldci.com.cn%2Fsimple%2F%3Ft16012.html

Load Xib file for the view

NSArray *nibViews=[[NSBundle mainBundle]loadNibNamed:@"TroubleLogin" owner:self options:nil];         UIView *myView=[nibViews objectAtIndex:0];         [myView setFrame:self.bounds];         myView.backgroundColor=[UIColor clearColor];         [self addSubview:myView];

Fetch the contact information from the contact list

http://developer.apple.com/library/ios/#samplecode/QuickContacts/Introduction/Intro.html Get the email id :  ABMultiValueRef emails = (ABMultiValueRef) ABRecordCopyValue(person, kABPersonEmailProperty); NSString *emailID = (NSString *)ABMultiValueCopyValueAtIndex(emails, 0); First name :  (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);

How to Create Binary of the application

Steps : 1. Go to target >> New target >> Static Library Create >> add name"TestLib" 2. New target is visible     Three options     Compile Sources :  Filter with *.m in the application . Drag and drop the .m file in the copy header.   Copy header:                                  I.     Filter with *.h in the application.                                 II.     Drag and drop the .h file in the copy header.                               I...

Combine two binary file into one

# Combine lib files for various platforms into one lipo -create libPseudoFramework dev.a libPseudoFramework sim.a -output libResultBinary.a   Step to Execute the command: Create a folder Put both the binary on that folder Open Termial  Goto that folder Execute the command You will get new binary file   # remove existing product lib file, just in case rm -rf build/${BUILD_STYLE}-iphoneos/libPseudoFramework-${BUILD_STYLE}.a       Help Link For More Detail: http://dev.byteclub.com/blog/1-iphone-sdk/48-how-to-almost-create-your-own-iphone-os-framework

Reflection image Demo

//Yo just pass the label obj to the function this will convert into image and you just transform the image -(UIImage *)grabImageFrom View: (UIView *) viewToGrab {              //UITextView *viewToGrab=[[U ITextView alloc]initWithF rame:self.view. bounds];        UIGraphicsBegin ImageContext(vi ewToGrab.bounds .size);              [[viewToGrab layer] renderInContext :UIGraphicsGetC urrentContext() ];        UIImage *viewImage = UIGraphicsGetIm ageFromCurrentI mageContext();        UIGraphicsEndIm ageContext();        return viewImage; } use this link to reflection on image: http://developer.apple.com/library/ios/#samplecode/Reflection/Listings/MyViewController_m.html#//apple_ref/doc/uid/DTS40008063-MyViewController_m-DontLinkElementID_6 

Current Date-Time

-(void) onTimer:(NSTimer *)timer; { NSDateFormatter *timeFormatter = [[[NSDateFormatter alloc] init] autorelease]; [timeFormatter setDateStyle:NSDateFormatterNoStyle]; [timeFormatter setTimeStyle:NSDateFormatterMediumStyle]; NSDate *stringTime = [NSDate date]; NSString *formattedDateStringTime = [timeFormatter stringFromDate:stringTime]; time.text = formattedDateStringTime; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; NSDate *stringDate = [NSDate date]; NSString *formattedDateStringDate = [dateFormatter stringFromDate:stringDate]; date.text = formattedDateStringDate; } -(void)viewDidLoad; { // Timer [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES]; }

Date difference in Weeks , days, Hrs

@interface NSDateFormatter ( Extras ) + ( NSString *) dateDifferenceStringFromString :( NSString *) dateString                                   withFormat :( NSString *) dateFormat ; @end @implementation NSDateFormatter ( Extras ) + ( NSString *) dateDifferenceStringFromString :( NSString *) dateString                                   withFormat :( NSString *) dateFormat {   NSDateFormatter * dateFormatter = [[ NSDateFormatter alloc ] init ];   [ dateFormatter setFormatterBehavior : NSDateFormatterBehavior10_4 ];   [ dateFormatter setDateFormat : dateFormat ];   NSDate * date = [ dateFormatter dateFromString : dateString ];   [ dateFormatter release ];   NSDate * now = [ NSDate date ];   double time = [ date timeIntervalSinceDate : now ];   tim...

Date difference

-( NSString *) dateDiff :( NSString *) origDate {     NSDateFormatter * df = [[ NSDateFormatter alloc ] init ];     [ df setFormatterBehavior : NSDateFormatterBehavior10_4 ];     [ df setDateFormat :@ "EEE, dd MMM yy HH:mm:ss VVVV" ];     NSDate * convertedDate = [ df dateFromString : origDate ];     [ df release ];     NSDate * todayDate = [ NSDate date ];     double ti = [ convertedDate timeIntervalSinceDate : todayDate ];     ti = ti * - 1 ;     if ( ti < 1 ) {         return @ "never" ;     } else       if ( ti < 60 ) {         return @ "less than a minute ago" ;     } else if ( ti < 3600 ) {         int diff = round ( ti / 60 );         return [ NSString stringWithFormat :@ "%d minutes ago" , diff ];     } else...

GMT to Local & Local to GMT

To convert from a localDate to GMT:   -(NSString *)localToGMT{        NSDate *currDate = [NSDate date];     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];     [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];     NSString *dateString = [dateFormatter stringFromDate:currDate];         NSDate *localDate = [dateFormatter dateFromString:dateString];     NSTimeInterval timeZoneOffset = [[NSTimeZone systemTimeZone] secondsFromGMTForDate:localDate];     NSDate *gmtDate = [localDate dateByAddingTimeInterval:-timeZoneOffset]; // NOTE the "-" sign!     NSString *gmtdateString = [dateFormatter stringFromDate:gmtDate];         [dateFormatter release];     return gmtdateString; } To convert from a GMT date to a localDate: -(NSString *)GMTToLocal:(NSString *)GMTdateStri...