Wednesday, May 11, 2011

E-mail Validation in javascript










Email:






Monday, May 9, 2011

Check and Get the focus on the input box through JavaScript on the UIWebView in iPhone.




  Document.body.focus();
  var  inID = document.activeElement.id;
   function Function1Delay()
      {
         if(document.activeElement .id  !=  inID)
          {
             inID = document.activeElement.id;
             alert('Start Scan');
             document.getElementById(inID).value='Dinesh Sharma';
             setTimeout("Func1Dealy()",200); 
          }
         else
          {
            setTimeout("Func1Delay()",500); 
          }
      }


1.

NSString *str12 = [NSString stringWithFormat:@"document.body.focus(); var inii=document.activeElement.id; function Func1Delay() {if(document.activeElement.id != inii){inii=document.activeElement.id; alert('start scan');document.getElementById(inii).value='dinesh sharma';setTimeout(\"Func1Delay()\", 500);} else { setTimeout(\"Func1Delay()\", 500);}}"];
[myWeb stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@" %@ Func1Delay(); ",str12]];


2.

/*
NSString *str1 = [NSString stringWithFormat:@"function showAlert() { alert('%@');}",str];
[myWeb stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"%@ showAlert(); ",str1]];
    */
3.[myWeb stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"var field = document.forms[0].q;" "field.value='something';"]];
//[myWeb stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"var field = document.activeElement; field.value='Dinesh Sharma';"]];

Friday, April 29, 2011

Get the Property form address contact in iPhone




strFirstName = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);

//Get mobile phone number
ABMultiValueRef phones =(NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty);
mobile=@"";
NSString* mobileLabel;
for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
NSLog(@"",mobileLabel);
if([mobileLabel isEqualToString:@"_$!!$_"]) {
mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
}
}
//get the email
//Get mobile phone number
ABMultiValueRef emailAddress =(NSString*)ABRecordCopyValue(person, kABPersonEmailProperty);
email=@"";
NSString* emailLabel;
for(CFIndex i = 0; i < ABMultiValueGetCount(emailAddress); i++) {
emailLabel = (NSString*)ABMultiValueCopyLabelAtIndex(emailAddress, i);
NSLog(@"",emailLabel);

if([emailLabel isEqualToString:@"_$!!$_"]) {
email = (NSString*)ABMultiValueCopyValueAtIndex(emailAddress, i);
}
}


- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
  shouldContinueAfterSelectingPerson:(ABRecordRef)person { 
customer.firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
customer.lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
customer.companyName = (NSString *)ABRecordCopyValue(person, kABPersonOrganizationProperty);
if (!customer.firstName.length) {
customer.firstName = @"*";
}
if (!customer.lastName.length) {
customer.lastName = @"*";
}
if (!customer.companyName.length) {
customer.companyName = @"";
}


CFStringRef email, emailLabel, phone, phoneLabel;
ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSMutableDictionary *myPhoneDict = [NSMutableDictionary dictionaryWithCapacity:ABMultiValueGetCount(phoneMulti)];
for (CFIndex i = 0; i < ABMultiValueGetCount(phoneMulti); i++) { 
phoneLabel = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phoneMulti, i));
phone = ABMultiValueCopyValueAtIndex(phoneMulti, i); 
[myPhoneDict setObject:(NSString*)phone forKey:(NSString*)phoneLabel];
CFRelease(phone);
CFRelease(phoneLabel);
if ( [myPhoneDict objectForKey:@"mobile"] != nil) {
customer.phone  = [myPhoneDict objectForKey:@"mobile"];
} else if ( [myPhoneDict objectForKey:@"home"] != nil) {
customer.phone  = [myPhoneDict objectForKey:@"home"];
} else if ( [myPhoneDict objectForKey:@"work"] != nil) {
customer.phone  = [myPhoneDict objectForKey:@"work"];
}

ABMutableMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty);
NSMutableDictionary *myEmailDict = [NSMutableDictionary dictionaryWithCapacity:ABMultiValueGetCount(multi)];
for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) { 
emailLabel = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multi, i));
email = ABMultiValueCopyValueAtIndex(multi, i); 
[myEmailDict setObject:(NSString*)email forKey:(NSString*)emailLabel];
CFRelease(email);
CFRelease(emailLabel);
if ([myEmailDict objectForKey:@"home"] != nil) {
customer.email = [myEmailDict objectForKey:@"home"];
} else if ([myEmailDict objectForKey:@"work"] != nil) {
customer.email = [myEmailDict objectForKey:@"work"];
} else if ([myEmailDict objectForKey:@"other"] != nil) {
customer.email = [myEmailDict objectForKey:@"other"];
}
// get the address stuff
ABMultiValueRef streets = ABRecordCopyValue(person, kABPersonAddressProperty);
NSMutableDictionary *myAddressDict = [NSMutableDictionary dictionaryWithCapacity:ABMultiValueGetCount(streets)];
for (CFIndex j = 0; j < ABMultiValueGetCount(streets); j++) {
NSMutableDictionary *myLabelDict = [[NSMutableDictionary alloc] init];
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(streets, j);
CFStringRef typeTmp = ABMultiValueCopyLabelAtIndex(streets, j);
CFStringRef type = ABAddressBookCopyLocalizedLabel(typeTmp);
NSString *street = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStreetKey) copy];
NSString *city = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCityKey) copy];
NSString *state = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStateKey) copy];
NSString *zip = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressZIPKey) copy];
NSString *country = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCountryKey) copy];
if ((street != nil) && (street.length > 0))
[myLabelDict setObject:street forKey:@"street"];
if ((city != nil) && (city.length > 0))
[myLabelDict setObject:city forKey:@"city"];
if ((state != nil) && (state.length > 0))
[myLabelDict setObject:state forKey:@"state"];
if ((zip != nil) && (zip.length > 0))
[myLabelDict setObject:zip forKey:@"zip"];
if ((country != nil) && (country.length > 0))
[myLabelDict setObject:country forKey:@"country"];
[myAddressDict setObject:myLabelDict forKey:(NSString *)type];
[myLabelDict release];
[street release];
[city release];
[state release];
[zip release];
[country release];
CFRelease(dict);
CFRelease(type);
CFRelease(typeTmp);
}

NSString *theKey;
if ([myAddressDict objectForKey:@"home"] != nil) {
theKey = @"home";
} else if ([myAddressDict objectForKey:@"work"] != nil) {
theKey = @"work";
} else if ([myAddressDict objectForKey:@"other"] != nil) {
theKey = @"other";
}
if ([[[myAddressDict objectForKey:theKey] objectForKey:@"street"] length] > 0) {
customer.street = [[myAddressDict objectForKey:theKey] objectForKey:@"street"];
} else {
customer.street = @"";
}
if ([[[myAddressDict objectForKey:theKey] objectForKey:@"city"] length] > 0) {
customer.city = [[myAddressDict objectForKey:theKey] objectForKey:@"city"];
} else {
customer.city = @"";
}
if ([[[myAddressDict objectForKey:theKey] objectForKey:@"state"] length] > 0) {
customer.state = [[myAddressDict objectForKey:theKey] objectForKey:@"state"];
} else {
customer.state = @"";
}
if ([[[myAddressDict objectForKey:theKey] objectForKey:@"zip"] length] > 0) {
customer.postalCode = [[myAddressDict objectForKey:theKey] objectForKey:@"zip"];
} else {
customer.postalCode = @"";
}
if ([[[myAddressDict objectForKey:theKey] objectForKey:@"country"] length] > 0) {
customer.country = [[myAddressDict objectForKey:theKey] objectForKey:@"country"];
} else {
customer.country = @"";
}
CFRelease(streets);
CFRelease(phoneMulti);
CFRelease(multi);
[customer dehydrate];
[self dismissModalViewControllerAnimated:YES];
return NO; 
}

Wednesday, January 12, 2011

iPhone MapKit Framework to cache Google map for offline: Good Idea

1) Can MapKit Framework support caching Google Map on iPhone locally ? 
2) Can MapKit Framework support to use offline map during GPS-ing ?


Answer :
Unfortunately no, you cannot cache the google tiles (at least not in iOS 4.x). However, you can use an MKOverlay to create an overlay that displays and caches tiles from another map source like OpenStreetMap. Apple published an example TileMap overlay with their 2010 WWDC videos.


Reference link:
http://stackoverflow.com/questions/3792532/iphone-mapkit-framework-to-cache-google-map-for-offline-use


Q. I am working on GPS Track...but when my device is offline then not show the Map. Can you please help for shut out it ? or How to implement the tiles in my application ?
Answer preferred by Apple forum.
Answer 1. : As I understand it MapKit terms and conditions require Google, try route-me for an alternative framwork.


Answer 2. : MapKit maintains a fixed-size map tile cache that contains (roughly speaking) tiles for the most recently viewed areas.  If the device is offline, and your MKMapView is zoomed to an area for which there are no tiles in the tile cache, maps will not be available.

The only solution to this would be to bundle your own map tiles with your app and implement your own map view.  It's up to you to decide if that is worthwhile for your use case.

Thursday, January 6, 2011

Time difference between two different times.

NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
[dateFormatter setDateFormat:@"hh:mm:ss"];
NSDate* firstDate = [dateFormatter dateFromString:starttime];
NSDate* secondDate = [dateFormatter dateFromString:endtime];
NSTimeInterval ti = [secondDate timeIntervalSinceDate:firstDate];
//NSString *str1 = [NSString stringWithFormat:@"%d",ti];
//NSLog(@"str1 %@",str1);
NSUInteger h, m, s;
h = (ti / 3600);
m = ((NSUInteger)(ti / 60)) % 60;
s = ((NSUInteger) ti) % 60;
NSString *str = [NSString stringWithFormat:@"%d:%02d:%02d", h, m, s];
//NSLog(@" strdiff : %@ ",str);

Tuesday, November 2, 2010

condition of allowed run the application in the both iPhone sdk etc.

Ref.: AvailabilityInternel.h class

//#if __IPHONE_3_2 >= __IPHONE_OS_VERSION_MAX_ALLOWED
//#endif

Monday, October 18, 2010

NSFileManager to save an image to or load/remove an image from documents directory

Reference link :
http://www.friendlydeveloper.com/2010/02/using-nsfilemanager-to-save-an-image-to-or-loadremove-an-image-from-documents-directory-coding/
special thanks for "friendlydeveloper"

NSFileManager offers a convenient way to write images to and load them from the documents directory.
If you’re frequently doing that in your project, I suggest to wrap up NSFileManager support in three simple methods:
01//saving an image
02 
03- (void)saveImage:(UIImage*)image:(NSString*)imageName {
04 
05NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
06 
07NSFileManager *fileManager = [NSFileManager defaultManager];
08 
09NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
10 
11NSString *documentsDirectory = [paths objectAtIndex:0];
12 
13NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]];
14 
15[fileManager createFileAtPath:fullPath contents:imageData attributes:nil];
16 
17NSLog(@"image saved");
18 
19}
20 
21//removing an image
22 
23- (void)removeImage:(NSString*)fileName {
24 
25NSFileManager *fileManager = [NSFileManager defaultManager];
26 
27NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
28 
29NSString *documentsDirectory = [paths objectAtIndex:0];
30 
31NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", fileName]];
32 
33[fileManager removeItemAtPath: fullPath error:NULL];
34 
35NSLog(@"image removed");
36 
37}
38 
39//loading an image
40 
41- (UIImage*)loadImage:(NSString*)imageName {
42 
43NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
44 
45NSString *documentsDirectory = [paths objectAtIndex:0];
46 
47NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]];
48 
49return [UIImage imageWithContentsOfFile:fullPath];
50 
51}
Now, you can easily save an image like:
1[self saveImage: myUIImage: @"myUIImageName"];
or load it like:
1myUIImage = [self loadImage: @"myUIImageName"];
or remove it like:
1[self removeImage: @"myUIImageName"];