Friday, 16 September 2016

Add Prefix Header In Application

Add Prefix Header In Application





Go to New File > iOS > Other > PCH File

Name : - YorAppName-prefix


Then Add Framework Which You Need for Example :-


#ifndef MyDemoApp_prefix_pch
#define MyDemoApp_prefix_pch


#endif /* MyDemoApp_prefix_pch */


#import <Availability.h>

#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "Constant.h"
#import "AppDelegate.h"
#endif


Then Add It in Setting Given Below :-


Add Name : - $(SRCROOT)/MyDemoApp-prefix.pch








Wednesday, 7 September 2016

Custom Map Annotation Pin View

Custom Map Annotation Pin View




//Just add this two methods...

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView*)view{
    
    UIImageView * myView = [[UIImageView allocinit];//(CGRectMake(-110, -72, 260, 80))
    myView.image = [UIImage imageNamed:@"2xLocatioPopUp.png"];//[UIColor blackColor];
    //myView.alpha = 0.4;
    //myView.layer.cornerRadius = 5.0;
    //[myView sizeToFit];
    [view addSubview:myView];

    UITextView * titleLabel = [[UITextView allocinitWithFrame:(CGRectMake(-1050250,0))];//(CGRectMake(-105, -72, 250, 60))
    titleLabel.text = @"You are Here";
    titleLabel.editable = FALSE;
    titleLabel.selectable = FALSE;
    titleLabel.scrollEnabled = FALSE;
    titleLabel.font = [UIFont systemFontOfSize:17.0];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel = [Utility setTextViewFrame:titleLabel fontSize:19.0];
    
    CGFloat height = titleLabel.frame.size.height;
    NSLog(@"%f",height);
    
    if (height < 30.0) {
        height = 30.0;
    }
    titleLabel.frame = CGRectMake(-105, -35 - height, 250, height);
    
    //MKAnnotationView * annotationView = [[MKAnnotationView alloc] init];
    
    myView.frame = CGRectMake(-110, titleLabel.frame.origin.y260, height + 45);

    [view addSubview:titleLabel];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
    
    static NSString *reuseId = @"ann";
    MKAnnotationView *av = [mapViewdequeueReusableAnnotationViewWithIdentifier:reuseId];
    if (av == nil)
    {
        av = [[MKAnnotationView allocinitWithAnnotation:annotationreuseIdentifier:reuseId];
    }
    else
    {
        av.annotation = eventPoint;
    }
    //av.frame = CGRectMake(av.frame.origin.x, av.frame.origin.y, 30, 30);
    av.image = [UIImage imageNamed:@"map_pin_OG_512x512.png"];

    return av;


}









 



Get Path & Navigation in Google Map

Get Path & Navigation in Google Map



Write Code in info.plist :-

:- For Get Current Location permit :-

<key>NSLocationWhenInUseUsageDescription</key>
    <string>This Application requires location service to work</string>

:- For Google Map Application :-

 <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>comgooglemaps</string>
    </array>

Write Method in Class :-

-(void)GetNavigation
{
    
    float lat_dest1 = [strLatitude floatValue];
    float lng_dest1 = [strLongitude floatValue];
    
    if ([[UIApplication sharedApplicationcanOpenURL:[NSURLURLWithString:@"comgooglemaps://"]])
    {
    
        CLLocationCoordinate2D start = { (locationmanager.location.coordinate.latitude), (locationmanager.location.coordinate.longitude) };
        CLLocationCoordinate2D end = { (lat_dest1), (lng_dest1) };
    
        NSString *googleMapsURLString = [NSStringstringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f", start.latitude, start.longitude, end.latitude, end.longitude];
    
        [[UIApplication sharedApplicationopenURL:[NSURLURLWithString:googleMapsURLString]];

    }
    else
    {
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Sorry !!"message:@"First Install Google map" preferredStyle:UIAlertControllerStyleAlert];
        
        
        UIAlertAction* yesButton = [UIAlertAction
                                    actionWithTitle:@"OK"
                                    style:UIAlertActionStyleDefault
                                    handler:^(UIAlertAction * action)
                                    {
                                        //Handel your yes please button action here
                                        
                                        
                                    }];
        [alert addAction:yesButton];
        [self presentViewController:alert animated:YES completion:nil];
    }
}






Set Tabbar at Anywhere (Programatically)

Set Tabbar at Anywhere (Programatically)



#import "firstView.h"
#import "SecView.h"
#import "ThirdView.h"

#import "FourthView.h"




-(IBAction)tabbar_Click:(id)sender
{
    firstView *tocViewController = [[firstView allocinitWithNibName:@"firstView"bundle:nil];
    
    SecView *bookmarkViewController = [[SecView allocinitWithNibName:@"SecView"bundle:nil];
    
    ThirdView *searchViewController = [[ThirdView allocinitWithNibName:@"ThirdView"bundle:nil];
    
    FourthView *aboutUsViewController = [[FourthView alloc]initWithNibName:@"FourthView" bundle:nil];
    
    UINavigationController *tocNavigationController = [[UINavigationController alloc]initWithRootViewController:tocViewController];
    UINavigationController *bookmarkNavigationController = [[UINavigationControllerallocinitWithRootViewController:bookmarkViewController];
    UINavigationController *searchNavigationController = [[UINavigationController alloc]initWithRootViewController:searchViewController];
    UINavigationController *aboutUsNavigationController = [[UINavigationControllerallocinitWithRootViewController:aboutUsViewController];
    
    
    [tocNavigationController.tabBarItem setImage:[UIImage imageNamed:@"data.png"]];
    [bookmarkNavigationController.tabBarItem setImage:[UIImageimageNamed:@"bookmark.png"]];
    [searchNavigationController.tabBarItem setImage:[UIImageimageNamed:@"search.png"]];
    [aboutUsNavigationController.tabBarItem setImage:[UIImageimageNamed:@"info.png"]];
    
    [tocNavigationController.tabBarItem setSelectedImage:[UIImageimageNamed:@"data1.png"]];
    [bookmarkNavigationController.tabBarItem setSelectedImage:[UIImageimageNamed:@"bookmark1.png"]];
    [searchNavigationController.tabBarItem setSelectedImage:[UIImageimageNamed:@"search1.png"]];
    [aboutUsNavigationController.tabBarItem setSelectedImage:[UIImageimageNamed:@"info1.png"]];
    
    [tocNavigationController.tabBarItem setTitle:@"Data"];
    [bookmarkNavigationController.tabBarItem setTitle:@"Bookmarks"];
    [searchNavigationController.tabBarItem setTitle:@"Search"];
    [aboutUsNavigationController.tabBarItem setTitle:@"About Us"];
    
    
    [tocNavigationController.tabBarItem setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:
                                                                [UIColor blackColor],NSForegroundColorAttributeName,
                                                                [UIFont boldSystemFontOfSize:12.0],NSFontAttributeNamenil]
                                                      forState:UIControlStateNormal];
    
    [bookmarkNavigationController.tabBarItem setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:
                                                                [UIColor blackColor],NSForegroundColorAttributeName,
                                                                [UIFont boldSystemFontOfSize:12.0],NSFontAttributeNamenil]
                                                      forState:UIControlStateNormal];
    
    [searchNavigationController.tabBarItem setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:
                                                                [UIColor blackColor],NSForegroundColorAttributeName,
                                                                [UIFont boldSystemFontOfSize:12.0],NSFontAttributeNamenil]
                                                      forState:UIControlStateNormal];
    
    [aboutUsNavigationController.tabBarItem setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:
                                                                [UIColor blackColor],NSForegroundColorAttributeName,
                                                                [UIFont boldSystemFontOfSize:12.0],NSFontAttributeNamenil]
                                                      forState:UIControlStateNormal];
    
   


    UITabBarController *tabBarController = [[UITabBarController allocinit];
    [tabBarController setViewControllers:[NSArrayarrayWithObjects:tocNavigationController,bookmarkNavigationController,searchNavigationController,aboutUsNavigationController, nil]];

    UIImage* tabBarBackground = [UIImage imageNamed:@"TabBar-iPhone.png"];
        
    [[UITabBar appearancesetBackgroundImage:tabBarBackground];
    
    tabBarController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    
    
    [self presentModalViewController:tabBarController animated:YES];
    

}

Saturday, 3 September 2016

Sharing data between iOS apps !

Sharing data between iOS apps !



Settings for project : 
  1. Add the Security.framework to your project.
  2. Download  -->     UICKeyChainStore        and add the UICKeyChainStore.hand UICKeyChainStore.m files from Lib folder to your project.
  3. Go to Target -> Capabilities -> Keychain Sharing. By default it is off. On this option.
  4. As you will on it, a file name projectName.entitlements will add in your "Project Navigator", with key "Keychain Access Groups" of type "Array" with one "Item" of type "String" and Value "$(AppIdentifierPrefix)$(CFBundleIdentifier)". For example com.my.firstApp is the Bundle identifier then Value will be "$(AppIdentifierPrefix)com.my.firstApp". It will look like this : 



Now all you need to do is start using the UICKeyChainStore and you'll be saving data to the KeyChain.

Now, in your class import "UICKeyChainStore.h" and write the following code: 

[UICKeyChainStore setString:@"mySecretPassword" forKey:@"password" service:@"MyService"];

[UICKeyChainStore stringForKey:@"password" service:@"MyService"];

Specifying the service allows you to store keys for a particular service, maybe you have a Twitter or Facebook specific set of keys you wish to save.

As you can see we are not specifying the accessGroup. By default it will pick the first access-group specified in your projectName.entitlements when writing and will search across all access-groups when none is specified.

Allowing your second app to access your shared keychain data:

Settings for project : 
  1. Repeat above steps from 1 to 3 (for firstApp). It will look like this : 



We want access to the Keychain group $(AppIdentifierPrefix)com.my.firstApp for reading, but we still want the default writing to occur in our own keychain group so we still specify $(AppIdentifierPrefix)com.my.secondApp as the first / default group. Add one more item in "Keychain Access Groups" with Value $(AppIdentifierPrefix)com.my.firstApp

It will look like this: 


Now, read the value from the shared Keychain exactly how we did in our first app.

In your class import "UICKeyChainStore.h" and write the following code: 

[UICKeyChainStore stringForKey:@"password" service:@"MyService"];

This should return the value “mySecretPassword” :)


Happy Coding :)