Wednesday, August 18, 2010

multiple annotation map

- (void)viewDidLoad
{
NSLog(@"ddddddd");
/*
locationManager=[[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate=self;
//Start the compass updates.
[locationManager startUpdatingHeading];
[[self locationManager] startUpdatingHeading];
[[self locationManager] startUpdatingLocation];
*/

[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];

MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 1.30;//41.902245099708516;
region.center.longitude = 103.8;//12.457906007766724;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];

[mapView setDelegate:self];

MyAnnotation *ann = [[MyAnnotation alloc] init];
ann.title = @"Rome";
ann.subtitle = @"San Peter";
ann.coordinate = region.center;
//[mapView addAnnotation:ann];






/// one more annt
//My own Annotation
MKCoordinateRegion SecondRegion;
SecondRegion.center.latitude = 1.301;
SecondRegion.center.longitude = 103.81;

MyAnnotation *aSecondAnnotation = [[MyAnnotation alloc] init];
aSecondAnnotation.title = @"Second Annotation";

//By the way, this line doesn’t work, everything is still in the same line :(
aSecondAnnotation.subtitle = @"clerqkey";
aSecondAnnotation.coordinate = SecondRegion.center;

//// 2 more

MKCoordinateRegion SecondRegiona;
SecondRegiona.center.latitude = 1.31;
SecondRegiona.center.longitude = 103.9;

MyAnnotation *aSecondAnnotationa = [[MyAnnotation alloc] init];
aSecondAnnotationa.title = @"3rd Annotation";

//By the way, this line doesn’t work, everything is still in the same line :(
aSecondAnnotationa.subtitle = @"ret";
aSecondAnnotationa.coordinate = SecondRegiona.center;


//////////////////////////////////////////////////////////////////////////////////////////////

NSArray *Annotations = [NSArray arrayWithObjects:ann,aSecondAnnotation,aSecondAnnotationa,nil];

[mapView addAnnotations:Annotations];


[super viewDidLoad];
}/*
- (void)locationManager:(CLLocationManager *) manager didUpdateHeading:(CLHeading *) newHeading {
NSLog(@"55555555555555555555555");
NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);
NSLog(@"New true heading: %f", newHeading.trueHeading);





}
*/


- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
for (id currentAnnotation in mapView.annotations) {
[mapView selectAnnotation:currentAnnotation animated:YES];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )annotation
{
MKPinAnnotationView *pinView = nil;
[[self locationManager] startUpdatingHeading];
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

pinView.pinColor = MKPinAnnotationColorPurple;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
}
else
{
[mapView.userLocation setTitle:@"I am here"];
}

return pinView;
}

Thursday, August 12, 2010

unzip data from web

NSString *aDirectory =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];


NSFileManager *fileManager= [NSFileManager defaultManager];

NSString* filePath = [NSString stringWithFormat:@"%@/temp.zip", aDirectory];
NSString* updateURL = @"http://localhost/list.zip";
NSLog(@"Checking update at : %@", updateURL);
NSData* updateData = [NSData dataWithContentsOfURL: [NSURL URLWithString: updateURL] ];

[fileManager createFileAtPath:filePath contents:updateData attributes:nil];

ZipArchive *zipArchive = [[ZipArchive alloc] init];

if([zipArchive UnzipOpenFile:filePath]) {

if ([zipArchive UnzipFileTo:aDirectory overWrite:YES]) {
//unzipped successfully
NSLog(@"Archive unzip Success");
[fileManager removeItemAtPath:filePath error:NULL];
} else {
NSLog(@"Failure To Unzip Archive");
}

} else {
NSLog(@"Failure To Open Archive");
}

[zipArchive release];

NSLog(@"string text is %@",filePath);

Tuesday, August 10, 2010

saving locaaly and update data from web

#pragma mark save file locally


NSString *applicationDocumentsDir =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:@"sample1.cfg"];

NSURL *instructionsURLd = [[NSURL alloc] initFileURLWithPath:filePath];
NSData *dataXML = [NSData dataWithContentsOfURL:instructionsURLd];

[dataXML writeToFile:storePath atomically:YES];

// NSLog(@"matrix path %@",applicationDocumentsDir);
//NSLog(@"neo path %@",storePath);



#pragma mark update
// http://localhost/update.cfg

//NSData *dataXML = [NSData dataWithContentsOfURL:instructionsURLd];

NSURL *urlf = [[NSURL alloc] initWithString:@"http://localhost/update.cfg"];
dataXML = [NSData dataWithContentsOfURL:urlf];


NSMutableData *file = [[NSMutableData alloc] initWithContentsOfFile:storePath];
[file appendData:dataXML];
[file writeToFile:storePath atomically:YES];

Friday, August 6, 2010

Dynamic buttons and method on them

#pragma mark load filePath
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"tabs" ofType:@"cfg"];
if (filePath) {


NSString *myText = [NSString stringWithContentsOfFile:filePath];

NSMutableArray *a1 = [[NSMutableArray alloc] init];
[a1 addObjectsFromArray:[myText componentsSeparatedByString:@"\n"]];

[a1 addObject:myText];


NSUInteger i;
for (i = 1; i <= [a1 count]-1; i++)
{

NSString *urlE=[a1 objectAtIndex:1];
NSLog(@"url is %@",urlE);




#pragma mark buttons
CGRect frame = CGRectMake(curXLoc, 10, 60, 30);
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = frame;
button.tag=i;
[button setImage:[UIImage imageNamed:@"tab2.png"] forState:UIControlStateNormal];
[button setTitle:(NSString *)@"new button" forState:(UIControlState)UIControlStateNormal];
[button addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
curXLoc += (kScrollObjWidth1);
[self.view addSubview:button];


}




}
}





-(void)buttonEvent:(UIButton*)sender{
NSLog(@"new button clicked!!!");
if (sender.tag == 1) {
NSLog(@"1");
}
if (sender.tag == 2) {
NSLog(@"2");
}
}

Tuesday, July 27, 2010

double tap

float distance;
if([touches count] == 2) {
// Order touches so they're accessible separately
NSMutableArray *touchesArray = [[[NSMutableArray alloc]
initWithCapacity:2] autorelease];
for(UITouch *aTouch in touches) {
[touchesArray addObject:aTouch];
}
UITouch *firstTouch = [touchesArray objectAtIndex:0];
UITouch *secondTouch = [touchesArray objectAtIndex:1];

// Do math
CGPoint firstPoint = [firstTouch locationInView:[firstTouch view]];
CGPoint secondPoint = [secondTouch locationInView:[secondTouch view]];
distance = sqrtf((firstPoint.x - secondPoint.x) *
(firstPoint.x - secondPoint.x) +
(firstPoint.y - secondPoint.y) *
(firstPoint.y - secondPoint.y));
}

show image in center of table view

CGRect frame;

frame= CGRectMake(230 ,50, 50, 50);
UIImageView * myImageView = [[UIImageView alloc]init];
myImageView.image = [UIImage imageNamed:@"bowl.png"];
//cell.imageView.image= [UIImage imageNamed:@"bowl.png"];

myImageView.frame = frame;
//UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bowl.png"]];
[cell.contentView
addSubview: myImageView];
[myImageView release];

Thursday, July 22, 2010

C in UNIX

gcc -c test.c
$ gcc test.c
$ gcc test.c -o a.out
$ ./a.out



thats it HAPPY CODING :-)

Wednesday, July 21, 2010

How to Debug an iPhone App Crash, Part 1: EXC_BAD_ACCESS

1. Run Build and Analyze: This kind of Build is very good at finding retain/release bugs. Take a good look at everything it flags.
2. Even better, run scan-build. I did a test recently, and found that some common errors are off by default in Build and Analyze that can be turned on in scan-build.
3. Choose Run > Enable Guard Malloc in the menu, and then re-run your application. This finds a whole class of buffer overrun issues. If this detects it, you’ll see a better error in the console.
4. You can instruct the compiler to ignore release calls and then report if anyone is sending messages to objects that would have been deallocated. This results in much better errors in the Console if it detects them.
5. Valgrind is the gold standard for finding memory bugs on Linux, and here’s a way to get it working in the iPhone Simulator.



Thanks to http://www.loufranco.com/blog/files/debug-iphone-crash-EXC_BAD_ACCESS.html

Friday, July 16, 2010

Adding images to map Annotation

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
(id )annotation {
if (annotation == mapView.userLocation) return nil;

UIImage *anImage = nil;
if([[annotation title] isEqualToString:@"type1"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type1.png" ofType:nil]];
}
else if([[annotation title] isEqualToString:@"type2"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type2.png" ofType:nil]];
}
else if([[annotation title] isEqualToString:@"type3"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type3.png" ofType:nil]];
}
else if([[annotation title] isEqualToString:@"type4"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type4.png" ofType:nil]];
}

MKAnnotationView *anView=(MKAnnotationView*)[mapView
dequeueReusableAnnotationViewWithIdentifier:@"annotation"];

if(anView==nil){
anView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotation"] autorelease];
}
anView.image = anImage;
anView.annotation=annotation;
anView.canShowCallout=YES;
if(tag==0){
anView.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
return anView;
}

Thursday, July 8, 2010

pasing string value

statement "SELECT * FROM wateat_tbl where name like '%love%' or desc like '%love%'"
mixing SQL qurey + user input in one string

NSString* SQL_statement = [NSString stringWithFormat:@"SELECT * FROM wateat_tbl where name like '%%%@%%' or desc like '%%%@%%'", myStringPrt2, myStringPrt2];

const char *sqlStatement = [SQL_statement UTF8String]; // string to char need UTF8

FEEDJIT Live