Callout bubble in MKMapView

custom bubble

All i needed was some custom text in the call out bubble, and then i needed that bubble to appear just as the pin dropped. i spent hours on something that seemed so simple…and actually , it is simple.

Read the rest of this entry »

Adding an int or float to an Array or Dictionary

omg, i can’t believe how strict Objective C can be. While working with MKMapView on an iPhone app i am currently writing, i was trying to pass the lattitude and longitude to a custom class. My code looked like:

NSDictionary *locationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:49.277778,@"lat",-123.108889,@"long",nil];

alas, one must do this:

NSDictionary *locationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:49.277778],@"lat",[NSNumber numberWithFloat:-123.108889],@"long",nil];

i think i need to start a post of the little things that drive me mad in this crazy language. By far , concatenating a string is the winner.

scrubbing video [NetStream]

I always like to do my video players from the ground up…i guess it’s just my style. I have used often the FLVPlayback, but there is a satisfaction in creating your own player. One thing that always plays with my head is the scrubbing. It’s the actual Math that gets me, and generally, i get it after a few tries…but never on the first (much like the custom scrollbar) . Read the rest of this entry »

shared font library, programatic textfields, and css

recently, i was tasked to do a gallery of images with captions. A few cavates to the request:

  1. we must use a shared library.
  2. we can not embed fonts to the working fla
  3. captions must be html enabled

…and so begins the dissection of Flash and Fonts Read the rest of this entry »

Objective C’s URLRequest & URLLoader

I am learning ObjectiveC. For the model app in my head, i need the equivilant of what i understand to be a URLRequest and a URLLoader. As well, i need to understand the event callbacks(Event.COMPLETE, IOErrorEvent.IO_ERROR) and how to handle these…so, off to the Apple Dev Samples. The sample that made sense to me was the SeismicXML parser. I went straight for the  (.m file) implementation class of SeismicXMLAppDelegate . In there i found the portion of code that seems to pertain to me:


static NSString *feedURLString = @"htgggtp://earthquake.usgs.gov/eqcenter/catalogs/7day-M2.5.xml";
NSURLRequest *earthquakeURLRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:feedURLString]];
self.earthquakeFeedConnection = [[[NSURLConnection alloc] initWithRequest:earthquakeURLRequest delegate:self] autorelease];

Let’s walk through it, but first the two equivialant definitions for our URLRequst and URLLoader. In ObjectiveC , we will be working with NSURLRequest and NSURLConnection.

the NSString is the url – easy. NSURLRequest…hmmm, that sounds just like AS3’s URLRequest, doesn’t it. We declare the variable earthquakeURLRequest as a ‘new’ NSURLRequest, and we add in some methods on the fly. (i am learning that this is a key thing about ObjectiveC- it seems to do a lot in a methods in line of code.) So, we instantiate the request, as well as its requestWithURL method, passing in our url string.  In the interface (.h file), we assigned the earthquakeFeedConnection (NSURLConnection) to self (this, in as3). So, we call it to the front (self.earthquakeFeedConnection) and instantiate the class with the famously confusing alloc/init. A key feature that can not be missed is the NSURLConnection needs to konw the delegate, which is the parent class in this case (self)

ok…so, what about the call backs? Yep, just keep reading Apple’s Sample code. The first two are the recepients of a response and of data.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
self.earthquakeData = [NSMutableData data];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[earthquakeData appendData:data];
}

then the error (like IOErrorEvent.IO_ERROR):
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if ([error code] == kCFURLErrorNotConnectedToInternet) {
// if we can identify the error, we can present a more precise message to the user.
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:NSLocalizedString(@"No Connection Error", @"Error message displayed when not connected to the Internet.") forKey:NSLocalizedDescriptionKey];
NSError *noConnectionError = [NSError errorWithDomain:NSCocoaErrorDomain code:kCFURLErrorNotConnectedToInternet userInfo:userInfo];
[self handleError:noConnectionError];
} else {
// otherwise handle the error generically
[self handleError:error];
}
self.earthquakeFeedConnection = nil;
}

and finally, the almighty Event.COMPLETE!
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
self.earthquakeFeedConnection = nil;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// Spawn a thread to fetch the earthquake data so that the UI is not blocked while the application parses the XML data.
//
// IMPORTANT! - Don't access UIKit objects on secondary threads.
//
[NSThread detachNewThreadSelector:@selector(parseEarthquakeData:) toTarget:self withObject:earthquakeData];
// earthquakeData will be retained by the thread until parseEarthquakeData: has finished executing, so we no longer need
// a reference to it in the main thread.
self.earthquakeData = nil;
}

i won’t go to far into this, but there it is…all but the complete are the connection method of the NSURLConnection class. One thing to note, which i may be wrong, but appears to be the case. In ObjectiveC, the complete event seems more of a clean up. In AS3 i would generally wait for that to move forward with the data. But it appears in ObjectiveC, we start parsing/etc from didRecieveData…hmm, like i say, it’s all new to me…but i had to document this for future reference.