Tuesday, July 24, 2012

how to make phone call by using objective c?


UIDevice *device = [UIDevice currentDevice];
if ([[device model] isEqualToString:@"iPhone"] ) {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:130-032-2837"]]];
} else {
    UIAlertView *Notpermitted=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [Notpermitted show];
    [Notpermitted release];
}

Thursday, July 12, 2012

fetch contact list from iPhone and send in JSON format



-(void)showPeoplePickerController
{
    
    ABAddressBookRef addressBook = ABAddressBookCreate();
    
    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
    CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
    [menuArray removeAllObjects];
    if(menuArray ==nil)
        menuArray = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < nPeople; i++) 
    {
        NSMutableDictionary *localDic=[[NSMutableDictionary alloc]init];
        ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
        
        //get firstname
        CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
        [localDic setObject:[NSString stringWithFormat:@"%@",firstName] forKey:@"first_name"];
        
        //get lastname
        CFStringRef lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
        [localDic setObject:[NSString stringWithFormat:@"%@",lastName] forKey:@"last_name"];
        
        
        //get Phonenumber
        ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(ref, kABPersonPhoneProperty);
        CFTypeRef mobileNumber;
        NSString *mobileLabel;
        
        
        for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
            mobileLabel=[NSString stringWithFormat:@"%@",ABMultiValueCopyLabelAtIndex(phoneNumbers,i)];
            
            if([mobileLabel isEqualToString:@"_$!<Mobile>!$_"])
            {
                mobileNumber = ABMultiValueCopyValueAtIndex(phoneNumbers,i);
                [localDic setObject:[NSString stringWithFormat:@"%@",mobileNumber] forKey:@"Phone_Mobile"];
                
            }
            else if([mobileLabel isEqualToString:@"iPhone"])
            {
                mobileNumber = ABMultiValueCopyValueAtIndex(phoneNumbers,i);
                [localDic setObject:[NSString stringWithFormat:@"%@",mobileNumber] forKey:@"Phone_iPhone"];
            }
            else if([mobileLabel isEqualToString:@"_$!<Home>!$_"])
            {
                mobileNumber = ABMultiValueCopyValueAtIndex(phoneNumbers,i);
                [localDic setObject:[NSString stringWithFormat:@"%@",mobileNumber] forKey:@"Phone_Home"];
                
            }
            else if([mobileLabel isEqualToString:@"_$!<Work>!$_"])
            {
                mobileNumber = ABMultiValueCopyValueAtIndex(phoneNumbers,i);
                [localDic setObject:[NSString stringWithFormat:@"%@",mobileNumber] forKey:@"Phone_Work"];
                break;
            }
            
        }
        
        
        
        //get EmailId
        ABMutableMultiValueRef EmailIds = ABRecordCopyValue(ref, kABPersonEmailProperty);
        CFTypeRef EmailId;
        NSString *EmailLabel;
        
        
        for (CFIndex i = 0; i < ABMultiValueGetCount(EmailIds); i++) {
            EmailLabel=[NSString stringWithFormat:@"%@",ABMultiValueCopyLabelAtIndex(EmailIds,i)];
            
            if([EmailLabel isEqualToString:@"_$!<Home>!$_"])
            {
                EmailId = ABMultiValueCopyValueAtIndex(EmailIds,i);
                [localDic setObject:[NSString stringWithFormat:@"%@",EmailId] forKey:@"Email_Home"];
                
            }
            else if([EmailLabel isEqualToString:@"_$!<Work>!$_"])
            {
                EmailId = ABMultiValueCopyValueAtIndex(EmailIds,i);
                [localDic setObject:[NSString stringWithFormat:@"%@",EmailId] forKey:@"Email_Work"];
                break;
            }
        }
        
        
        //get Social Datas..
        ABMultiValueRef SocialProperty = ABRecordCopyValue(ref, kABPersonSocialProfileProperty);
        
        for (CFIndex i = 0; i < ABMultiValueGetCount(SocialProperty); i++) 
        {
            
            CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(SocialProperty, i);
            NSString *service = [NSString stringWithFormat:@"%@",CFDictionaryGetValue(dict, @"service")];
           // NSLog(@"%@",dict);
            if([service isEqualToString:@"twitter"])
                [localDic setObject:[NSString stringWithFormat:@"%@",CFDictionaryGetValue(dict, @"username")] forKey:@"twitter_uname"];
            else if([service isEqualToString:@"facebook"])
                [localDic setObject:[NSString stringWithFormat:@"%@",CFDictionaryGetValue(dict, @"username")] forKey:@"facebook_uname"];
            else if([service isEqualToString:@"flickr"])
                [localDic setObject:[NSString stringWithFormat:@"%@",CFDictionaryGetValue(dict, @"username")] forKey:@"flickr_uname"];
            else if([service isEqualToString:@"linkedin"])
                [localDic setObject:[NSString stringWithFormat:@"%@",CFDictionaryGetValue(dict, @"username")] forKey:@"linkedin_uname"];
            
            CFRelease(dict);
        }
        
        //Get Address Detail Info..
        
        ABMultiValueRef addressProperty = ABRecordCopyValue(ref, kABPersonAddressProperty);
        
        for (CFIndex i = 0; i < ABMultiValueGetCount(addressProperty); i++) 
        {
            
            CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(addressProperty, i);
            
            CFStringRef myCountryCode = CFDictionaryGetValue(dict, kABPersonAddressCountryCodeKey);
            [localDic setObject:[NSString stringWithFormat:@"%@",myCountryCode] forKey:@"Country_Code"];
            
            CFRelease(dict);
        }
        
        [menuArray addObject:localDic];
        [localDic release];
    }
   // NSLog(@"menuArray  %@",menuArray);
    
    NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:menuArray,@"contacts_info", nil];
    NSError *writeError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:&writeError];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
   // NSLog(@"JSON Output: %@", jsonString);
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:@"YOUR REQUEST URL"]];
    //NSLog(@"request..%@",request);
    NSURLConnection *connection = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
    [request release];
    [jsonString release];
    if (connection) {
       // NSLog(@"connection established");
    }
    
}

Call native iPhone code from UIWebView


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
   if ( [request.mainDocumentURL.relativePath isEqualToString:@"/ur function name in HTML page"] ){
return NO;
    }

Detect phone number in webview


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
   
    NSURL *url = request.URL;    
    NSString *numberstr = [url absoluteString];//convert url to string
    NSLog(@"str...%@",numberstr);
    
    
    
    if ([url.scheme isEqualToString:@"tel"]) {
        NSLog(@"request.URL.....%@",request.URL);
     
        
    }

Thursday, March 22, 2012

How to get indexpath of button in a tableView row ?

NSIndexPath *indexPath =[self.YourTable indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
   

Monday, March 19, 2012

Detecting a when a a UIScrollView reaches the bottom.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
 if (scrollView.contentOffset.y == scrollView.contentSize.height - scrollView.frame.size.height) {
 // reached the bottom
 }
}

Tuesday, January 31, 2012

Getting subarray from Array

for (id element in CompleteArray) {
        if([element isKindOfClass:[NSArray class]]){
            NSMutableArray *Arr1 = [NSMutableArray arrayWithArray:element];
           
        }else {
            NSMutableArray *Arr2 = [NSMutableArray alloc]init];
            [Arr2 addObject:element];
           
        }
       
    }