Working Again!

After six weeks of no income, I started work this week at TeleCommunication Systems (TCS). I’m assigned to the team working on next generation 911, also called NG911.

Our existing system was designed when land line phones dominated before cell phones were even heard of, at least to the general public.

In the intervening years, cell phone service, and later Voice Over IP (VOIP) or internet phones have been scabbed into the system with some hacks. Good hacks, but they are still hacks. The Next Generation system that the National Emergency Number Association (NENA) has defined will provide a more solid and extensible base for handling the existing system and future growth, including text messages, photos, videos and other sources of information that our mobile communications make possible that can help the emergency responders be better prepared for the situation at hand.

Technorati Tags:
,

Posted in Software Development, TCS | Tagged , , | Leave a comment

Bug in Core Data?

After a great deal of searching around and playing with alternatives, I’ve figured out that if I insert new records into the SoundChurch store one record at a time, everything works. If I allow Core Data to attempt to insert multiple records at once, it throws the error discussed in the previous post.

Could I have discovered a bug in Core Data?

Technorati Tags:
, ,

Posted in iOS, Software Development | Tagged , | 2 Comments

CoreData error saving data

As I continue to attempt to improve the operation of the Sound Church application, I’ve run into issues with Core Data returning an error when I attempt to save an Item.

The error:

2011-07-09 16:57:36.670 Sound-Church[12292:207] Unresolved error Error Domain=NSCocoaErrorDomain Code=256 “The operation couldn’t be completed. (Cocoa error 256.)” UserInfo=0x4d62010 {NSFilePath=/Users/john/Library/Application Support/iPhone Simulator/4.3.2/Applications/BF78B117-48CA-48C7-A61E-29A452E2824A/Documents/Sound_Church.sqlite, NSUnderlyingException=error during SQL execution : constraint failed}, {
NSFilePath = “/Users/john/Library/Application Support/iPhone Simulator/4.3.2/Applications/BF78B117-48CA-48C7-A61E-29A452E2824A/Documents/Sound_Church.sqlite”;
NSUnderlyingException = “error during SQL execution : constraint failed”;
}

I see the error from this code:


- (void)saveContext

{

   NSLog(@"Entering saveContext");

   NSError *error = nil;

   NSManagedObjectContext *managedObjectContext = self.managedObjectContext;

   if (managedObjectContext != nil)

   {

     if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error])

     {

       NSLog(@"Unresolved error %@, %@", error, [error userInfo]);

       abort();

     }

   }

}

In searching the web, I found this article that talks about that very message, but it doesn’t seem to apply as apparently the writer is directly accessing the sqlite database, which I don’t do.

I also found this question and answer, which suggests a possible problem, but again, I don’t see it applying to me, as I use a NSFetchedResultsController to populate the UITableView and otherwise only fetch results to verify that the new Item is unique.

The code where I fetch results to check for an error:

- (void)parser:(NSXMLParser *)parser

didEndElement:(NSString *)elementName

namespaceURI:(NSString *)namespaceURI

qualifiedName:(NSString *)qName

{

   if (!self.currentItemObject)

   {

     // We don't want to bother attempting to process all the header info.

     return;

   }



   if ([elementName isEqualToString: kItemElementName])

   {

     NSPredicate *predicate = [NSPredicate predicateWithFormat: @"guid == \"%@\"", currentItemObject.guid];

     NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];

     [request setPredicate: predicate];

     NSEntityDescription *entity = [NSEntityDescription entityForName:@"Item"

    inManagedObjectContext:self.context];

     [request setEntity: entity];

     NSError *error = [[[NSError alloc] init] autorelease];

     NSMutableArray *items = [[context executeFetchRequest: request error: &error] mutableCopy];

     if (!items)

     {

       // TODO: Need to do better error handling.

       NSLog(@"Error fetching items. %@", [error localizedDescription]);

       [items release];

       return;

     }



     if (0 < [items count])

     {

       // This is a duplicate element, we don't want to save it.

       [items release];

       return;

     }



     [items release];

...

At this point, I haven’t resolved this issue, so I’m still looking for a solution.

In the process of digging through the code, I did stumble upon another problem. I found that the title of the podcasts seemed to always be the same as the summary. So I did some digging, and found that, in fact, I was not copying the data elements into the NSManagedObject. Dumb.. Since the objects (NSStrings in this case) are passed as pointers, when I would write the next string into the same NSMutableString, it overwrote the previous entry, so all elements of an object became the last thing I entered.

So that’s solved, but I’m going to have to do some more digging into the sqlite table to figure out the problem with the error.

Posted in iOS, Sound Church | Tagged , , | Leave a comment

Sound Church Progress

I’m now getting the podcast data to load into the CoreData store, but still getting a BadAccess Exception that I haven’t tracked down. Still looking to find out where I’m accessing something after it’s deleted.

I have an image of the screen. Not really exciting, especially since it seems to be loading the one item multiple times, and that one item is the lone video in the package.
Sound Church screen with the lone video in every cell.

I’m thinking I’ll break the connection I have between the Channel object and the Item objects. The connection is somewhat arbitrary, and I’m not even sure I need the channel, but I have it for now. I certainly don’t need the connection to the channel.

Latest code has been uploaded to github (github account required), for anyone who’s interested to look at it.

Posted in iOS, Sound Church | Tagged , , , | Leave a comment

NSManagedObject

I’ve been discovering the intricacies of managing NSManagedObjects. These are the objects that you as a developer have to use when developing with Core Data. Because of the level of control over the lifecycle of the objects that Core Data takes, the normal -(id)init; and -(void)dealloc; methods should not be overridden in a subclass of NSManagedObject.

Instead, you need to use the NSEntityDescription class method


+ (id)insertNewObjectForEntityForName:(NSString *)entityName

inManagedObjectContext:(NSManagedObjectContext *)context;


This method returns a NSManagedObject of the type noted by the entityName parameter.

While dealing with all this stuff. I realized I don’t understand all the in’s and out’s of how the model creates objects. I had the model backwards, as the one Channel contains many Items, but the model reversed that, so I had to pull some hackery to get what I want.

One little key, if you modify the model, you’ll have to delete the files in ~/Library/Application Support/iPhone Simulator/<version>/Applications/. I deleted everything in there and it was happy again.

At this point, I’m getting data into the model, and that’s good enough for now. I still need to deal with new vs. existing entries, but that’s for another time. It’s now time to move on to the RootViewController and start displaying the data available.

Posted in iOS, Objective-C, Sound Church, XCode | Tagged , , | Leave a comment

NSXMLParser initWithContentsOfURL:

In digging around looking at errors I was getting with the NSXMLParser when using the

- (id)initWithData: (NSData *)data;


initializer, I discovered the


- (id)initWithContentsOfURL: (NSURL *)url;


initializer. This initializer handles all the connection logic without me having to deal with it. Since the reality of this application is, if you can’t download the data from the server, you can still use the app with data that you’ve downloaded previously, there’s no need for me to maintain the downloading separately.

I’m no longer using the RSSDownloader class, or the RSSDownloaderDelegate protocol. Since the only other case of downloading is to get the audio file for a specific message, I probably don’t need the abstraction of moving the download logic to a separate controller class. That, however, is an issue for another time.

Posted in iOS, Objective-C, Sound Church, XCode | Tagged , , | Leave a comment

Sound Church

I’ve been working on the Sound Church application between interviews and phone calls since I’m no longer employed by Point Inside. The app is coming along.

I have a class, RSSDownloader, that implements the NSURLConnection protocol. It also has a delegate that handles the output, providing a bit of abstraction for the connections. When the application launches, the downloader will download the xml file from the RSS feed server and parse it. Then when the user wants to listen to a podcast, that podcast needs to be downloaded, so the RSSDownloader will be used again.

I’m currently working on the parser, which parses the xml file into the required objects. Currently it’s failing on the title of the Channel object. In the current data definition, the channel contains the data that’s part of the RSS header. It contains a list of Items, each item being a separate podcast.

I’d do a screenshot of the data model, but Xcode 4 seems to spread the model out over more than one screen, even though there’s only two entities, and I can’t seem to figure out how to move them closer together, or if it’s possible.

Posted in iOS | Leave a comment

OCMock for iPhone

Thinking about using OCMock with my Sound-Church project. First off, getting it to build is a challenge, particularly to include the library with the version running on the phone. The solution to that problem is with the linker settings.

Linker flags

Notice the -ObjC -all_load flags. Those are required to load a static library, as the dynamic nature of Objective-C makes it not load those libraries.

I’m still figuring out how to use a fake method with multiple parameters with this tool, however. The available documentation is a bit light. I did find this post, which is about the best I’ve found for using OCMock. Nobody describes using OCMock with Xcode 4, however.

Posted in iOS, Sound Church, XCode | Tagged , | Leave a comment

The managed object model version used to open the persistent store is incompatible with the one that was used to create the persistent store.

I’ve been getting this error today when attempting to build my Sound-Church application. Couldn’t figure it out until I found this post that explained it.

For iOS, look in ~/Library/Application Support/iPhone Simulator/ where version is the iOS version you are targeting to find the offending files. I just blew away all the sub-folders in that folder to solve my problem.

Posted in iOS, XCode | Tagged , , | Leave a comment

New website

If you’re here, you’ve noticed the revamping of this website, with the blog front and center. I will say more about the reasons soon. In the meantime, enjoy the new site.

Posted in Business, Software Development, The Web | Tagged , | 1 Comment