Wednesday, 9 May 2012

Playing the push notification sound file

First we should add the Sound files  to  bundle of the projects.Then we can create payload like this.

{"aps": {"alert": "hi", "sound": "attention.wav"}, "device_tokens": ["1E22FB4E50812D90F85EA9B6E93DB7A90643F09D07A86B0E4FB724CE04735C70"]}

Sound field file name should exist in application's bundle.

Wednesday, 11 April 2012

Address to Latitude and Longitude values, Latitude and Longitude to Address

Converting Address to Latitude and Longitude values:



http://maps.google.com/maps/geo?q=Your Address&output=csv

Converting Latitude and Longitude  to Address:

http://maps.google.com/maps/geo?q=17.499943,78.451407&output=csv





Wednesday, 21 March 2012

Showing UIButton title in multiple lines


myButton.titleLabel.textAlignment = UITextAlignmentCenter;
myButton.titleLabel.lineBreakMode = UILineBreakModeCharacterWrap;
[myButton setTitle:@"Please\nTouch" forState:UIControlStateNormal];

Tuesday, 20 March 2012

Custom animation while push view controller


    CATransition* transition = [CATransition animation];
    transition.duration = 0.6;
    transition.type = kCATransitionFade;
    transition.subtype = kCATransitionFade;
    [self.navigationController.view.layer addAnimation:transition
                                                forKey:kCATransition];
    MenuViewContoller *postingVC = [[MenuViewContoller alloc] init];
    [self.navigationController pushViewController:postingVC animated:NO];
    [postingVC release];

Friday, 9 March 2012

SMTP custom message formate


        NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/html",kSKPSMTPPartContentTypeKey,
                                   [NSString stringWithFormat:@"<h1>Ask Us</h1><h2>Get the Answers You Need Now!</h2><b>Thank you for giving us your review</b><br/>"]
                                   ,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

        test_smtp_message.parts = [NSArray arrayWithObjects:plainPart, nil]; //vcfPart
        [test_smtp_message send];

Sunday, 4 March 2012

Solving Time Difference problem with GMT


                    NSDate *resultDate = [format dateFromString:strDate];

                    NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
                    NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
                    
                    NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:resultDate];
                    NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:resultDate];
                    NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
                    
                    NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:resultDate] autorelease];
                    [format setDateFormat:@"MMM dd yyyy, HH:mm"];
                    NSString *strResultDate = [format stringFromDate:destinationDate];

Wednesday, 29 February 2012

iPhone Development Tutorials for Beginners

I am posting in my blog new tutorials for beginners who are going to start iPhone developement.
https://github.com/gopinathdev/iPhone-Development-Tutorials

Keep visiting i will post new tutorials ..

Setting Image for TabBar


UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg"] 
    resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage:
        [UIImage imageNamed:@"tab_select_indicator"]];

Setting Image for NavigationBar


UIImage *gradientImage44 = [[UIImage imageNamed:@"surf_gradient_textured_44"] 
        resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

[[UINavigationBar appearance] setBackgroundImage:gradientImage44 
        forBarMetrics:UIBarMetricsDefault];

Adding Image to UIView with out UIImageView


Setting the Image to UIView with out UIImageView.   
[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_sand"]]];    

Show or Hide StatusBar

In Application's Resource  folder have app-info.plist file, set the
property Status bar is initially hidden make yes/no.

Changing status bar style


In AppDelegate's "didFinishLaunchingWithOptions" method we can usually set this method for status bar visibulity.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];

Monday, 27 February 2012

Solving Webview bounces problem


for (id subview in webView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;

Reading Text fille content from Application Bundle



NSString *filePath = [[NSBundle mainBundle] pathForResource:@"EAP" ofType:@"txt"];

NSString *strData = [[NSString alloc] initWithContentsOfFile:filePath];
NSLog(@"Info :%@",strData);

Friday, 24 February 2012

TBXML Parser Sample

TBXML is the best XML parser with memory and performance aspectives.You can download sample source at https://github.com/gopinathdev/TBXML-Parser 

Lazy Loading sample

Best sample for lazy loading for images in Table View. If you want more details with source code visit at https://github.com/gopinathdev/lazyload

Objective-C XML Parsers


Before we begin, I wanted to make sure everyone is aware of the most important difference between XML parsers: whether the parser is a SAX or a DOM parser.
  • SAX parser is one where your code is notified as the parser walks through the XML tree, and you are responsible for keeping track of state and constructing any objects you might want to keep track of the data as the parser marches through.
  • A DOM parser reads the entire document and builds up an in-memory representation that you can query for different elements. Often, you can even construct XPath queries to pull out particular pieces.
TBXML is the best one parsers avialble in Objective C with performance and memory prospectives.

Monday, 20 February 2012

Synchronous and Asynchronous Request Processing


Synchronous Request Handling:
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost/json"]];
NSURLResponse *response = nil;
NSError *error = nil;
//getting the data
NSData *newData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//json parse
NSString *responseString = [[NSString alloc] initWithData:newData encoding:NSUTF8StringEncoding];
NSDictionary *jsonObject = [responseString JSONValue];
//Accessing JSON content
NSLog(@"type :  %@", [jsonObject objectForKey:@"Type"] );
Some explanations :
response is the url response for the json call
error is error returned by NSURLConnection
newData is data returned by the server
Notice that you can cast the JSON deserialized data into a NSDictionnary or anNSMutuableArray.

Asynchronous Request Handling:
To make an Asynchronous call we’ll need to use NSURLConnection withinitWithRequest method, then we need to implement differents other methods to handle the finish of data loading, error handling etc.
//in the viewDidLoad
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost/json"]];//asynchronous call
[[NSURLConnection alloc] initWithRequest:request delegate:self];
Implementing delegate methods :
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"%@", error);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    [responseData release];
    NSDictionary *jsonObject = [responseString JSONValue];
    NSLog(@"type :  %@", [jsonObject objectForKey:@"Type"] );
    [connection release];
}