Posted on Aug 17, 2011

Automatically update store schema with Core Data

Today I was playing with Core Data technology and I was trying to check whether it is possible to update the store schema according to the changes I made to the entities, relationships and whatever else.

I found out that the important steps are:

  • Use the versioning: before modifying your current schema you should select “Editor -> Add Model Version..”
  • Edit as much as you like
  • Select the new version as the active one
  • Go to your app delegate file and modify the - (NSPersistentStoreCoordinator *) persistentStoreCoordinator method as follows:
    NSURL *url = [applicationFilesDirectory URLByAppendingPathComponent:@"YourApp.storedata"];
        __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
    
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
    						 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
    						 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
    
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:options error:&error]) {
    		// The rest of the code here
    	}
    
    return __persistentStoreCoordinator;
    



    The highlighted lines are the one to be added. Please notice that row 8 needs to be updated with options:options. I only tried it using NSSQLiteStoreType as persistent store type but it should work fine even with NSXMLStoreType.

References:

  1. Working with Core Data: Schema Versioning and Lightweight Migrations

Posted on May 1, 2011

Free over-the-air distribution

Few days ago, Matteo Kuzeko, pointed out to my attention a web service that easily allows iOS developers to share they own application over-the-air in order to do beta testing: TestFlight

In my previous related post I briefly told you how to do the same all by yourself; with TestFlight the goal is the same but this service brings altogether few interesting features. Practically speaking, you have to build up a Team. The latter is usually composed by the developers and the testers.
With the online control-panel you can invite people by using their email addresses (one at a time) or you can generate an URL to send to all of them an invitation to join the beta testing.

Once your teammates subscribe to the website, they will have to register their devices as well. Once they do that, the developers have to add their device to the list of “compatible” devices. This step is required only the first time you set up the team.

The cool features that TestFlight brings are the instant report of what’s going on in the team (it displays the status of all the teammates and what they did so far) and it sends notifications every time the developers deploy (and hence upload) a new version of the app. This way the mates are automatically notified by the system.

I found it to be very interesting and quite immediate and I will definitively propose it to my team in the next days.

Posted on Dec 21, 2010

iOS4 and wireless application deploy

Starting from iOS4 it is possible to publish applications on to a generic webserver and allow people to download an application with just a single “tap” without using iTunes or Xcode.

The operation is quite straightforward and also well documented in the related Apple Documentation. This is only possible, of course, if you have a valid developer certificate and a list of UUIDs of the devices enabled to run the application onto. Such list is part of the so called “provisioning profile” that is generated through the Apple Developer Portal. The idea is that this method is useful for enterprise development (aka Ad Hoc) and you don’t want to deal with colleagues asking for a new deploy or for the latest version every time you update your application or fix some bug.

So let’s start setting up our system. Fire up Xcode and select Build -> Build and Archive. The Organiser will pop-up. Select the build you want to publish and click on the Share... button above the list. Select then the identity you want to sign your code with (usually this is the same you use for signing the code for a standard deploy on the device). Click, then, on Distribuite for Enterprise..

At this point a form will appear asking you from which URL the application should be downloaded from. Let’s suppose your website is available at www.example.com and your application (the file .ipa) is hosted at www.example.com/download/myapp.ipa, then http://www.example.com/download/myapp.ipa should go in that field. [See the update below]
Fill the other fields as you wish; you can get more information about that in the Apple Documentation

Once you filled the form and clicked OK select the place where to save the generated files (ipa and plist).
Congrats you are done!

Now the tricky parts comes when you have to deal with the webserver-side code. I have created a small example page below.
Remember that you have to put on your website all the files: myapp.ipa, myapp.plist and myapp.mobileprovision.

<!DOCTYPE HTML>
<html>
  <head>
    <title>Install your application</title>
  </head>
  <body>
    <ul>
      <li> <a href="http://www.example.com/download/myapp.mobileprovision">Install Team Provisioning File</a></li>
      <li><a href="itms-services://?action=download-manifest&url=http%3A%2F%2Fwww.example.com%2Fdownload%2Fmyapp.plist">Install Application</a></li>
    </ul>
    </div>
  </body>
</html>

Please notice that the second href is nothing just a plain old-fashioned URL. Nothing special into that. If you are wondering about those weird %2F and %3A they are normal urlencoded symbols (for ‘/’ and ‘:’ resp.).
Once you did this you are definitely done.

Maybe if I find some time in the near future I will upload a php page that updates automagically the links to the new application snapshot you publish.

Happy sharin’ :)

[UPDATE 11st January 2011]
Please remember that in the URL textfield you should put exactly the link to the file that is going to be hosted on your website. Is it then necessary that you put the same filename both in that URL field as well as in the filename field where Xcode asks you where to put your archived application (the ipa and plist files).

Posted on Dec 1, 2010

Using Git with Xcode projects

Do you like Git? Me too.

I have found a very nice setting for .gitignore and .gitattributes file in order to improve your overall experience.

Go into you project root directory and create a file named .gitignore and put the following into it:

build
*.mode1v3
*.pbxuser
*.perspective
*.perspectivev3
*.mode2v3
.DS_Store

You do not want to upload your compiled files. There is no need.
The rest of the list is just a bunch of useless files that are generated by Xcode. You want to ignore them especially if you are working on a team because they are mainly settings for Xcode IDE.
Those files are not strictly part of the project.

Said that, create another file named .gitattributes and put the following into it:

*.pbxproj -crlf -diff -merge

This will tell git to ignore the file when viewing diffs. It will treat the project file as a binary file so it will just add it without complaining and
ruining the output of your git commands.

In detail:

  • -crlf : Prevent from trying to fix newlines
  • -diff : Prevent from showing the changes on git diff command
  • -merge: Exclude that file from merge commands

Posted on Jul 20, 2010

MapKitDynRoutes: Handle iOS4 routes dynamically

Since iPhone iOS4 has released I’ve been working on the new features brought by the new version of the OS.
One of the most useful thing (to me) introduced by iOS4 is the capability of drawing routes directly on the map using public APIs.
How that works is fairly simple: given two or more coordinates it generates a Polyline and put it on the map. This line automagically rescales/resizes in order to maintain the correct aspect even when zooming/panning.

Unfortunately, this new object doesn’t allow developers to update the line with new points. The only thing you can do is to destroy the line, remove the overlay from the map, recreate a line with all previous points plus the new one, generate the respective line associated with the map and add it (as overlay) on the map itself. This is quite a waste of CPU cycles.

I’ve written a set of two classes that tries to handle the Polyline growth automatically.

The project is called MapKitDynRoutes and the libraries are FFMapRoute and FFMapRoutes.

MapKitDynRoutes is shipped with a Demo project that shows how to use the library. It contains, furthermore, a small object FFLocationManager that simulates the GPS behaviour by injecting coordinates to the application using a timer and reading those from a CSV file.

MapKitDynRoutes is released under MIT license.