Saturday, 27 January 2018

Google place Autocomplete


#import "AppDelegate.h"
@import GooglePlaces;

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    [GMSPlacesClient provideAPIKey:@"Api Key"];

    return YES;
}


#add this view controller

#import "ViewController.h"
#import "NSString+Extra.h"
#import <GooglePlaces/GooglePlaces.h>

@interface ViewController ()<GMSAutocompleteViewControllerDelegate>
{
    GMSPlacesClient *_placesClient;
    IBOutlet UIButton *btnSearch;
}

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _placesClient = [GMSPlacesClient sharedClient];


}


- (IBAction)getCurrentPlace:(UIButton *)sender {
    GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
    acController.delegate = self;
    [self presentViewController:acController animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
// Handle the user's selection.
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
    [self dismissViewControllerAnimated:YES completion:nil];
    // Do something with the selected place.
    NSLog(@"Place name %@", place.name);
    NSLog(@"Place address %@", place.formattedAddress);
    NSLog(@"Place attributions %@", place.attributions.string);
    [place.attributions.string showAsAlert:self];
}

- (void)viewController:(GMSAutocompleteViewController *)viewController
didFailAutocompleteWithError:(NSError *)error {
    [self dismissViewControllerAnimated:YES completion:nil];
    // TODO: handle the error.
    NSLog(@"Error: %@", [error description]);
}

// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
    [self dismissViewControllerAnimated:YES completion:nil];
}

// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}


// Handle the user's selection.
- (void)resultsController:(GMSAutocompleteResultsViewController *)resultsController
 didAutocompleteWithPlace:(GMSPlace *)place {
    _searchController.active = NO;
    // Do something with the selected place.
    NSLog(@"Place name %@", place.name);
    NSLog(@"Place address %@", place.formattedAddress);
    NSLog(@"Place attributions %@", place.attributions.string);
}

- (void)resultsController:(GMSAutocompleteResultsViewController *)resultsController
didFailAutocompleteWithError:(NSError *)error {
    [self dismissViewControllerAnimated:YES completion:nil];
    // TODO: handle the error.
    NSLog(@"Error: %@", [error description]);
}

// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictionsForResultsController:
(GMSAutocompleteResultsViewController *)resultsController {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

- (void)didUpdateAutocompletePredictionsForResultsController:
(GMSAutocompleteResultsViewController *)resultsController {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

Monday, 22 January 2018

Category and contant file important for project

https://drive.google.com/file/d/1i_R-TGaqzuzWs56hYxPiMb_A1KOxq4qT/view?ts=5a6621db

Friday, 12 January 2018

Alertview controller in full app

Here i will show you how to use import one file use alertview controller in full app
just import this file in your class file (.h or .m) file in your app
#import "NSString+Extra.h"



How to call this alert view controller


[strMessage showAsAlert:self];

strMessage=@"Any message you want to pass".


Download file 

NSString+Extra.h from here --->>>>>>>>>

https://drive.google.com/file/d/1VZqgK-sI7Gdb_iW-AIF4vsek2Dedd55S/view?usp=sharing

Tuesday, 19 December 2017

afnetworking Service call

-(void)Start
{
     NSString *stringURL = [NSString stringWithFormat:@"url"];
    
    NSString* webStringURL = [stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    
    NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"GET" URLString:webStringURL parameters:nil error:nil];
    
    req.timeoutInterval= [[[NSUserDefaults standardUserDefaults] valueForKey:@"timeoutInterval"] longValue];
    [req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [req setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    
    [MBProgressHUD showHUDAddedTo:self.view animated:true];
    
    [[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error)
      {
          if (!error)
          {
              NSLog(@"Reply JSON: %@", responseObject);
              
              if ([responseObject isKindOfClass:[NSArray class]])
              {
                  arrResult=[[NSMutableArray alloc]init];
                  
                  for (NSMutableDictionary *dic in responseObject)
                  {
                      [arrResult addObject:dic];
                  }
                  
                  
              }
          }
          else
          {
              NSLog(@"Error: %@, %@, %@", error, response, responseObject);
          }
      }] resume];

}

Email Id Validation and Mobile Phone Format

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if(textField == txtSignUpMobileNo)
    {
        int length = [self getLength:textField.text];
        //NSLog(@"Length  =  %d ",length);
        
        if(length == 10)
        {
            if(range.length == 0)
                return NO;
        }
        
        if(length == 4)
        {
            NSString *num = [self formatNumber:textField.text];
            textField.text = [NSString stringWithFormat:@"%@ ",num];
            if(range.length > 0)
                textField.text = [NSString stringWithFormat:@"%@",[num substringToIndex:4]];
        }
        else if(length == 7)
        {
            NSString *num = [self formatNumber:textField.text];
            
            //NSLog(@"%@",[num substringToIndex:4]);
            //NSLog(@"%@",[num substringFromIndex:4]);
            
            textField.text = [NSString stringWithFormat:@"%@ %@ ",[num  substringToIndex:4],[num substringFromIndex:4]];
            if(range.length > 0)
                textField.text = [NSString stringWithFormat:@"%@ %@",[num substringToIndex:4],[num substringFromIndex:4]];
        }
        
        return YES;
    }
    else
    {
        NSUInteger newLength = [textField.text length] + [string length] - range.length;
        return (newLength > 50) ? NO : YES;
    }
    
    return YES;
    
}
-(NSString*)formatNumber:(NSString*)mobileNumber
{
    mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"(" withString:@""];
    mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@")" withString:@""];
    mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
    mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"-" withString:@""];
    mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"+" withString:@""];
    
    //NSLog(@"%@", mobileNumber);
    
    int length = (int)[mobileNumber length];
    if(length > 10)
    {
        mobileNumber = [mobileNumber substringFromIndex: length-10];
        //NSLog(@"%@", mobileNumber);
    }
    
    return mobileNumber;
    
}
-(int)getLength:(NSString*)mobileNumber
{
    mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"(" withString:@""];
    mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@")" withString:@""];
    mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
    mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"-" withString:@""];
    mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"+" withString:@""];
    
    int length = (int)[mobileNumber length];
    
    return length;
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self resignKeyboard:0];
    
    [textField resignFirstResponder];
    return YES;
}
- (BOOL)validateEmail:(NSString *)email
{
    //DLog(@"checkEmailString = %@",email);
    BOOL emailFlg = NO;
    NSArray *atArr = [email componentsSeparatedByString:@"@"];
    
    //check with one @
    if ([atArr count] == 2)
    {
        NSArray *dotArr = [atArr[1] componentsSeparatedByString:@"."];
        
        //check with at least one .
        if ([dotArr count] >= 2)
        {
            emailFlg = YES;
            
            //all section can't be
            for (int i = 0; i<[dotArr count]; i++)
            {
                
                if ([dotArr[i] length] == 0 || [dotArr[i] rangeOfString:@" "].location != NSNotFound)
                {
                    emailFlg = NO;
                }
            }
        }
    }
    
    return emailFlg;
    

}

Monday, 18 December 2017

NSURLSessionDataTask and NsUrlSession manager

  @try
    {
        NSString *strurl=[NSString stringWithFormat:@"Url Here",];
        
        NSURL *url=[NSURL URLWithString:strurl];
        
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        
        NSURLSession *session = [NSURLSession sharedSession];
        
        NSURLSessionDataTask *task = [session dataTaskWithRequest:request
                                                completionHandler:
                                      ^(NSData *data, NSURLResponse *response, NSError *error)
                                      {
                                          
                                          // NSError *error;
                                          NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
                                          
                                          arrResult=[[NSMutableArray alloc]init];
                                          
                                          for (NSMutableDictionary *dic in json)
                                          {
                                              [arrResult addObject:dic];
                                          }
                                          if ([arrResult count]>0)
                                          {
                                              [tblView reloadData];
                                              [MBProgressHUD hideHUDForView:self.view animated:YES];
                                          }
                                      }];
        
        [task resume];
        
    }
    @catch (NSException *exception)
    {
        NSString *strError = [NSString stringWithFormat:@"%@",exception];
        
        UIAlertView *validateAlert = [[UIAlertView alloc] initWithTitle:sharvar.strAlertMsgTitle message:strError delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [validateAlert show];

    }

Sunday, 12 June 2016

How to send email in swift

import foundation
import socail
import messaging
let mailComposerVC = MFMailComposeViewController()

mailComposerVC.mailComposeDelegate = self // Extremely important to set the --

mailComposeDelegate-- property, NOT the --delegate--
mailComposerVC.setToRecipients(["someone@somewhere.com"])

mailComposerVC.setSubject("Sending you an in-app e-mail...")

mailComposerVC.setMessageBody("Sending e-mail in-app is not so bad!", isHTML: false) just copy pase this code in button action and and check out put