Monday, June 9, 2014

Cookie setting in iPhone

-(void) setCookie:(NSString *)cookieName:(NSString *)cookieValue:(NSString *)cookieDomain
{
    NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
                                cookieDomain, NSHTTPCookieDomain,
                                cookieName, NSHTTPCookieName,
                                cookieValue, NSHTTPCookieValue,
                                @"/", NSHTTPCookiePath,
                                nil];
 
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:[NSHTTPCookie cookieWithProperties:properties]];
}



NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://aaaa.com"]
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                                       timeoutInterval:10];

    [self setCookie:@"sessionid" :@"5b0bdfa53414487c537cc05205f3c663" :@"www.aaaa.com"];
    [urlRequest setHTTPMethod: @"GET"];
    NSURLResponse * response = nil;
    NSError * error = nil;
    NSData * data = [NSURLConnection sendSynchronousRequest:urlRequest
                                          returningResponse:&response
                                                      error:&error];
    
    if (error == nil)
    {
        // Parse data here
        NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(str);
    }

HTTP connection in iPhone

 NSURLRequest * urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.cogi.com/services/rest/0.0/"]];
    NSURLResponse * response = nil;
    NSError * error = nil;
    NSData * data = [NSURLConnection sendSynchronousRequest:urlRequest
                                          returningResponse:&response
                                                      error:&error];
    
    if (error == nil)
    {
        // Parse data here
        NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(str);

    }

Thursday, May 22, 2014

setting RGB colors in iPhone app



#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]


self.backgroundColor=UIColorFromRGB(0x212221);

Wednesday, May 21, 2014

iphone textfield font size adjustment

CGFloat yourSelectedFontSize = 17.0 ;
    UIFont *yourNewSameStyleFont = [textField.font fontWithSize:yourSelectedFontSize];

    [textField setFont:yourNewSameStyleFont];

Wednesday, May 14, 2014

iphone changing view size on keyboard appearance

NSDictionary* info = [notification userInfo];
       CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKeyCGRectValue].size;
        self.textNoteView.frame = CGRectMake(self.textNoteView.frame.origin.xself.textNoteView.frame.origin.yself.textNoteView.frame.size.widthself.textNoteView.frame.size.height - keyboardSize.height);

Checking orientation in iphone

 UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
    {
       

    }

Thursday, May 8, 2014

Release audio mic or other stuff when iPhone app goes to background keeping them in Background mode in plist

// Tell iOS this as a background task in case we get backgrounded
UIBackgroundTaskIdentifier taskId = [[UIApplication sharedApplication] 
          beginBackgroundTaskWithExpirationHandler:NULL];

//----------------------------------------------
// Perform your  operations here
//----------------------------------------------


// Tell iOS that we are done with stuff that needed to keep going even if backgrounded    
[[UIApplication sharedApplication] endBackgroundTask:taskId];