NSMutableArray *countries = [[ NSMutableArray alloc ] initWithObjects :@"Afghanistan", @"Akrotiri", @"Albania", @"Algeria", @"American Samoa", @"Andorra", @"Angola", @"Anguilla", @"Antarctica", @"Antigua and Barbuda", @"Argentina", @"Armenia", @"Aruba", @"Ashmore and Cartier Islands", @"Australia", @"Austria", @"Azerbaijan", @"The Bahamas", @"Bahrain", @"Bangladesh", @"Barbados", @"Bassas da India", @"Belarus", @"Belgium", @"Belize", @"Benin", @"Bermuda", @"Bhutan", @"Bolivia", @"Bosnia and Herzegovina", @"Botswana", @"Bouvet Island", @"Brazil", @"British Indian Ocean Territory", @"British Virgin Islands", @"Brunei", @"Bulgaria", @"Burkina Faso", @"Burma", @"Burundi", @"Cambodia", @"Cameroon", @"Canada", @"Cape Verde", @"Cayman Islands", @"Central African Republic", @"Chad", @"Chile", @"China", @"Christmas Island", @"Clipperton Island", @"Cocos (Keeling) Islands", @"Colombia", @"Comoros", @"Democratic Republic of the Congo", @"Republic of the Congo", @"Cook Islands", @"Coral Sea Islands", @"Costa Rica", @"Cote d'Ivoire", @"Croatia", @"Cuba", @"Cyprus", @"Czech Republic", @"Denmark", @"Dhekelia", @"Djibouti", @"Dominica", @"Dominican Republic", @"Ecuador", @"Egypt", @"El Salvador", @"Equatorial Guinea", @"Eritrea", @"Estonia", @"Ethiopia", @"Europa Island", @"Falkland Islands (Islas Malvinas)", @"Faroe Islands", @"Fiji", @"Finland", @"France", @"French Guiana", @"French Polynesia", @"French Southern and Antarctic Lands", @"Gabon", @"The Gambia", @"Gaza Strip", @"Georgia", @"Germany", @"Ghana", @"Gibraltar", @"Glorioso Islands", @"Greece", @"Greenland", @"Grenada", @"Guadeloupe", @"Guam", @"Guatemala", @"Guernsey", @"Guinea", @"Guinea-Bissau", @"Guyana", @"Haiti", @"Heard Island and McDonald Islands", @"Holy See (Vatican City)", @"Honduras", @"Hong Kong", @"Hungary", @"Iceland", @"India", @"Indonesia", @"Iran", @"Iraq", @"Ireland", @"Isle of Man", @"Israel", @"Italy", @"Jamaica", @"Jan Mayen", @"Japan", @"Jersey", @"Jordan", @"Juan de Nova Island", @"Kazakhstan", @"Kenya", @"Kiribati", @"North Korea", @"South Korea", @"Kuwait", @"Kyrgyzstan", @"Laos", @"Latvia", @"Lebanon", @"Lesotho", @"Liberia", @"Libya", @"Liechtenstein", @"Lithuania", @"Luxembourg", @"Macau", @"Macedonia", @"Madagascar", @"Malawi", @"Malaysia", @"Maldives", @"Mali", @"Malta", @"Marshall Islands", @"Martinique", @"Mauritania", @"Mauritius", @"Mayotte", @"Mexico", @"Federated States of Micronesia", @"Moldova", @"Monaco", @"Mongolia", @"Montserrat", @"Morocco", @"Mozambique", @"Namibia", @"Nauru", @"Navassa Island", @"Nepal", @"Netherlands", @"Netherlands Antilles", @"New Caledonia", @"New Zealand", @"Nicaragua", @"Niger", @"Nigeria", @"Niue", @"Norfolk Island", @"Northern Mariana Islands", @"Norway", @"Oman", @"Pakistan", @"Palau", @"Panama", @"Papua New Guinea", @"Paracel Islands", @"Paraguay", @"Peru", @"Philippines", @"Pitcairn Islands", @"Poland", @"Portugal", @"Puerto Rico", @"Qatar", @"Reunion", @"Romania", @"Russia", @"Rwanda", @"Saint Helena", @"Saint Kitts and Nevis", @"Saint Lucia", @"Saint Pierre and Miquelon", @"Saint Vincent and the Grenadines", @"Samoa", @"San Marino", @"Sao Tome and Principe", @"Saudi Arabia", @"Senegal", @"Serbia", @"Montenegro", @"Seychelles", @"Sierra Leone", @"Singapore", @"Slovakia", @"Slovenia", @"Solomon Islands", @"Somalia", @"South Africa", @"South Georgia and the South Sandwich Islands", @"Spain", @"Spratly Islands", @"Sri Lanka", @"Sudan", @"Suriname", @"Svalbard", @"Swaziland", @"Sweden", @"Switzerland", @"Syria", @"Taiwan", @"Tajikistan", @"Tanzania", @"Thailand", @"Tibet", @"Timor-Leste", @"Togo", @"Tokelau", @"Tonga", @"Trinidad and Tobago", @"Tromelin Island", @"Tunisia", @"Turkey", @"Turkmenistan", @"Turks and Caicos Islands", @"Tuvalu", @"Uganda", @"Ukraine", @"United Arab Emirates", @"United Kingdom", @"United States", @"Uruguay", @"Uzbekistan", @"Vanuatu", @"Venezuela", @"Vietnam", @"Virgin Islands", @"Wake Island", @"Wallis and Futuna", @"West Bank", @"Western Sahara", @"Yemen", @"Zambia", @"Zimbabwe", nil];
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > All City Of India in Array :-
NSMutableArray * arrForCityName = [[ NSMutableArray alloc ] initWithObjects : @"Adilabad" , @"Agartala" , @"Agra" , @"Ahmedabad" , @"Ahmednagar" , @"Aizawl" , @"Ajmer" , @"Aligarh" , @"Allahabad" , @"Almora" , @"Alwar" , @"Amravati" , @"Amreli" , @"Amritsar" , @"Anakapalle" , @"Anand" , @"Ankleshwar" , @"Arrah" , @"Asansol" , @"Ashok Nagar" , @"Azamgarh" , @"Baharampur" , @"Bahraich" , @"Bhagalpur" , @"Bharuch" , @"Bhavnagar" , @"Bhopal" , @"Bhubaneswar" , @"Bhuj" , @"Chandigarh" , @"Chennai" , @"Cuttack" , @"Dahod" , @"Daman and Diu" , @"Darbhanga" , @"Darjeeling" , @"Dombivli" , @"Faridabad" , @"Firozabad" , @"Gandhinagar" , @"Godhra" , @"Greater Noida" , @"Gurgaon" , @"Guwahati" , @"Haridwar" , @"Himatnagar" , @"Indore" , @"Jabalpur" , @"Jaipur" , @"Jaisalmer" , @"Jalandhar" , @"Jammu" , @"Jamnagar" , @"Jamshedpur" , @"Jhansi" , @"Jodhpur" , @"Kalyan" , @"Kanpur" , @"Kochi" , @"Kolhapur" , @"Kolkata" , @"Lucknow" , @"Madurai" , @"Mangalooru" , @"Mathura" , @"Mumbai" , @"Muzaffarnagar" , @"Nagpur" , @"Nashik" , @"Navi Mumbai" , @"Navsari" , @"New Delhi" , @"Pali" , @"Panipat" , @"Panvel" , @"Pathankot" , @"Patna"@"Pondicherry" , @"Pune" , @"Raipur" , @"Rajkot" , @"Ranchi" , @"Ratlam" , @"Rohtak" , @"Saharanpur" , @"Salem" , @"Shillong" , @"Shimla" , @"Srinagar" , @"Surat" , @"Thiruvananthapuram" , @"Tiruchirappalli" , @"Udaipur" , @"Ujjain" , @"Unnao" , @"Vadodara" , @"Varanasi" , @"Vijayawada" , @"Visakhapatnam" , @"Wadhwan" , nil ];
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Google Support Places in Array :-
NSMutableArray * arrobj = [[ NSMutableArray alloc ] initWithObjects : @"accounting" , @"airport" , @"amusement_park" , @"aquarium" , @"art_gallery" , @"atm" , @"bakery" , @"bank" , @"bar" , @"beauty_salon" , @"bicycle_store" , @"book_store" , @"bowling_alley" , @"bus_station" , @"cafe" , @"campground" , @"car_dealer" , @"car_rental" , @"car_repair" , @"car_wash" , @"casino" , @"cemetery" , @"church" , @"city_hall" , @"clothing_store" , @"convenience_store" , @"courthouse" , @"dentist" , @"department_store" , @"doctor" , @"electrician" , @"electronics_store" , @"embassy" , @"establishment" , @"finance" , @"fire_station" , @"florist" , @"food" , @"funeral_home" , @"furniture_store" , @"gas_station" , @"general_contractor" , @"grocery_or_supermarket" , @"gym" , @"hair_care" , @"hardware_store" , @"health" , @"hindu_temple" , @"home_goods_store" , @"hospital" , @"insurance_agency" , @"jewelry_store" , @"laundry" , @"lawyer" , @"library" , @"liquor_store" , @"local_government_office" , @"locksmith" , @"lodging" , @"meal_delivery" , @"meal_takeaway" , @"mosque" , @"movie_rental" , @"movie_theater" , @"moving_company" , @"museum" , @"night_club" , @"painter" , @"park" , @"parking" , @"pet_store" , @"pharmacy" , @"physiotherapist" , @"place_of_worship" , @"plumber" , @"police" , @"post_office" , @"real_estate_agency" , @"restaurant" , @"roofing_contractor" , @"rv_park" , @"school" , @"shoe_store" , @"shopping_mall" , @"spa" , @"stadium" , @"storage" , @"store" , @"subway_station" , @"synagogue" , @"taxi_stand" , @"train_station" , @"travel_agency" , @"university" , @"veterinary_care" , @"zoo" , nil ];
(Show on View With Capital Text)
NSMutableArray *arrobjdata = [[ NSMutableArray alloc ] initWithObjects : @"Accounting" , @"Airport" , @"Amusement Park" , @"Aquarium" , @"Art Gallery" , @"Atm" , @"Bakery" , @"Bank" , @"Bar" , @"Beauty Salon" , @"Bicycle Store" , @"Book Store" , @"Bowling Alley" , @"Bus Station" , @"Cafe" , @"Campground" , @"Car Dealer" , @"Car Rental" , @"Car Rrepair" , @"Car Wash" , @"Casino" , @"Cemetery" , @"Church" , @"City Hall" , @"Clothing Store" , @"Convenience Store" , @"Courthouse" , @"Dentist" , @"Department Store" , @"Doctor" , @"Electrician" , @"Electronics Store" , @"Embassy" , @"Establishment" , @"Finance" , @"Fire Station" , @"Florist" , @"Food" , @"Funeral Home" , @"Furniture Store" , @"Gas Station" , @"General Contractor" , @"Grocery Or market" , @"Gym" , @"Hair Care" , @"Hardware Store" , @"Health" , @"Hindu Temple" , @"Home Goods Store" , @"Hospital" , @"Insurance Agency" , @"Jewelry Store" , @"Laundry" , @"Lawyer" , @"Library" , @"Liquor Store" , @"Local Government Office" , @"Locksmith" , @"Lodging" , @"Meal Lelivery" , @"Meal Takeaway" , @"Mosque" , @"Movie rental" , @"Movie Theater" , @"Moving Company" , @"Museum" , @"Night Club" , @"Painter" , @"Park" , @"Parking" , @"Pet Store" , @"Pharmacy" , @"Physiotherapist" , @"Place Of Worship" , @"Plumber" , @"Police" , @"Post Office" , @"Real Estate Agency" , @"Restaurant" , @"Roofing Contractor" , @"Rv Park" , @"School" , @"Shoe Store" , @"Shopping Mall" , @"Spa" , @"Stadium" , @"Storage" , @"Store" , @"Subway Station" , @"Synagogue" , @"Taxi Stand" , @"Train Station" , @"Travel Agency" , @"University" , @"Veterinary Care" , @"Zoo" , nil ];
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Push Notification Implementation :-
- ( BOOL )application:( UIApplication *)application didFinishLaunchingWithOptions:( NSDictionary *)launchOptions
{
// **************** Apple Push Integration Starts Here **************** //
// ---------------------------------------------------------------------- //
/// New iOS 8 User Notification Settings
NSDictionary *userInfo = [launchOptions objectForKey : UIApplicationLaunchOptionsRemoteNotificationKey ];
if (userInfo != NULL )
{
[[ UIApplication sharedApplication ] setApplicationIconBadgeNumber : 0 ];
NSString *notification = [[userInfo valueForKey : @"aps" ] valueForKey : @"alert" ];
NSLog ( @"%@" , notification);
}
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([application respondsToSelector : @selector (registerUserNotificationSettings:)])
{
UIUserNotificationType userNotificationTypes = ( UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound );
UIUserNotificationSettings *settings = [ UIUserNotificationSettings settingsForTypes :userNotificationTypes
categories : nil ];
[application registerUserNotificationSettings :settings];
// [application registerForRemoteNotifications];
}
else
#endif
{
// iOS 7
/*
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
*/
}
// ---------------------------------------------------------------------- //
//-------
return YES ;
}
#pragma mark -Push Notification
- ( void )application:( UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:( NSData *)deviceToken
{
NSLog ( @"tk : %@" , deviceToken) ;
}
- ( void )application:( UIApplication *)application didRegisterUserNotificationSettings:( UIUserNotificationSettings *)notificationSettings
{
[application registerForRemoteNotifications ];
}
- ( void )application:( UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:( NSError *)error
{
// NSLog(@"Did Fail to Register for Remote Notifications");
NSLog ( @"%@, %@" , error, error. localizedDescription );
}
- ( void )application:( UIApplication *)application didReceiveRemoteNotification:( NSDictionary *)userInfo
{
[[ UIApplication sharedApplication ] setApplicationIconBadgeNumber : 0 ];
NSString *notification = [[userInfo valueForKey : @"aps" ] valueForKey : @"alert" ];
NSLog ( @"%@" ,notification);
}
//----------------------------------------------- For ios 10 -----------------------------------------------//
//-----------------------------------------------
//-----------------------------------------------
//-----------------------------------------------
For iOS 10 using xCode 8 GM.
1) In the targets, under Capabilities enable Push Notifications to add Push Notifications Entitlements.
2) Implement UserNotifications.framework into your app. Import UserNotifications.framework in your AppDelegate.
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
@end
3) In didFinishLaunchingWithOptions method assign UIUserNotificationSettings and implement UNUserNotificationCenter delegate.
#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if( !error ){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}];
}
return YES;
}
4) Now finally implement this two delegate methods.
//====================For iOS 10====================
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
//Called when a notification is delivered to a foreground app.
NSLog(@"Userinfo %@",notification.request.content.userInfo);
completionHandler(UNNotificationPresentationOptionAlert);
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{
//Called to let your app know which action was selected by the user for a given notification.
NSLog(@"Userinfo %@",response.notification.request.content.userInfo);
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Hide KeyBoard At AnyWhere Touch :-
-( void )touchesBegan:( NSSet *)touches withEvent:( UIEvent *)event
{
[ _txt resignFirstResponder ];
}
-( void )touchesEnded:( NSSet *)touches withEvent:( UIEvent *)event
{
[ _txt resignFirstResponder ];
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Create own json String For Post :-
NSMutableArray *array = [[ NSMutableArray alloc ] init ];
for ( int i = 0 ; i< arrOrganozationName . count ; i++)
{
NSString *dataName = [ arrOrganozationName objectAtIndex :i];
NSString *dataType = [ arrOrganozationType objectAtIndex :i];
NSMutableDictionary *dic = [ NSMutableDictionary dictionaryWithObjectsAndKeys :dataName, @"Name" ,dataType, @"Type" , nil ];
[array addObject :dic];
}
NSMutableDictionary *Dicdata = [ NSMutableDictionary dictionaryWithObjectsAndKeys :array, @"Data" , @"Success" , @"Status" , nil ] ;
NSError *error;
NSData *jsonData2 = [ NSJSONSerialization dataWithJSONObject :Dicdata options : NSJSONWritingPrettyPrinted error :&error];
NSString *jsonString = [[ NSString alloc ] initWithData :jsonData2 encoding : NSUTF8StringEncoding ];
NSLog ( @"jsonData as string:\n%@" , jsonString);
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Get data From json File :-
NSData *data = [ NSData dataWithContentsOfFile :[[ NSBundle mainBundle ] pathForResource : @"countriesToCities" ofType : @"json" ]];
NSDictionary *dictTemp = [ NSJSONSerialization JSONObjectWithData :data options : 0 error : nil ];
NSArray *resultarr = [dictTemp valueForKey : @"India" ];
for ( int i = 0 ; i < resultarr. count ; i++)
{
NSString *strname = [resultarr objectAtIndex :i];
[arrdata addObject :strname];
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Set Array In Ascending Order :-
NSSortDescriptor *descriptor=[[ NSSortDescriptor alloc ] initWithKey : @"self" ascending : YES ];
NSMutableArray *descriptors=[ NSMutableArray arrayWithObject : descriptor];
NSArray *arrForCityName = [arrdata sortedArrayUsingDescriptors :descriptors];
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Data Communication btw Application & Extention :-
set RequestsOpenAccess in plist and at setting->keyboard-customkeyboar->Full Access ON
My extention Plist:
enable app-groups and setting app groupfrom my Xcode project from target-->capability--Expand App Group and by tap on + add app group like following screenshot:
And doing same thing for my keyboard extension target. Then i used this setting app groups identifier in NSuserDefault:
_defaultvalue = [[ NSUserDefaults alloc ] initWithSuiteName :@ "group.keyboaredExtention" ];
[ _defaultvalue setBool : NO forKey :@ "Layout" ];
[ _defaultvalue synchronize ];
Then Access It in Keyboard View :-
-( void ) LoadKeyboardview
{
_defaultvalue = [[ NSUserDefaults alloc ] initWithSuiteName :@ "group.keyboaredExtention " ];
if ([ _defaultvalue boolForKey :@ "Layout" ])
{
self . ObjKeyLayout =[[[ NSBundle mainBundle ] loadNibNamed :@ "keyboardLayout" owner : nil options : nil ] objectAtIndex : 0 ];
[ self addGesturToKeyBoard ];
self . inputView = self . ObjKeyLayout ;
}
else {
self . ObjKeyLayout =[[[ NSBundle mainBundle ] loadNibNamed :@ "leftLayout" owner : nil options : nil ] objectAtIndex : 0 ];
[ self addGesturToKeyBoard ];
self . inputView = self . ObjKeyLayout ;
}
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Use [ UIApplication sharedApplication ] In Application Extention :-
1 ) Go to the app extension settings -> Build Settings -> Preprocessor Macros
2) add -----> TARGET_IS_EXTENSION
3) You can Write AnyWhere in Application Extention .... Given Below
#ifndef TARGET_IS_EXTENSION
//---------------- Whatever You want to Write
/*
if ( self .backgroundTaskId != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask: self .backgroundTaskId];
self .backgroundTaskId = UIBackgroundTaskInvalid;
}
*/
#endif
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > App Transport Security has blocked :-
Write in info.plist :-
<key> NSAppTransportSecurity </key>
<dict>
<key> NSAllowsArbitraryLoads </key>
<true/>
</dict>
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Get Path in Google Map (PolyLine) :-
-( void )GetPath
{
NSString *baseUrl = [ NSString stringWithFormat : @"https://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&sensor=true" , @"Ahmedabad" , @"chandni chownk new delhi" ];
NSURL *url = [ NSURL URLWithString :[baseUrl stringByAddingPercentEscapesUsingEncoding : NSUTF8StringEncoding ]];
NSLog ( @"Url: %@" , url);
NSURLRequest *request = [ NSURLRequest requestWithURL :url];
[ NSURLConnection sendAsynchronousRequest :request queue :[ NSOperationQueue mainQueue ] completionHandler :^( NSURLResponse *response, NSData *data, NSError *connectionError) {
if (!connectionError){
NSDictionary *result = [ NSJSONSerialization JSONObjectWithData :data options : 0 error : nil ];
NSArray *routes = [result objectForKey : @"routes" ];
if (routes. count == 0 )
{
UIAlertController *alert = [ UIAlertController alertControllerWithTitle : @"Sorry !!" message : @"Path Not Identify , Enter Other City" 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 ];
}
else
{
NSDictionary *firstRoute = [routes objectAtIndex : 0 ];
NSString *encodedPath = [firstRoute[ @"overview_polyline" ] objectForKey : @"points" ];
GMSPolyline *polyPath = [ GMSPolyline polylineWithPath :[ GMSPath pathFromEncodedPath :encodedPath]];
polyPath. strokeColor = [ UIColor blueColor ];
polyPath. strokeWidth = 5.5f ;
polyPath. map = mapView ;
}
}
}];
}
--- You Can Also Set Lat & Long :-
float lat_dest1 = [ strLatitude floatValue ];
float lng_dest1 = [ strLongitude floatValue ];
NSString *baseUrl = [ NSString stringWithFormat : @"http://maps.googleapis.com/maps/api/directions/json?origin=%f,%f&destination=%f,%f&sensor=true" , 23.0300 , 72.5800 ,lat_dest1,lng_dest1];
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Emoji to Unicode :-
NSData *data = [ _strTextData dataUsingEncoding : NSNonLossyASCIIStringEncoding ];
NSString *goodValue = [[ NSString alloc ] initWithData :data encoding : NSUTF8StringEncoding ];
NSLog ( @"%@" ,goodValue);
:--- > Unicode to Emoji :-
NSData *data1 = [goodValue dataUsingEncoding : NSUTF8StringEncoding ];
NSString *goodValue1 = [[ NSString alloc ] initWithData :data1 encoding : NSNonLossyASCIIStringEncoding ];
NSLog ( @"%@" ,goodValue1);
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > iOS NSDateFormats :-
Generally people don 't remember the formats string while they use NSDateFormatter. This reference will provide a easy to remember quick guides.
y = year
Y = Year (This year designation is used in ISO year-week calendar as defined by ISO 8601 , but can be used in non-Gregorian based calendar systems where week date processing is desired. May not always be the same value as calendar year.)
Q = quarter
M = month
w = week of year
W = week of monthd = day of the month
D = day of year
E = day of week
a = period (AM or PM)
h = hour ( 1 - 12 )
H = hour ( 0 - 23 )
m = minute
s = second
z = zone
Commonly used NSDateFormat String -
@"E, d M y" - Mon, 1 5 2015
@"EE, dd MM yy" - Mon, 01 05 15
@"EEE, ddd MMM yyy" - Mon, 001 May 2015
@"EEEE, dddd MMMM yyyy - Monday, 0001 May 2015
@"dd-MM-yyyy" - 01 - 05 - 2015
@"dd-MM-yyyy HH:mm:ss" - 01 - 05 - 2015 15 : 10 : 10
@"dd-MM-yyyy hh:mm:ss a" - 01 - 05 - 2015 10 : 15 : 12 AM
@"EEE, dd MMM yyyy HH:mm:ss Z" - Mon, 06 Sep 2009 16 : 45 : 00 - 0900
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Pop to any ViewControllers :-
for ( UIViewController * viewController in self . navigationController . viewControllers )
{
if ([viewController isKindOfClass :[ TutorUpdateViewController class ]] )
{
TutorUpdateViewController *groupViewController = ( TutorUpdateViewController *)viewController;
groupViewController. strForDetail = @"YES" ;
[ self . navigationController popToViewController :groupViewController animated : YES ];
}
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Use of Accelerometer :-
< UIAccelerometerDelegate >
- ( void ) viewDidLoad
{
[ super viewDidLoad ];
[[ UIAccelerometer sharedAccelerometer ] setDelegate : self ];
//Do any additional setup after loading the view,typically from a nib
}
- ( void ) accelerometer :( UIAccelerometer *) accelerometer didAccelerate :
( UIAcceleration *) acceleration {
[ xlabel setText :[ NSString stringWithFormat :@ "%f" , acceleration . x ]];
[ ylabel setText :[ NSString stringWithFormat :@ "%f" , acceleration . y ]];
[ zlabel setText :[ NSString stringWithFormat :@ "%f" , acceleration . z ]];
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > ON / OFF Flash Light :-
- Import ( AVFoundation.framework )
- Write Code : -
- ( IBAction )flashClick:( id )sender {
flashLight = [ AVCaptureDevice defaultDeviceWithMediaType : AVMediaTypeVideo ];
if ([ flashLight isTorchAvailable ] && [ flashLight isTorchModeSupported : AVCaptureTorchModeOn ])
{
BOOL success = [ flashLight lockForConfiguration : nil ];
if (success)
{
if ( flashLight . torchMode == AVCaptureTorchModeOn )
{
[ _btnFlash setTitle : @"TURN ON" forState : UIControlStateNormal ];
[ flashLight setTorchMode : AVCaptureTorchModeOff ];
}
else
{
[ _btnFlash setTitle : @"TURN OFF" forState : UIControlStateNormal ];
[ flashLight setTorchMode : AVCaptureTorchModeOn ];
}
[ flashLight unlockForConfiguration ];
}
}
else {
NSLog ( @"Torch not found in Simulator" );
}
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Get Location Name By Lat / Long :-
- Import ( CoreLocation.framework )
- ( IBAction )btnClick:( id )sender {
CLLocation *LocationAtual = [[ CLLocation alloc ] initWithLatitude : 23.0300 longitude : 72.5800 ];
CLGeocoder *geocoder = [[ CLGeocoder alloc ] init ] ;
[geocoder reverseGeocodeLocation :LocationAtual
completionHandler :^( NSArray *placemarks, NSError *error) {
NSLog ( @"reverseGeocodeLocation:completionHandler: Completion Handler called!" );
if (error){
NSLog ( @"Geocode failed with error: %@" , error);
return ;
}
CLPlacemark *placemark = [placemarks objectAtIndex : 0 ];
NSLog ( @"placemark.ISOcountryCode %@" ,placemark. ISOcountryCode );
NSLog ( @"placemark.country %@" ,placemark. country );
NSLog ( @"placemark.postalCode %@" ,placemark. postalCode );
NSLog ( @"placemark.administrativeArea %@" ,placemark. administrativeArea );
NSLog ( @"placemark.locality %@" ,placemark. locality );
NSLog ( @"placemark.subLocality %@" ,placemark. subLocality );
NSLog ( @"placemark.subThoroughfare %@" ,placemark. subThoroughfare );
}];
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > AlertView With TextField :-
UIAlertController *alert = [ UIAlertController alertControllerWithTitle : @"Add Name"
message :nil
preferredStyle :UIAlertControllerStyleAlert ];
[alert addTextFieldWithConfigurationHandler:^( UITextField *textField) {
// optionally configure the text field
textField.placeholder = @"Enter Name" ;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.keyboardType = UIKeyboardTypeAlphabet;
textField.returnKeyType = UIReturnKeySend ;
textField.de l e gate = self ;
}];
UIAlertAction *okAction = [ UIAlertAction actionWithTitle : @"Add"
style :UIAlertActionStyleDefault
handler :^(UIAlertAction *action) {
UITextField *textField = [alert.textFields firstObject ];
StrAddedName = textField.text ;
//---------------------------------------
}];
UIAlertAction *Cancel = [ UIAlertAction actionWithTitle : @"Cancel"
style :UIAlertActionStyleDefault
handler :^(UIAlertAction *action) {
}];
[alert addAction :Cancel];
[alert addAction :okAction];
[self presentViewController:alert animated: YES completion: nil ];
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Button in NavigationBar :-
- (void )viewDidLoad {
[super viewDidLoad];
//--------------------------------
UIImage * imageAlert = [UIImage imageNamed :@"map_icon.png" ];
CGRect frameimg = CGRectMake (0 ,0 ,25 ,25 );
UIButton *alertButton = [[UIButton alloc ] initWithFrame :frameimg];
[alertButton setBackgroundImage:imageAlert forState: UIControlStateNormal];
[alertButton addTarget :self action :@selector (AlertAction)
forControlEvents: UIControlEventTouchUpInside];
[alertButton setShowsTouchWhenHighlighted: YES ];
UIBarButtonItem *notificationbutton =[[UIBarButtonItem alloc ] initWithCustomView :alertButton];
self . navigationItem. rightBarButtonItem = notificationbutton;
}
-(void )AlertAction
{
// Code Here
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > Pull To refresh tableview :-
@interface PoleViewController ()
{
UIRefreshControl *refreshControl ;
}
@end
- (void )viewDidLoad {
[super viewDidLoad];
refreshControl = [[ UIRefreshControl alloc ] init ];
[ tblObj addSubview : refreshControl];
[refreshControl addTarget: self action: @selector (refreshTable) forControlEvents: UIControlEventValueChanged];
}
- (void )refreshTable
{
}
//-----------------------------------------------------------------------------
//---------------------------------------------------------
:--- > B it Bucket Commands :-
Get started with command line
I have an existing project
Step 1: Switch to your repository's directory
cd /path/to/your/repo
Step 2: Connect your existing repository to Bitbucket
git remote add origin https://aniruddh_rathod@bitbucket.org/aniruddh_rathod/ios-development.git git push -u origin master
I'm starting from scratch
git clone https://aniruddh_rathod@bitbucket.org/aniruddh_rathod/ios-development.git cd ios-development echo "# My project's README" >> README.md git add README.md git commit -m "Initial commit" git push -u origin master
For All File Push
git add --all
git commit -m "First commit"
git push -u origin master
:--- > GitLab Commands :-
Command line instructions
Git global setup
git config --global user.name "Username"
git config --global user.email "email"
Create a new repository
git clone git@gitlab.com:Project_Name.git
cd packstoreship
touch README.md
git add README.md
git commit -m "add README"
Existing folder
cd existing_folder
git init
git remote add origin git@gitlab.com:Project_Name.git
git add .
git commit -m "Initial commit"
Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.com: Project_Name.git